diff options
author | André Erdmann <dywi@mailerd.de> | 2013-07-02 23:05:28 +0200 |
---|---|---|
committer | André Erdmann <dywi@mailerd.de> | 2013-07-02 23:05:28 +0200 |
commit | 067b4e7f942517bf1662e718d918948887b720ae (patch) | |
tree | 4de55a732c8cbfa6a2aabacb91aabbc2e0de49c6 /tests | |
parent | roverlay/interface: access subsystems more easily (diff) | |
download | R_overlay-067b4e7f942517bf1662e718d918948887b720ae.tar.gz R_overlay-067b4e7f942517bf1662e718d918948887b720ae.tar.bz2 R_overlay-067b4e7f942517bf1662e718d918948887b720ae.zip |
roverlay/tests
roverlay/tests contains unittests for roverlay's code.
This commit also add a test environment (plus a few test cases) for dependency
resolution.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/__init__.py | 0 | ||||
-rw-r--r-- | tests/base.py | 46 | ||||
-rw-r--r-- | tests/depres.py | 149 | ||||
-rw-r--r-- | tests/interface.py | 27 | ||||
-rw-r--r-- | tests/static/__init__.py | 0 | ||||
-rw-r--r-- | tests/static/depres.py | 61 |
6 files changed, 283 insertions, 0 deletions
diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/tests/__init__.py diff --git a/tests/base.py b/tests/base.py new file mode 100644 index 0000000..a9d3f84 --- /dev/null +++ b/tests/base.py @@ -0,0 +1,46 @@ +# R overlay -- +# -*- coding: utf-8 -*- +# Copyright (C) 2013 André Erdmann <dywi@mailerd.de> +# Distributed under the terms of the GNU General Public License; +# either version 2 of the License, or (at your option) any later version. + +import unittest + +import roverlay +import roverlay.config.static + + + +class BasicRoverlayTestCase ( unittest.TestCase ): + CONFIG_FILE = "R-overlay.conf.tests" + CONFIG = None + + @classmethod + def load_config ( cls ): + # does nothing if already initialized + if cls.CONFIG is None: + roverlay.setup_initial_logger() + cls.CONFIG = roverlay.load_config_file ( cls.CONFIG_FILE ) + # --- end of load_config (...) --- + +# @classmethod +# def setUpClass ( cls ): +# pass + +# @classmethod +# def tearDownClass ( cls ): +# pass + +class RoverlayTestCase ( BasicRoverlayTestCase ): + + @classmethod + def setUpClass ( cls ): + super ( RoverlayTestCase, cls ).setUpClass() + cls.load_config() + + +def make_testsuite ( testcase_cls ): + return unittest.TestSuite ( + map ( lambda s: testcase_cls ( "test_" + s ), testcase_cls.TESTSUITE ) + ) +# --- end of make_testsuite (...) --- diff --git a/tests/depres.py b/tests/depres.py new file mode 100644 index 0000000..9be82a3 --- /dev/null +++ b/tests/depres.py @@ -0,0 +1,149 @@ +# R overlay -- +# -*- coding: utf-8 -*- +# Copyright (C) 2013 André Erdmann <dywi@mailerd.de> +# Distributed under the terms of the GNU General Public License; +# either version 2 of the License, or (at your option) any later version. + +import random + +import roverlay.interface.depres + +import tests.base +import tests.interface +import tests.static.depres + +from tests.static.depres import DEPRES_DATA, DEPRES_RULES, DEPRES_INCLUDE + + + +def suite(): + return tests.base.make_testsuite ( DepresTestCase ) + + +as_iterable = lambda s : ( s, ) if isinstance ( s, str ) else s + +class DepresTestCase ( tests.interface.RoverlayInterfaceTestCase ): + + TESTSUITE = [ + 'sanity_checks', + 'visualize', + 'depres_static', 'depres_static_randomized', + ] + + DEPRES_INTERFACE = None + + @classmethod + def setUpClass ( cls ): + super ( DepresTestCase, cls ).setUpClass() + cls.ROOT_INTERFACE.register_interface ( + "depres", roverlay.interface.depres.DepresInterface, force=True + ) + cls.DEPRES_INTERFACE = cls.ROOT_INTERFACE.spawn_interface ( "depres" ) + + def setUp ( self ): + #ref + self.depres = self.__class__.DEPRES_INTERFACE + self.depres.get_new_pool() + # --- end of setUp (...) --- + + def tearDown ( self ): + self.depres.discard_pool() + self.depres.discard_empty_pools() + self.depres.update() + # --- end of tearDown (...) --- + + def do_depres_test ( self, rule_names, test_data ): + unpacked = lambda T: T[0] if T and len ( T ) == 1 else T + + self.depres.compile_rules() + self.tearDown() + self.depres.get_new_pool() + for rule_name in rule_names: + self.assertTrue ( + self.depres.add_rule_list ( DEPRES_RULES [rule_name] ) + ) + self.assertTrue ( self.depres.compile_rules() ) + + for depstr, t_expected_result in test_data: + expected_result = unpacked ( t_expected_result ) + result = unpacked ( self.depres.resolve ( depstr ) ) + + + self.assertEquals ( + result, expected_result, + "{!r} should be resolved as {!r} and not {!r}".format ( + depstr, expected_result, result + ) + ) + # --- end of do_depres_test (...) --- + + def do_randomized_depres_test ( + self, rule_names, test_data, allow_modify=False + ): + if allow_modify and isinstance ( test_data, list ): + rand_list = test_data + else: + rand_list = list ( test_data ) + random.shuffle ( rand_list ) + return self.do_depres_test ( rule_names, rand_list ) + # --- end of do_randomized_depres_test (...) --- + + def get_depres_include ( self, dataset_name ): + if dataset_name in DEPRES_INCLUDE: + return as_iterable ( DEPRES_INCLUDE [dataset_name] ) + else: + return ( dataset_name, ) + # --- end of get_depres_include (...) --- + + def test_visualize ( self ): + for name, ruleset in DEPRES_RULES.items(): + self.depres.compile_rules() + self.tearDown() + self.depres.get_new_pool() + + self.assertTrue ( self.depres.add_rule_list ( ruleset ) ) + self.assertTrue ( self.depres.compile_rules() ) + + vis = self.depres.visualize_pool() + self.assertIsInstance ( vis, str ) + self.assertEquals ( + bool ( not self.depres.get_pool().empty() ), bool ( vis ) + ) + # --- end of test_visualize (...) --- + + def test_sanity_checks ( self ): + for dataset_name in DEPRES_DATA.keys(): + if dataset_name in DEPRES_INCLUDE: + ruleset_list = as_iterable ( DEPRES_INCLUDE [dataset_name] ) + else: + ruleset_list = ( dataset_name, ) + + for ruleset_name in ruleset_list: + self.assertIn ( + ruleset_name, DEPRES_RULES, + "missing ruleset {!r} for depres test {!r}".format ( + ruleset_name, dataset_name + ) + ) + # --- end of test_sanity_checks (...) --- + + def test_depres_static ( self ): + for name, test_data in DEPRES_DATA.items(): + self.do_depres_test ( + self.get_depres_include ( name ), + DEPRES_DATA [test_data] if isinstance ( test_data, str ) + else test_data + ) + # --- end of test_depres_static (...) --- + + def test_depres_static_randomized ( self ): + data_keys = list ( DEPRES_DATA.keys() ) + random.shuffle ( data_keys ) + + for name in data_keys: + test_data = DEPRES_DATA [name] + self.do_randomized_depres_test ( + self.get_depres_include ( name ), + DEPRES_DATA [test_data] if isinstance ( test_data, str ) + else test_data + ) diff --git a/tests/interface.py b/tests/interface.py new file mode 100644 index 0000000..44a5a31 --- /dev/null +++ b/tests/interface.py @@ -0,0 +1,27 @@ +# R overlay -- +# -*- coding: utf-8 -*- +# Copyright (C) 2013 André Erdmann <dywi@mailerd.de> +# Distributed under the terms of the GNU General Public License; +# either version 2 of the License, or (at your option) any later version. + +import tests.base + +import roverlay.interface.root + +class RoverlayInterfaceTestCase ( tests.base.RoverlayTestCase ): + + ROOT_INTERFACE = None + + @classmethod + def setUpClass ( cls ): + super ( RoverlayInterfaceTestCase, cls ).setUpClass() + if cls.ROOT_INTERFACE is None: + cls.ROOT_INTERFACE = roverlay.interface.root.RootInterface ( + config=cls.CONFIG + ) + + @classmethod + def tearDownClass ( cls ): + super ( RoverlayInterfaceTestCase, cls ).tearDownClass() + if cls.ROOT_INTERFACE is not None: + cls.ROOT_INTERFACE.close() diff --git a/tests/static/__init__.py b/tests/static/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/tests/static/__init__.py diff --git a/tests/static/depres.py b/tests/static/depres.py new file mode 100644 index 0000000..f72d3dd --- /dev/null +++ b/tests/static/depres.py @@ -0,0 +1,61 @@ +# R overlay -- +# -*- coding: utf-8 -*- +# Copyright (C) 2013 André Erdmann <dywi@mailerd.de> +# Distributed under the terms of the GNU General Public License; +# either version 2 of the License, or (at your option) any later version. + +# ready-to-use input for testing dependency resolution + +DONT_RESOLVE = lambda s: ( s, None ) +DONT_RESOLVE_TUPLE = lambda *S: tuple ( map ( DONT_RESOLVE, S ) ) + +# dict <dataset name>, <tuple ( <dependency string>, <expected result> )> +# +DEPRES_DATA = { + 'fftw': ( + ( "fftw", "sci-libs/fftw" ), + ( "fftw 2", ">=sci-libs/fftw-2" ), + ( "fftw 2.1.5", ">=sci-libs/fftw-2.1.5:2.1" ), + ), + 'slot0': ( + ( "p0", "cat/pkg:*" ), + DONT_RESOLVE ( "p0 !=2" ), + ( "p1", "cat/pkg:=" ), + ( "p2", "cat/pkg" ), + DONT_RESOLVE ( "p2 <3" ), + ( "p2 =2.2.49", "=cat/pkg-2.2.49:2.2/49" ), + DONT_RESOLVE ( "p2 5" ), + DONT_RESOLVE ( "p2 5.4" ), + DONT_RESOLVE ( "p2 !5" ), + DONT_RESOLVE ( "p2 !=5" ), + DONT_RESOLVE ( "p3 1." ), + ( "p3 2.1.0", "cat/pkg:1" ), + ( "p4 5.4.3.2.1", "cat/pkg:5=" ), + ), + 'empty': DONT_RESOLVE_TUPLE ( "fftw", ), +} + +# dict <ruleset name>, <m-tuples>( <rule file line>^m ) +DEPRES_RULES = { + 'fftw': ( + 'sci-libs/fftw {', 'fftw', '}', + '~sci-libs/fftw:+v:s=..1 :: fftw', + '~sci-libs/fftw :: fftw', + ), + 'slot0': ( + '~cat/pkg:open:* :: p0', + '~cat/pkg:open: :: p1', + '~cat/pkg:with_version:s=..1:/2 :: p2', + '~cat/pkg:s=1 :: p3', + '~cat/pkg:= :: p4', + ), + 'empty': (), +} + +# dict <dataset name>, <iterable|str <ruleset name(s)>> +# datasets not listed here default to <dataset name> as <ruleset name> +DEPRES_INCLUDE = { + #"fftw": "fftw", +} + +#DEPRES_FAULTY_RULES=... |