Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Makefile1
-rw-r--r--Makefile.tests5
-rw-r--r--commands/common.py6
-rw-r--r--config/modules/index.json3
-rw-r--r--devbot/config.py26
-rw-r--r--devbot/plugins/fedora.py4
-rw-r--r--tests/devbot/data/fedora-release-171
-rw-r--r--tests/devbot/data/fedora-release-181
-rw-r--r--tests/devbot/test_config.py67
-rw-r--r--tests/devbot/test_git.py3
10 files changed, 91 insertions, 26 deletions
diff --git a/Makefile b/Makefile
index fc8b3b7..0359aee 100644
--- a/Makefile
+++ b/Makefile
@@ -2,6 +2,7 @@ SOURCE_DIR=$(CURDIR)/source
COMMANDS_DIR=$(CURDIR)/commands
HOME_DIR=$(CURDIR)/home
TOOLS_DIR=$(CURDIR)/tools
+BASE_DIR=$(CURDIR)
.PHONY: all
diff --git a/Makefile.tests b/Makefile.tests
index d60ac49..d47e558 100644
--- a/Makefile.tests
+++ b/Makefile.tests
@@ -1,8 +1,9 @@
TESTS_DATA=$(HOME_DIR)/testsdata
test-devbot:
- mkdir -p $(TESTS_DATA)
- TMPDIR=$(TESTS_DATA) PYTHONPATH=. python tests/devbot/test_git.py
+ mkdir -p $(TESTS_DATA) && \
+ cd tests/devbot && \
+ TMPDIR=$(TESTS_DATA) PYTHONPATH=$(BASE_DIR) python -m unittest discover
rm -rf $(TESTS_DATA)
check: test-devbot test-ui
diff --git a/commands/common.py b/commands/common.py
index 38c3418..6f2d9fd 100644
--- a/commands/common.py
+++ b/commands/common.py
@@ -27,12 +27,6 @@ def setup():
config.set_prefs_path(os.path.join(base_dir, "prefs"))
config.set_logs_dir(logs_dir)
- module_files = ["system.json",
- "sugar.json",
- "activities.json"]
-
- config.set_module_files(module_files)
-
dep_files = ["system",
"sugar-build",
"sugar-buildtime",
diff --git a/config/modules/index.json b/config/modules/index.json
new file mode 100644
index 0000000..c098f19
--- /dev/null
+++ b/config/modules/index.json
@@ -0,0 +1,3 @@
+["activities.json",
+ "sugar.json",
+ "system.json"]
diff --git a/devbot/config.py b/devbot/config.py
index ed65c3a..a5f9428 100644
--- a/devbot/config.py
+++ b/devbot/config.py
@@ -22,7 +22,6 @@ etc_dir = None
libexec_dir = None
home_dir = None
dep_files = None
-module_files = None
package_files = None
prefs_path = None
@@ -169,10 +168,6 @@ def set_dep_files(files):
global dep_files
dep_files = files
-def set_module_files(files):
- global module_files
- module_files = files
-
def set_package_files(files):
global package_files
package_files = files
@@ -184,7 +179,7 @@ def set_prefs_path(path):
def _read_prefs():
global prefs_path
- if not os.path.exists(prefs_path):
+ if prefs_path is None or not os.path.exists(prefs_path):
return {}
prefs = {}
@@ -199,6 +194,9 @@ def _read_prefs():
def _save_prefs(prefs):
global prefs_path
+ if prefs_path is None:
+ return
+
with open(prefs_path, "w") as f:
for pref in prefs.items():
f.write("%s\n" % "=".join(pref))
@@ -248,17 +246,17 @@ def load_checks():
return filter(_filter_if, checks)
def load_modules():
- global module_files
-
- modules = []
+ module_dir = os.path.join(config_dir, "modules")
- for file in module_files:
- path = os.path.join(config_dir, "modules", file)
+ with open(os.path.join(module_dir, "index.json")) as f:
+ modules = []
+ for module_file in json.load(f):
+ path = os.path.join(module_dir, module_file)
- for info in json.load(open(path)):
- modules.append(Module(info))
+ for info in json.load(open(path)):
+ modules.append(Module(info))
- return modules
+ return modules
def clean():
try:
diff --git a/devbot/plugins/fedora.py b/devbot/plugins/fedora.py
index 60d73d8..ebfc91a 100644
--- a/devbot/plugins/fedora.py
+++ b/devbot/plugins/fedora.py
@@ -82,6 +82,8 @@ class PackageManager(interfaces.PackageManager):
distro.register_package_manager("fedora", PackageManager)
class DistroInfo(interfaces.DistroInfo):
+ _FEDORA_RELEASE_PATH = "/etc/fedora-release"
+
def __init__(self):
arch = subprocess.check_output(["uname", "-i"]).strip()
@@ -94,7 +96,7 @@ class DistroInfo(interfaces.DistroInfo):
self.supported = (arch in ["i386", "i686", "x86_64"])
try:
- release = open("/etc/fedora-release").read().strip()
+ release = open(_FEDORA_RELEASE_PATH).read().strip()
except IOError:
release = None
self.valid = False
diff --git a/tests/devbot/data/fedora-release-17 b/tests/devbot/data/fedora-release-17
new file mode 100644
index 0000000..2c71c58
--- /dev/null
+++ b/tests/devbot/data/fedora-release-17
@@ -0,0 +1 @@
+Fedora release 17 (Beefy Miracle)
diff --git a/tests/devbot/data/fedora-release-18 b/tests/devbot/data/fedora-release-18
new file mode 100644
index 0000000..5006ba3
--- /dev/null
+++ b/tests/devbot/data/fedora-release-18
@@ -0,0 +1 @@
+Fedora release 18 (Spherical Cow)
diff --git a/tests/devbot/test_config.py b/tests/devbot/test_config.py
new file mode 100644
index 0000000..3ffd90a
--- /dev/null
+++ b/tests/devbot/test_config.py
@@ -0,0 +1,67 @@
+import os
+import tempfile
+import unittest
+import subprocess
+
+from devbot import git
+from devbot import config
+from devbot import distro
+
+tests_dir = os.path.abspath(os.path.dirname(__file__))
+base_dir = os.path.dirname(os.path.dirname(tests_dir))
+config_dir = os.path.join(base_dir, "config")
+data_dir = os.path.join(tests_dir, "data")
+
+class TestConfig(unittest.TestCase):
+ def setUp(self):
+ config.set_config_dir(config_dir)
+
+ def _set_distro(self, name, version):
+ self._orig_supported_distro = distro._supported_distros
+ for info_class in distro._supported_distros:
+ if "_FEDORA_RELEASE_PATH" in distro_info_class:
+ info_class._FEDORA_RELEASE_PATH = \
+ os.path.join(data_dir, "fedora-release-18")
+
+ info = info_class()
+ if info.name == name and info.version == version:
+ self._supported_distros = [info]
+ break
+
+ def _unset_distro(self):
+ distro._supported_distros = self._orig_supported_distro
+
+ def _find_module(self, modules, name):
+ for module in modules:
+ if module.name == name:
+ return module
+
+ return None
+
+ def _assert_module(self, modules, name):
+ self.assertIsNotNone(self._find_module(modules, name))
+
+ def _assert_no_module(self, modules, name):
+ self.assertIsNotNone(self._find_module(modules, name))
+
+ def test_fedora_17_info(self):
+ self._set_distro("fedora", "17")
+
+ modules = config.load_modules()
+ self._assert_module(modules, "glib")
+ self._assert_module(modules, "gtk+")
+ self._assert_module(modules, "gstreamer")
+ self._assert_module(modules, "sugar")
+
+ self._unset_distro()
+
+ def test_fedora_18_info(self):
+ self._set_distro("fedora", "18")
+
+ modules = config.load_modules()
+ self._assert_module(modules, "glib")
+ self._assert_module(modules, "gtk+")
+ self._assert_module(modules, "gstreamer")
+ self._assert_module(modules, "sugar")
+
+ self._unset_distro()
diff --git a/tests/devbot/test_git.py b/tests/devbot/test_git.py
index 21d81e8..e78626a 100644
--- a/tests/devbot/test_git.py
+++ b/tests/devbot/test_git.py
@@ -116,6 +116,3 @@ class TestGit(unittest.TestCase):
self.assertTrue(os.path.exists(to_clean_path))
module.clean()
self.assertFalse(os.path.exists(to_clean_path))
-
-if __name__ == '__main__':
- unittest.main()