-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathtest_pycycle.py
88 lines (66 loc) · 3.21 KB
/
test_pycycle.py
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
from __future__ import print_function
import os
import pytest
import pycycle.utils
def test_get_path_from_package_name():
func = pycycle.utils.get_path_from_package_name
assert func('/test/one/two', 'some.package') == '/test/one/two/some/package.py'
assert func('', 'some.package') == ''
assert func('/', None) == ''
assert func(None, 'some.package') == ''
assert func('/test/', 'some_package') == '/test/some_package.py'
def test_format_path():
pass
def test_simple_project():
project = {'path': os.path.abspath('./tests/_projects/a_references_b_b_references_a'),
'has_cycle': True,
'result': 'b_module -> a_module: Line 1 =>> b_module'}
root_node = pycycle.utils.read_project(project['path'])
assert root_node != None
assert pycycle.utils.check_if_cycles_exist(
root_node) == project['has_cycle']
assert pycycle.utils.get_cycle_path(root_node, acc=[], seen=set()) == project['result']
def test_no_circular_imports():
project = {'path': os.path.abspath('./tests/_projects/has_no_circular_imports'),
'has_cycle': False,
'result': ''}
root_node = pycycle.utils.read_project(project['path'])
assert root_node is not None
assert pycycle.utils.check_if_cycles_exist(
root_node) == project['has_cycle']
assert pycycle.utils.get_cycle_path(root_node, acc=[], seen=set()) == ''
def test_large_circle():
project = {'path': os.path.abspath('./tests/_projects/large_circle'),
'has_cycle': True,
'result': 'a_module.a_file -> a_module.b_module.b_file: Line 1 -> c_module.c_file: Line 1 -> d_module.d_file: Line 1 =>> a_module.a_file'}
root_node = pycycle.utils.read_project(project['path'])
assert root_node is not None
assert pycycle.utils.check_if_cycles_exist(
root_node) == project['has_cycle']
assert pycycle.utils.get_cycle_path(root_node, acc=[], seen=set()) == project['result']
def test_large_no_circle():
project = {'path': os.path.abspath('./tests/_projects/large_without_circle'),
'has_cycle': False,
'result': ''}
root_node = pycycle.utils.read_project(project['path'])
assert root_node is not None
assert pycycle.utils.check_if_cycles_exist(
root_node) == project['has_cycle']
assert pycycle.utils.get_cycle_path(root_node, acc=[], seen=set()) == ''
def test_relative_imports():
project = {'path': os.path.abspath('./tests/_projects/relative_imports'),
'has_cycle': True,
'result': 'myapp.models -> managers: Line 1 =>> myapp.models'}
root_node = pycycle.utils.read_project(project['path'])
assert root_node is not None
assert pycycle.utils.check_if_cycles_exist(
root_node) == project['has_cycle']
assert pycycle.utils.get_cycle_path(root_node, acc=[], seen=set()) == project['result']
def test_import_context():
project = {'path': os.path.abspath('./tests/_projects/large_circle_context'),
'has_cycle': False,
'result': ''}
root_node = pycycle.utils.read_project(project['path'])
assert root_node is not None
assert pycycle.utils.check_if_cycles_exist(
root_node) == project['has_cycle']