~coreygoldberg/uci-engine/subunit-results

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import mock
import unittest
import tempfile
import os
from testing import venv
from ucitests import fixtures


class TestVirtualEnv(unittest.TestCase):
    def setUp(self):
        super(TestVirtualEnv, self).setUp()
        fixtures.set_uniq_cwd(self)
        _p = mock.patch('testing.venv.get_basedir',
                        return_value=self.uniq_dir)
        _p.start()
        self.addCleanup(_p.stop)
        override = {
            'PATH': os.environ.get('PATH', ''),
            'PYTHONPATH': os.environ.get('PYTHONPATH', ''),
            'VIRTUAL_ENV': os.environ.get('VIRTUAL_ENV', ''),
            'PIP_CACHE': os.environ.get('PIP_CACHE', ''),
            'REEXECED_UNDER_VENV': os.environ.get('REXECED_UNDER_VENV', ''),
            'CI_DEPS_BRANCH': os.environ.get('CI_DEPS_BRANCH', ''),
            'ARCHFLAGS': os.environ.get('ARCHFLAGS', ''),
        }
        fixtures.isolate_from_env(self, override)

    def test_create(self):
        path = tempfile.mktemp(dir=self.uniq_dir)
        venv.create(path)
        activate = os.path.join(path, 'bin/activate')
        self.assertTrue(os.path.exists(activate))

    def test_find_components(self):
        components = [x for x in venv.find_components()]
        self.assertTrue('ci-utils' in components)

    def test_prepare(self):
        path = tempfile.mktemp(dir=self.uniq_dir)
        venv.create(path, 'python2.7')
        venv.prepare(['ci-utils'])
        pkgs = 'lib/python2.7/site-packages'
        pkgs = os.path.join(path, pkgs)
        self.assertTrue(os.path.exists(pkgs))


if __name__ == '__main__':
    unittest.main()