-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_utils.py
106 lines (81 loc) · 3.8 KB
/
test_utils.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# Utilities that are reused across multiple tests.
import os
import unittest
import inclusions_config
BASIC_TEST_CONFIG = {
"name": "basic_test",
"repo_root": os.path.abspath("./test/test_repo"),
"included_files": ["foo/foo.h",],
}
inclusions_config.EvaluateConfig(BASIC_TEST_CONFIG)
BASIC_TEST_INCLUDED_FILES_TO_LIMIT_TO = ["foo/foo.h"]
COMPLEX_TEST_CONFIG = {
"name": "complex_test",
"repo_root": os.path.abspath("./test/test_repo"),
"included_files": [
"bar/bar.h",
"bar/core.h",
],
}
inclusions_config.EvaluateConfig(COMPLEX_TEST_CONFIG)
COMPLEX_TEST_INCLUDED_FILES_TO_LIMIT_TO = ["bar/bar.h"]
def VerifyBasicIncludingToIncluded(test_case, including_to_included):
including_files = including_to_included.keys()
including_files.sort()
expected_including_files = [
"bar/bar.h", "bar/core.h", "foo/foo.cc", "foo/foo_unittest.cc"
]
test_case.assertEqual(including_files, expected_including_files)
for f in including_to_included:
test_case.assertEqual(including_to_included[f], ["foo/foo.h"])
def VerifyBasicIncludingToIncludedWithLimitedIncludes(test_case,
including_to_included):
# Nothing should have changed, as the set to limit to is equal to the original
# |included_files| set.
VerifyBasicIncludingToIncluded(test_case, including_to_included)
def VerifyBasicIncludedToIncluding(test_case, included_to_including):
test_case.assertIn("foo/foo.h", included_to_including)
inclusions_of_foo = included_to_including["foo/foo.h"]
inclusions_of_foo.sort()
test_case.assertEqual(
inclusions_of_foo,
["bar/bar.h", "bar/core.h", "foo/foo.cc", "foo/foo_unittest.cc"])
def VerifyBasicIncludedToIncludingWithLimitedIncludes(test_case,
included_to_including):
# Nothing should have changed, as the set to limit to is equal to the original
# |included_files| set.
VerifyBasicIncludedToIncluding(test_case, included_to_including)
def VerifyComplexIncludingToIncluded(test_case, including_to_included):
including_files = including_to_included.keys()
including_files.sort()
test_case.assertEqual(
including_files, ["bar/bar.h", "bar/baz/bar_core_factory.h", "foo/foo.h"])
test_case.assertEqual(including_to_included["bar/bar.h"], ["bar/core.h"])
test_case.assertEqual(including_to_included["bar/baz/bar_core_factory.h"],
["bar/core.h"])
test_case.assertEqual(including_to_included["foo/foo.h"],
["bar/bar.h", "bar/core.h"])
def VerifyComplexIncludingToIncludedWithLimitedIncludes(test_case,
including_to_included):
including_files = including_to_included.keys()
including_files.sort()
test_case.assertEqual(including_files, ["foo/foo.h"])
test_case.assertEqual(including_to_included["foo/foo.h"], ["bar/bar.h"])
def VerifyComplexIncludedToIncluding(test_case, included_to_including):
test_case.assertIn("bar/bar.h", included_to_including)
inclusions_of_bar = included_to_including["bar/bar.h"]
inclusions_of_bar.sort()
test_case.assertEqual(inclusions_of_bar, ["foo/foo.h"])
test_case.assertIn("bar/core.h", included_to_including)
inclusions_of_core = included_to_including["bar/core.h"]
inclusions_of_core.sort()
test_case.assertEqual(
inclusions_of_core,
["bar/bar.h", "bar/baz/bar_core_factory.h", "foo/foo.h"])
def VerifyComplexIncludedToIncludingWithLimitedIncludes(test_case,
included_to_including):
test_case.assertEqual(1, len(included_to_including))
test_case.assertIn("bar/bar.h", included_to_including)
inclusions_of_bar = included_to_including["bar/bar.h"]
inclusions_of_bar.sort()
test_case.assertEqual(inclusions_of_bar, ["foo/foo.h"])