diff options
author | Sam Thursfield <sam@afuera.me.uk> | 2019-08-07 14:47:00 +0200 |
---|---|---|
committer | Sam Thursfield <sam@afuera.me.uk> | 2019-08-23 12:39:19 +0300 |
commit | 8ae991922d4178f250cbc3e7f0734d558b01b21e (patch) | |
tree | 78fedc7017e0b7785cc340f33287a91451540b64 /utils | |
parent | e71c9119c34419a345ffbc80af40a6654a78af28 (diff) | |
download | tracker-8ae991922d4178f250cbc3e7f0734d558b01b21e.tar.gz |
functional-tests: Add new trackertestutils module
This module aims to reduce duplication between tracker.git and
tracker-miners.git. The idea is to share as much code as we can
between the different functional-tests. The tracker-sandbox
script will also be use this library.
The module is installed into Tracker's private library directory.
As it is only needed for development and testing, packagers should split
it into the appropriate -devel package.
Diffstat (limited to 'utils')
-rw-r--r-- | utils/meson.build | 1 | ||||
-rw-r--r-- | utils/trackertestutils/README.md | 2 | ||||
-rw-r--r-- | utils/trackertestutils/__init__.py | 1 | ||||
-rw-r--r-- | utils/trackertestutils/dconf.py | 80 | ||||
-rw-r--r-- | utils/trackertestutils/meson.build | 7 |
5 files changed, 91 insertions, 0 deletions
diff --git a/utils/meson.build b/utils/meson.build index c624b4914..3b7847501 100644 --- a/utils/meson.build +++ b/utils/meson.build @@ -1,3 +1,4 @@ subdir('mtp') subdir('ontology') subdir('tracker-resdump') +subdir('trackertestutils') diff --git a/utils/trackertestutils/README.md b/utils/trackertestutils/README.md new file mode 100644 index 000000000..98840ba0a --- /dev/null +++ b/utils/trackertestutils/README.md @@ -0,0 +1,2 @@ +This Python package contains utility functions which are useful when testing +Tracker. diff --git a/utils/trackertestutils/__init__.py b/utils/trackertestutils/__init__.py new file mode 100644 index 000000000..8b1378917 --- /dev/null +++ b/utils/trackertestutils/__init__.py @@ -0,0 +1 @@ + diff --git a/utils/trackertestutils/dconf.py b/utils/trackertestutils/dconf.py new file mode 100644 index 000000000..328f9b845 --- /dev/null +++ b/utils/trackertestutils/dconf.py @@ -0,0 +1,80 @@ +from gi.repository import GLib +from gi.repository import Gio + +import logging +import os + +log = logging.getLogger(__name__) + + +class DConfClient(object): + """ + Allow changing Tracker configuration in DConf. + + Tests should be run with a separate DConf profile so that these changes do + not affect the user's configuration. The 'trackertest' profile exists for + this reason, and the constructor will fail if this isn't the profile in + use, to avoid any risk of modifying or removing your real configuration. + + The constructor will fail if DConf is not the default backend, because this + probably indicates that the memory backend is in use. Without DConf the + required configuration changes will not take effect, causing many tests to + break. + """ + + def __init__(self, schema): + self._settings = Gio.Settings.new(schema) + + backend = self._settings.get_property('backend') + self._check_settings_backend_is_dconf(backend) + self._check_using_correct_dconf_profile() + + def _check_settings_backend_is_dconf(self, backend): + typename = type(backend).__name__.split('.')[-1] + if typename != 'DConfSettingsBackend': + raise Exception( + "The functional tests require DConf to be the default " + "GSettings backend. Got %s instead." % typename) + + def _check_using_correct_dconf_profile(self): + profile = os.environ["DCONF_PROFILE"] + if not os.path.exists(profile): + raise Exception( + "Unable to find DConf profile '%s'. Check that Tracker and " + "the test suite have been correctly installed (you must pass " + "--enable-functional-tests to configure)." % profile) + + assert os.path.basename(profile) == "trackertest" + + def write(self, key, value): + """ + Write a settings value. + """ + self._settings.set_value(key, value) + + def read(self, schema, key): + """ + Read a settings value. + """ + return self._settings.get_value(key) + + def reset(self): + """ + Remove all stored values, resetting configuration to the default. + + This can be done by removing the entire 'trackertest' configuration + database. + """ + + self._check_using_correct_dconf_profile() + + # XDG_CONFIG_HOME is useless, so we use HOME. This code should not be + # needed unless for some reason the test is not being run via the + # 'test-runner.sh' script. + dconf_db = os.path.join(os.environ["HOME"], + ".config", + "dconf", + "trackertest") + if os.path.exists(dconf_db): + log.debug("[Conf] Removing dconf database: %s", dconf_db) + os.remove(dconf_db) diff --git a/utils/trackertestutils/meson.build b/utils/trackertestutils/meson.build new file mode 100644 index 000000000..163aecfdf --- /dev/null +++ b/utils/trackertestutils/meson.build @@ -0,0 +1,7 @@ +sources = [ + '__init__.py', + 'dconf.py', +] + +install_data(sources, + install_dir: join_paths(tracker_internal_libs_dir, 'trackertestutils')) |