diff options
| author | Kali Kaneko <kali@leap.se> | 2015-08-28 10:59:30 -0400 | 
|---|---|---|
| committer | Kali Kaneko <kali@leap.se> | 2015-08-28 10:59:30 -0400 | 
| commit | 8fa97c02b5f07f896e52d9bb272128f267af04ea (patch) | |
| tree | e0ce6bbaaa48441ebcfb807a45e8753fe8432423 /src/leap/common/testing/basetest.py | |
| parent | d272a953a01f5c601e4894a916f7b4d990a03327 (diff) | |
| parent | ccecd1b3750bd10404511c33be1aaca82631a502 (diff) | |
Merge tag '0.4.2' into debian/experimental
Tag leap.common version 0.4.2
Conflicts:
	pkg/requirements-testing.pip
	setup.cfg
	src/leap/common/_version.py
	src/leap/common/events/events_pb2.py
Diffstat (limited to 'src/leap/common/testing/basetest.py')
| -rw-r--r-- | src/leap/common/testing/basetest.py | 39 | 
1 files changed, 38 insertions, 1 deletions
| diff --git a/src/leap/common/testing/basetest.py b/src/leap/common/testing/basetest.py index 54826d5..3d3cee0 100644 --- a/src/leap/common/testing/basetest.py +++ b/src/leap/common/testing/basetest.py @@ -28,8 +28,13 @@ except ImportError:      import unittest  from leap.common.check import leap_assert +from leap.common.events import server as events_server +from leap.common.events import client as events_client +from leap.common.events import flags, set_events_enabled  from leap.common.files import mkdir_p, check_and_fix_urw_only +set_events_enabled(False) +  class BaseLeapTest(unittest.TestCase):      """ @@ -40,6 +45,14 @@ class BaseLeapTest(unittest.TestCase):      @classmethod      def setUpClass(cls): +        cls.setUpEnv() + +    @classmethod +    def tearDownClass(cls): +        cls.tearDownEnv() + +    @classmethod +    def setUpEnv(cls):          """          Sets up common facilities for testing this TestCase:          - custom PATH and HOME environmental variables @@ -48,6 +61,9 @@ class BaseLeapTest(unittest.TestCase):          """          cls.old_path = os.environ['PATH']          cls.old_home = os.environ['HOME'] +        cls.old_xdg_config = None +        if "XDG_CONFIG_HOME" in os.environ: +            cls.old_xdg_config = os.environ["XDG_CONFIG_HOME"]          cls.tempdir = tempfile.mkdtemp(prefix="leap_tests-")          cls.home = cls.tempdir          bin_tdir = os.path.join( @@ -55,20 +71,41 @@ class BaseLeapTest(unittest.TestCase):              'bin')          os.environ["PATH"] = bin_tdir          os.environ["HOME"] = cls.tempdir +        os.environ["XDG_CONFIG_HOME"] = os.path.join(cls.tempdir, ".config") +        cls._init_events()      @classmethod -    def tearDownClass(cls): +    def _init_events(cls): +        if flags.EVENTS_ENABLED: +            cls._server = events_server.ensure_server( +                emit_addr="tcp://127.0.0.1:0", +                reg_addr="tcp://127.0.0.1:0") +            events_client.configure_client( +                emit_addr="tcp://127.0.0.1:%d" % cls._server.pull_port, +                reg_addr="tcp://127.0.0.1:%d" % cls._server.pub_port) + +    @classmethod +    def tearDownEnv(cls):          """          Cleanup common facilities used for testing this TestCase:          - restores the default PATH and HOME variables          - removes the temporal folder          """ +        if flags.EVENTS_ENABLED: +            events_client.shutdown() +            cls._server.shutdown() +          os.environ["PATH"] = cls.old_path          os.environ["HOME"] = cls.old_home +        if cls.old_xdg_config is not None: +            os.environ["XDG_CONFIG_HOME"] = cls.old_xdg_config          # safety check! please do not wipe my home...          # XXX needs to adapt to non-linuces          leap_assert(              cls.tempdir.startswith('/tmp/leap_tests-') or +            (cls.tempdir.startswith('/tmp/') and +             cls.tempdir.startswith(tempfile.gettempdir()) and +             'leap_tests-' in cls.tempdir) or              cls.tempdir.startswith('/var/folder'),              "beware! tried to remove a dir which does not "              "live in temporal folder!") | 
