tests.test_discover_modules   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 29
dl 0
loc 49
rs 10
c 0
b 0
f 0
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A TestDiscoverModules.test_get_modules_from_source() 0 14 1
A TestDiscoverModules.test_discover_modules_with_raise() 0 9 2
A TestDiscoverModules.test_discover_modules() 0 15 1
1
from pathlib import Path
2
from unittest import TestCase
3
4
from barentsz._discover import discover_modules, _get_modules_from_source
5
6
7
class TestDiscoverModules(TestCase):
8
9
    def test_discover_modules(self):
10
        # SETUP
11
        path_to_resources = (Path(__file__).parent.parent / 'test_resources'
12
                             / 'examples_for_tests')
13
        expected_module0 = 'examples_for_tests.module1'
14
        expected_module1 = 'examples_for_tests.level2.module1'
15
16
        # EXECUTE
17
        modules = discover_modules(path_to_resources)
18
        module_names = [module.__name__ for module in modules]
19
20
        # VERIFY
21
        self.assertEqual(2, len(modules))
22
        self.assertIn(expected_module0, module_names)
23
        self.assertIn(expected_module1, module_names)
24
25
    def test_discover_modules_with_raise(self):
26
        # SETUP
27
        path_to_resources = (Path(__file__).parent.parent / 'test_resources'
28
                             / 'examples_for_tests')
29
30
        # EXECUTE & VERIFY
31
        with self.assertRaises(ImportError):
32
            # test_resources.level2.module2 has invalid syntax.
33
            discover_modules(path_to_resources, raise_on_fail=True)
34
35
    def test_get_modules_from_source(self):
36
        # SETUP
37
        path_to_resources = (Path(__file__).parent.parent / 'test_resources'
38
                             / 'examples_for_tests' / 'level2')
39
        str_path_to_resources = str(path_to_resources)
40
41
        # EXECUTE
42
        a = _get_modules_from_source(path_to_resources)
43
        b = _get_modules_from_source(str_path_to_resources)
44
        c = _get_modules_from_source(a)
45
        d = _get_modules_from_source(b[0])
46
47
        # VERIFY
48
        self.assertTrue(a == b == c == d)
49