[tracker/sam/functional-tests-quiet: 10/15] trackertestutils: Rewrite dconf client to call `gsettings` directly
- From: Sam Thursfield <sthursfield src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/sam/functional-tests-quiet: 10/15] trackertestutils: Rewrite dconf client to call `gsettings` directly
- Date: Sun, 1 Sep 2019 13:14:33 +0000 (UTC)
commit 3e5640f29bb6e1be95c19f4e2b658b207f55150e
Author: Sam Thursfield <sam afuera me uk>
Date: Sat Aug 31 03:23:09 2019 +0300
trackertestutils: Rewrite dconf client to call `gsettings` directly
This is needed because we no longer set DCONF_PROFILE in the test
process environment, we only set it in the environment of the Tracker
daemons under test.
utils/trackertestutils/dconf.py | 68 +++++++++++------------------------------
1 file changed, 18 insertions(+), 50 deletions(-)
---
diff --git a/utils/trackertestutils/dconf.py b/utils/trackertestutils/dconf.py
index 4ad0e88e9..de9da19df 100644
--- a/utils/trackertestutils/dconf.py
+++ b/utils/trackertestutils/dconf.py
@@ -18,11 +18,9 @@
# 02110-1301, USA.
#
-from gi.repository import GLib
-from gi.repository import Gio
-
import logging
import os
+import subprocess
log = logging.getLogger(__name__)
@@ -36,28 +34,22 @@ class DConfClient(object):
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.
+ We use the `gsettings` binary rather than using the Gio.Settings API.
+ This is to avoid the need to set DCONF_PROFILE in our own process
+ environment.
"""
- 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 __init__(self, extra_env):
+ self.env = os.environ
+ self.env.update(extra_env)
def _check_using_correct_dconf_profile(self):
- profile = os.environ["DCONF_PROFILE"]
+ profile = self.env.get("DCONF_PROFILE")
+ if not profile:
+ raise Exception(
+ "DCONF_PROFILE is not set in the environment. This class must "
+ "be created inside a TrackerDBussandbox to avoid risk of "
+ "interfering with real settings.")
if not os.path.exists(profile):
raise Exception(
"Unable to find DConf profile '%s'. Check that Tracker and "
@@ -66,35 +58,11 @@ class DConfClient(object):
assert os.path.basename(profile) == "trackertest"
- def write(self, key, value):
+ def write(self, schema, 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)
+ subprocess.run(['gsettings', 'set', schema, key, value.print_(False)],
+ env=self.env,
+ stdout=subprocess.PIPE,
+ stderr=subprocess.PIPE)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]