[tracker/sam/functional-test-fixes: 6/20] functional-tests: Convert DConf code to use GObject introspection
- From: Sam Thursfield <sthursfield src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/sam/functional-test-fixes: 6/20] functional-tests: Convert DConf code to use GObject introspection
- Date: Sun, 20 Jul 2014 16:20:58 +0000 (UTC)
commit e914b064f4c92b3a20b9202d5089f0fc9e24b29f
Author: Sam Thursfield <sam afuera me uk>
Date: Sun Jul 20 11:42:19 2014 +0100
functional-tests: Convert DConf code to use GObject introspection
Currently this breaks everything because you can't mix static PyGObject modules with
PyGI. I guess the tests need to be converted to PyGI completely! :(
Original motivation was that we should raise an error if running using the memory
backend instead of DConf, because absolutely nothing works in that case.
.../functional-tests/301-miner-resource-removal.py | 20 +++--
.../common/utils/applicationstest.py | 17 ++-
tests/functional-tests/common/utils/dconf.py | 99 +++++++++++---------
tests/functional-tests/common/utils/minertest.py | 19 +++--
tests/functional-tests/common/utils/system.py | 19 ++--
.../functional-tests/common/utils/writebacktest.py | 19 +++-
6 files changed, 113 insertions(+), 80 deletions(-)
---
diff --git a/tests/functional-tests/301-miner-resource-removal.py
b/tests/functional-tests/301-miner-resource-removal.py
index edf48b8..f1a8a38 100755
--- a/tests/functional-tests/301-miner-resource-removal.py
+++ b/tests/functional-tests/301-miner-resource-removal.py
@@ -27,6 +27,8 @@ from common.utils.dconf import DConfClient
from common.utils.helpers import MinerFsHelper, StoreHelper, ExtractorHelper, log
from common.utils.system import TrackerSystemAbstraction
+from gi.repository import GLib
+
import dbus
import glib
import os
@@ -42,14 +44,16 @@ def get_test_uri (filename):
return "file://" + os.path.join (MINER_TMP_DIR, filename)
-CONF_OPTIONS = [
- (cfg.DCONF_MINER_SCHEMA, "enable-writeback", "false"),
- (cfg.DCONF_MINER_SCHEMA, "index-recursive-directories", [MINER_TMP_DIR]),
- (cfg.DCONF_MINER_SCHEMA, "index-single-directories", "[]"),
- (cfg.DCONF_MINER_SCHEMA, "index-optical-discs", "true"),
- (cfg.DCONF_MINER_SCHEMA, "index-removable-devices", "false"),
- (cfg.DCONF_MINER_SCHEMA, "throttle", 5)
- ]
+CONF_OPTIONS = {
+ cfg.DCONF_MINER_SCHEMA: {
+ 'enable-writeback': GLib.Variant.new_boolean(False),
+ 'index-recursive-directories': GLib.Variant.new_strv([MINER_TMP_DIR]),
+ 'index-single-directories': GLib.Variant.new_strv([])),
+ 'index-optical-discs': GLib.Variant.new_boolean(False),
+ 'index-removable-devices': GLib.Variant.new_boolean(False),
+ 'throttle': GLib.Variant.new_int(5)),
+ }
+}
REASONABLE_TIMEOUT = 30
diff --git a/tests/functional-tests/common/utils/applicationstest.py
b/tests/functional-tests/common/utils/applicationstest.py
index 25e213a..72a8b84 100644
--- a/tests/functional-tests/common/utils/applicationstest.py
+++ b/tests/functional-tests/common/utils/applicationstest.py
@@ -22,18 +22,23 @@ from common.utils.system import TrackerSystemAbstraction
from common.utils.helpers import log
import unittest2 as ut
+from gi.repository import GLib
+
import shutil
import os
import time
APPLICATIONS_TMP_DIR = os.path.join (cfg.TEST_MONITORED_TMP_DIR, "test-applications-monitored")
-CONF_OPTIONS = [
- (cfg.DCONF_MINER_SCHEMA, "index-recursive-directories", [APPLICATIONS_TMP_DIR]),
- (cfg.DCONF_MINER_SCHEMA, "index-single-directories", "[]"),
- (cfg.DCONF_MINER_SCHEMA, "index-optical-discs", "false"),
- (cfg.DCONF_MINER_SCHEMA, "index-removable-devices", "false")
- ]
+index_dirs = [APPLICATIONS_TMP_DIR]
+CONF_OPTIONS = {
+ cfg.DCONF_MINER_SCHEMA: {
+ 'index-recursive-directories': GLib.Variant.new_strv(index_dirs),
+ 'index-single-directories': GLib.Variant.new_strv([]),
+ 'index-optical-discs': GLib.Variant.new_boolean(False),
+ 'index-removable-devices': GLib.Variant.new_boolean(False),
+ }
+}
# Copy rate, 10KBps (1024b/100ms)
SLOWCOPY_RATE = 1024
diff --git a/tests/functional-tests/common/utils/dconf.py b/tests/functional-tests/common/utils/dconf.py
index 8a7978c..11a7851 100644
--- a/tests/functional-tests/common/utils/dconf.py
+++ b/tests/functional-tests/common/utils/dconf.py
@@ -1,26 +1,41 @@
-import subprocess
+from gi.repository import GLib
+from gi.repository import Gio
+
import os
+
from helpers import log
-class DConfClient:
+class DConfClient(object):
"""
- Shamefull implementation until we get GobjectIntrospection on libdconf
+ 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 write (self, schema, key, value):
- command = ["gsettings", "set", schema, key, str(value)]
- FNULL = open('/dev/null', 'w')
- cmd = subprocess.Popen (command, stdout=subprocess.PIPE) #, stdout=FNULL, stderr=FNULL)
- cmd.wait ()
-
-
- def read (self, schema, key):
- command = ["gsettings", "get", schema, key]
- FNULL = open('/dev/null', 'w')
- cmd = subprocess.Popen (command, stdout=subprocess.PIPE) #, stdout=FNULL, stderr=FNULL)
- return cmd.stdout.readline ()
-
- def reset (self):
- profile = os.environ ["DCONF_PROFILE"]
+
+ 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__
+ 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 "
@@ -29,6 +44,28 @@ class DConfClient:
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.
@@ -39,29 +76,3 @@ class DConfClient:
if os.path.exists (dconf_db):
log ("[Conf] Removing dconf database: " + dconf_db)
os.remove (dconf_db)
-
-
-if __name__ == "__main__":
-
-
- SCHEMA_MINER = "org.freedesktop.Tracker.Miner.Files"
- os.environ ["DCONF_PROFILE"] = os.path.join (cfg.DATADIR, "tracker-tests",
- "trackertest")
-
- dconf = DConfClient ()
- value = dconf.read (DConfClient.SCHEMA_MINER, "throttle")
- print "Original value:", int (value)
- print "Setting 5"
- dconf.write (DConfClient.SCHEMA_MINER, "throttle", "5")
- value = dconf.read (DConfClient.SCHEMA_MINER, "throttle")
- assert int(value) == 5
-
- print "Setting 3"
- dconf.write (DConfClient.SCHEMA_MINER, "throttle", "3")
- value = dconf.read (DConfClient.SCHEMA_MINER, "throttle")
- assert int (value) == 3
-
- print "Now with lists"
- dconf.write (DConfClient.SCHEMA_MINER, "index-recursive-directories", ['$HOME/set-with-python'])
- value = dconf.read (DConfClient.SCHEMA_MINER, "index-recursive-directories")
- print "result", value
diff --git a/tests/functional-tests/common/utils/minertest.py
b/tests/functional-tests/common/utils/minertest.py
index 8651b05..46ee2d7 100644
--- a/tests/functional-tests/common/utils/minertest.py
+++ b/tests/functional-tests/common/utils/minertest.py
@@ -22,6 +22,8 @@ from common.utils.system import TrackerSystemAbstraction
from common.utils.helpers import StoreHelper
import unittest2 as ut
+from gi.repository import GLib
+
import shutil
import os
@@ -36,13 +38,16 @@ def uri (filename):
DEFAULT_TEXT = "Some stupid content, to have a test file"
-CONF_OPTIONS = [
- (cfg.DCONF_MINER_SCHEMA, "index-recursive-directories", [os.path.join (MINER_TMP_DIR,
"test-monitored")]),
- (cfg.DCONF_MINER_SCHEMA, "index-single-directories", "[]"),
- (cfg.DCONF_MINER_SCHEMA, "index-optical-discs", "false"),
- (cfg.DCONF_MINER_SCHEMA, "index-removable-devices", "false"),
- (cfg.DCONF_MINER_SCHEMA, "throttle", 5)
- ]
+index_dirs = [os.path.join (MINER_TMP_DIR, "test-monitored")]
+CONF_OPTIONS = {
+ cfg.DCONF_MINER_SCHEMA: {
+ 'index-recursive-directories': GLib.Variant.new_strv(index_dirs),
+ 'index-single-directories': GLib.Variant.new_strv([]),
+ 'index-optical-discs': GLib.Variant.new_boolean(False),
+ 'index-removable-devices': GLib.Variant.new_boolean(False),
+ 'throttle': GLib.Variant.new_int(5),
+ }
+}
class CommonTrackerMinerTest (ut.TestCase):
diff --git a/tests/functional-tests/common/utils/system.py b/tests/functional-tests/common/utils/system.py
index 9636b8c..c1d5707 100644
--- a/tests/functional-tests/common/utils/system.py
+++ b/tests/functional-tests/common/utils/system.py
@@ -37,15 +37,16 @@ class UnableToBootException (Exception):
class TrackerSystemAbstraction:
- def set_up_environment (self, gsettings, ontodir):
+ def set_up_environment (self, settings, ontodir):
"""
Sets up the XDG_*_HOME variables and make sure the directories exist
- gsettings is a list of triplets (schema, key, value) that will be set/unset in gsetting
+ Settings should be a dict mapping schema names to dicts that hold the
+ settings that should be changed in those schemas. The contents dicts
+ should map key->value, where key is a key name and value is a suitable
+ GLib.Variant instance.
"""
- assert not gsettings or type(gsettings) is list
-
helpers.log ("[Conf] Setting test environment...")
for var, directory in TEST_ENV_DIRS.iteritems ():
@@ -65,11 +66,11 @@ class TrackerSystemAbstraction:
os.environ [var] = value
# Previous loop should have set DCONF_PROFILE to the test location
- if gsettings:
- self.dconf = DConfClient ()
- self.dconf.reset ()
- for (schema, key, value) in gsettings:
- self.dconf.write (schema, key, value)
+ for schema_name, contents in settings.iteritems():
+ dconf = DConfClient(schema_name)
+ dconf.reset()
+ for key, value in contents.iteritems():
+ dconf.write(key, value)
helpers.log ("[Conf] environment ready")
diff --git a/tests/functional-tests/common/utils/writebacktest.py
b/tests/functional-tests/common/utils/writebacktest.py
index b73d903..3701226 100644
--- a/tests/functional-tests/common/utils/writebacktest.py
+++ b/tests/functional-tests/common/utils/writebacktest.py
@@ -17,6 +17,9 @@
# Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
# Boston, MA 02110-1301, USA.
#
+
+from gi.repository import GLib
+
from common.utils.system import TrackerSystemAbstraction
import shutil
import unittest2 as ut
@@ -31,12 +34,16 @@ TEST_FILE_PNG = "writeback-test-4.png"
WRITEBACK_TMP_DIR = os.path.join (cfg.TEST_MONITORED_TMP_DIR, "writeback")
-CONF_OPTIONS = [
- (cfg.DCONF_MINER_SCHEMA, "index-recursive-directories", [WRITEBACK_TMP_DIR]),
- (cfg.DCONF_MINER_SCHEMA, "index-single-directories", "[]"),
- (cfg.DCONF_MINER_SCHEMA, "index-optical-discs", "false"),
- (cfg.DCONF_MINER_SCHEMA, "index-removable-devices", "false")
- ]
+index_dirs = [WRITEBACK_TMP_DIR]
+CONF_OPTIONS = {
+ cfg.DCONF_MINER_SCHEMA: {
+ 'index-recursive-directories': GLib.Variant.new_strv(index_dirs),
+ 'index-single-directories': GLib.Variant.new_strv([]),
+ 'index-optical-discs': GLib.Variant.new_boolean(False),
+ 'index-removable-devices': GLib.Variant.new_boolean(False),
+ }
+}
+
def uri (filename):
return "file://" + os.path.join (WRITEBACK_TMP_DIR, filename)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]