|
1
|
|
|
from pathlib import Path |
|
2
|
|
|
from unittest import TestCase |
|
3
|
|
|
|
|
4
|
|
|
from barentsz._discover import discover_paths |
|
5
|
|
|
|
|
6
|
|
|
|
|
7
|
|
|
class TestDiscoverPaths(TestCase): |
|
8
|
|
|
|
|
9
|
|
View Code Duplication |
def test_discover_paths(self): |
|
|
|
|
|
|
10
|
|
|
# SETUP |
|
11
|
|
|
path_to_resources = (Path(__file__).parent.parent / 'test_resources' |
|
12
|
|
|
/ 'examples_for_tests') |
|
13
|
|
|
expected0 = path_to_resources / 'module1.py' |
|
14
|
|
|
expected1 = path_to_resources / '__init__.py' |
|
15
|
|
|
expected2 = path_to_resources / '_private_module.py' |
|
16
|
|
|
expected3 = path_to_resources / 'level2/module1.py' |
|
17
|
|
|
expected4 = path_to_resources / 'level2/module2.py' |
|
18
|
|
|
expected5 = path_to_resources / 'level2/__init__.py' |
|
19
|
|
|
expected6 = path_to_resources / 'not_a_package/module3.py' |
|
20
|
|
|
expected7 = path_to_resources / 'not_a_package/is_a_package/module5.py' |
|
21
|
|
|
expected8 = path_to_resources / 'not_a_package/is_a_package/__init__.py' |
|
22
|
|
|
|
|
23
|
|
|
# EXECUTE |
|
24
|
|
|
paths = discover_paths(path_to_resources, '**/*.py') |
|
25
|
|
|
|
|
26
|
|
|
# VERIFY |
|
27
|
|
|
self.assertEqual(9, len(paths)) |
|
28
|
|
|
self.assertIn(expected0, paths) |
|
29
|
|
|
self.assertIn(expected1, paths) |
|
30
|
|
|
self.assertIn(expected2, paths) |
|
31
|
|
|
self.assertIn(expected3, paths) |
|
32
|
|
|
self.assertIn(expected4, paths) |
|
33
|
|
|
self.assertIn(expected5, paths) |
|
34
|
|
|
self.assertIn(expected6, paths) |
|
35
|
|
|
self.assertIn(expected7, paths) |
|
36
|
|
|
self.assertIn(expected8, paths) |
|
37
|
|
|
|
|
38
|
|
View Code Duplication |
def test_discover_paths_with_a_string(self): |
|
|
|
|
|
|
39
|
|
|
# SETUP |
|
40
|
|
|
path_to_resources = (Path(__file__).parent.parent / 'test_resources' |
|
41
|
|
|
/ 'examples_for_tests') |
|
42
|
|
|
expected0 = path_to_resources / 'module1.py' |
|
43
|
|
|
expected1 = path_to_resources / '__init__.py' |
|
44
|
|
|
expected2 = path_to_resources / '_private_module.py' |
|
45
|
|
|
expected3 = path_to_resources / 'level2/module1.py' |
|
46
|
|
|
expected4 = path_to_resources / 'level2/module2.py' |
|
47
|
|
|
expected5 = path_to_resources / 'level2/__init__.py' |
|
48
|
|
|
expected6 = path_to_resources / 'not_a_package/module3.py' |
|
49
|
|
|
expected7 = path_to_resources / 'not_a_package/is_a_package/module5.py' |
|
50
|
|
|
expected8 = path_to_resources / 'not_a_package/is_a_package/__init__.py' |
|
51
|
|
|
|
|
52
|
|
|
# EXECUTE |
|
53
|
|
|
paths = discover_paths(str(path_to_resources), '**/*.py') |
|
54
|
|
|
|
|
55
|
|
|
# VERIFY |
|
56
|
|
|
self.assertEqual(9, len(paths)) |
|
57
|
|
|
self.assertIn(expected0, paths) |
|
58
|
|
|
self.assertIn(expected1, paths) |
|
59
|
|
|
self.assertIn(expected2, paths) |
|
60
|
|
|
self.assertIn(expected3, paths) |
|
61
|
|
|
self.assertIn(expected4, paths) |
|
62
|
|
|
self.assertIn(expected5, paths) |
|
63
|
|
|
self.assertIn(expected6, paths) |
|
64
|
|
|
self.assertIn(expected7, paths) |
|
65
|
|
|
self.assertIn(expected8, paths) |
|
66
|
|
|
|
|
67
|
|
|
def test_discover_paths_with_wrong_arg_type(self): |
|
68
|
|
|
# EXECUTE & VERIFY |
|
69
|
|
|
with self.assertRaises(ValueError): |
|
70
|
|
|
discover_paths({}, '**/*.py') |
|
71
|
|
|
|