aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--g_octave/description_tree.py24
-rw-r--r--tests/test_description_tree.py55
-rw-r--r--tests/utils.py34
3 files changed, 75 insertions, 38 deletions
diff --git a/g_octave/description_tree.py b/g_octave/description_tree.py
index 7f84974..d71234b 100644
--- a/g_octave/description_tree.py
+++ b/g_octave/description_tree.py
@@ -15,23 +15,22 @@
__all__ = ['DescriptionTree']
-from config import Config
-conf = Config()
+import os
+from config import Config
from description import *
-from exception import DescriptionTreeException
-
-import os
+from exception import ConfigException, DescriptionTreeException
class DescriptionTree(object):
- def __init__(self, db_path=None):
+ def __init__(self, conf=None):
self.pkg_list = {}
- # external db_path used by tests
- self._db_path = db_path is not None and db_path or \
- os.path.join(conf.db, 'octave-forge')
+ if conf is None:
+ conf = Config()
+
+ self._db_path = os.path.join(conf.db, 'octave-forge')
if not os.path.isdir(self._db_path):
raise DescriptionTreeException('Invalid db: %s' % self._db_path)
@@ -45,7 +44,12 @@ class DescriptionTree(object):
mypkg = re_pkg_atom.match(pkg)
if mypkg == None:
raise DescriptionTreeException('Invalid Atom: %s' % mypkg)
- if mypkg.group(1) not in conf.blacklist:
+ try:
+ blacklist = conf.blacklist
+ except ConfigException:
+ # blacklist isn't mandatory
+ blacklist = []
+ if mypkg.group(1) not in blacklist:
self.pkg_list[cat].append({
'name': mypkg.group(1),
'version': mypkg.group(2),
diff --git a/tests/test_description_tree.py b/tests/test_description_tree.py
index a8f0d50..7e9f527 100644
--- a/tests/test_description_tree.py
+++ b/tests/test_description_tree.py
@@ -21,32 +21,18 @@ from g_octave import description, description_tree
class TestDescriptionTree(unittest.TestCase):
- _packages = [
- ('main', 'pkg1', '1.0'),
- ('main', 'pkg2', '0.1'),
- ('main', 'pkg2', '0.2'),
- ('extra', 'pkg1', '1.1'),
- ('language', 'lang', '0.1'),
- ]
-
def setUp(self):
- self._tree_dir = utils.create_description_tree(self._packages)
- self._tree = description_tree.DescriptionTree(self._tree_dir)
-
- def test_temptree(self):
- for cat, pkg, ver in self._packages:
- temp_file = os.path.join(
- self._tree_dir,
- cat, pkg+'-'+ver,
- 'DESCRIPTION'
- )
- self.assertTrue(os.path.exists(temp_file))
+ conf, self._config_file, self._tempdir = utils.create_env()
+ self._tree = description_tree.DescriptionTree(conf = conf)
def test_package_versions(self):
versions = {
- 'pkg1': ['1.0', '1.1'],
- 'pkg2': ['0.1', '0.2'],
- 'lang': ['0.1'],
+ 'main1': ['0.0.1'],
+ 'main2': ['0.0.1', '0.0.2'],
+ 'extra1': ['0.0.1'],
+ 'extra2': ['0.0.1', '0.0.2'],
+ 'language1': ['0.0.1'],
+ 'language2': ['0.0.1', '0.0.2'],
}
for pkg in versions:
ver = self._tree.package_versions(pkg)
@@ -56,9 +42,12 @@ class TestDescriptionTree(unittest.TestCase):
def test_latest_version(self):
versions = {
- 'pkg1': '1.1',
- 'pkg2': '0.2',
- 'lang': '0.1',
+ 'main1': '0.0.1',
+ 'main2': '0.0.2',
+ 'extra1': '0.0.1',
+ 'extra2': '0.0.2',
+ 'language1': '0.0.1',
+ 'language2': '0.0.2',
}
for pkg in versions:
self.assertEqual(
@@ -87,7 +76,18 @@ class TestDescriptionTree(unittest.TestCase):
self.assertEqual(self._tree.version_compare(ver), latest)
def test_description_files(self):
- for cat, pkg, ver in self._packages:
+ packages = [
+ ('main', 'main1', '0.0.1'),
+ ('main', 'main2', '0.0.1'),
+ ('main', 'main2', '0.0.2'),
+ ('extra', 'extra1', '0.0.1'),
+ ('extra', 'extra2', '0.0.1'),
+ ('extra', 'extra2', '0.0.2'),
+ ('language', 'language1', '0.0.1'),
+ ('language', 'language2', '0.0.1'),
+ ('language', 'language2', '0.0.2'),
+ ]
+ for cat, pkg, ver in packages:
self.assertTrue(
isinstance(
self._tree[pkg+'-'+ver],
@@ -97,12 +97,11 @@ class TestDescriptionTree(unittest.TestCase):
def tearDown(self):
# removing the temp tree
- shutil.rmtree(self._tree_dir)
+ utils.clean_env(self._config_file, self._tempdir)
def suite():
suite = unittest.TestSuite()
- suite.addTest(TestDescriptionTree('test_temptree'))
suite.addTest(TestDescriptionTree('test_package_versions'))
suite.addTest(TestDescriptionTree('test_latest_version'))
suite.addTest(TestDescriptionTree('test_version_compare'))
diff --git a/tests/utils.py b/tests/utils.py
index a0bf86c..32f8802 100644
--- a/tests/utils.py
+++ b/tests/utils.py
@@ -11,10 +11,13 @@
:license: GPL-2, see LICENSE for more details.
"""
+import ConfigParser
import os
import shutil
import tempfile
+from g_octave import config
+
def create_description_tree(packages):
# 'packages' is a list of tuples, like this:
# [(category, name, version)]
@@ -32,3 +35,34 @@ def create_description_tree(packages):
os.path.join(temp_path, 'DESCRIPTION')
)
return tree_dir
+
+def create_env():
+ """returns a tuple with the *g_octave.config* object and the path of
+ the temporary config and directory
+ """
+
+ config_file = tempfile.mkstemp(suffix='.cfg')[1]
+ directory = tempfile.mkdtemp()
+ current_dir = os.path.dirname(os.path.abspath(__file__))
+ db = os.path.join(current_dir, 'files')
+ overlay = os.path.join(directory, 'overlay')
+
+ cp = ConfigParser.ConfigParser()
+ cp.add_section('main')
+ cp.set('main', 'db', db)
+ cp.set('main', 'overlay', overlay)
+
+ with open(config_file, 'w') as fp:
+ cp.write(fp)
+
+ conf = config.Config(
+ fetch_phase = True,
+ config_file = config_file,
+ create_dirs = True
+ )
+
+ return conf, config_file, directory
+
+def clean_env(config_file, directory):
+ os.unlink(config_file)
+ shutil.rmtree(directory)