FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
codeql/python/extractor/tests/test_projectlayout.py at main · github/codeql · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
github
/
codeql
Public
Notifications
You must be signed in to change notification settings
Fork
2.1k
Star
10k
Code
Issues
998
Pull requests
466
Discussions
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Discussions
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
codeql
/
python
/
extractor
/
tests
/
test_projectlayout.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
133 lines (104 loc) · 4.32 KB
Breadcrumbs
codeql
/
python
/
extractor
/
tests
/
test_projectlayout.py
Copy path
File metadata and controls
133 lines (104 loc) · 4.32 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#
# This is a port of com.semmle.extractor.projectstructure.ProjectLayoutTests
# and must be kept in sync
#
from
semmle
.
projectlayout
import
ProjectLayout
import
unittest
PROJECT_LAYOUT
=
ProjectLayout
(
u"""
@Example
/this/path/will/remain
-this/path/will/not
/and/look//this/path/is/ok
#Source
/src//
-/src/tests
#Tests
/src/tests//
#Generated
/gen
/gen2//gen
#Misc
misc//
othermisc
//thirdmisc
#ExecutionOrder
ex/order
-ex/order/tests/a
ex/order/tests
/src/tests//testA.c
#Patterns
**/*.included
**/inc
-**/exc
my
-my/excluded/**/files
my/**//files/**/a
//**/weird"""
.
split
(
'
\n
'
))
MINIMAL_LAYOUT
=
ProjectLayout
(
u"""
/included/path
- excluded/path"""
.
split
(
'
\n
'
))
CS_LAYOUT
=
ProjectLayout
(
u"""
#Production code
/
-**/src.test
#Testing code
**/src.test"""
.
split
(
'
\n
'
))
def
map
(
path
):
return
PROJECT_LAYOUT
.
artificial_path
(
path
)
class
ProjectLayoutTests
(
unittest
.
TestCase
):
def
test_advanced_patterns
(
self
):
self
.
assertEqual
(
u"/Patterns/firstPattern.included"
,
map
(
u"/firstPattern.included"
))
self
.
assertEqual
(
u"/Patterns/P1/P2/a.included"
,
map
(
u"/P1/P2/a.included"
))
self
.
assertEqual
(
u"/Patterns/P3/P4/inc"
,
map
(
u"/P3/P4/inc"
))
self
.
assertEqual
(
u"/Patterns/P4/P5/inc/a.c"
,
map
(
u"/P4/P5/inc/a.c"
))
assert
map
(
u"/P3/P4/inc/exc"
)
is
None
assert
map
(
u"/P3/P4/inc/exc/a/b.c"
)
is
None
self
.
assertEqual
(
u"/Patterns/my/code"
,
map
(
u"/my/code"
))
assert
map
(
"u/my/excluded/but/very/interesting/files/a.c"
)
is
None
self
.
assertEqual
(
u"/Patterns/files/a/b.c"
,
map
(
u"/my/excluded/but/very/interesting/files/a/b.c"
))
self
.
assertEqual
(
u"/Patterns/P5/P6/weird"
,
map
(
u"/P5/P6/weird"
))
def
test_non_virtual_path
(
self
):
self
.
assertEqual
(
u"/this/path/will/remain/the-same.c"
,
map
(
u"/this/path/will/remain/the-same.c"
))
assert
map
(
u"/this/path/will/not/be/included.c"
)
is
None
self
.
assertEqual
(
u"/this/path/is/ok/to-use.c"
,
map
(
u"/and/look/this/path/is/ok/to-use.c"
))
def
test_ignore_unmentioned_paths
(
self
):
assert
map
(
u"/lib/foo.c"
)
is
None
def
test_do_not_match_partial_names
(
self
):
assert
map
(
u"/gen2/foo.c"
)
is
None
assert
map
(
u"/src2/foo.c"
)
is
None
def
test_simple_mapping
(
self
):
self
.
assertEqual
(
u"/Source/foo.c"
,
map
(
u"/src/foo.c"
))
def
test_match_in_sequence
(
self
):
self
.
assertEqual
(
u"/ExecutionOrder/ex/order/tests/a"
,
map
(
"/ex/order/tests/a"
))
self
.
assertEqual
(
u"/Tests/testA.c"
,
map
(
u"/src/tests/testA.c"
))
def
test_excluded_and_included
(
self
):
self
.
assertEqual
(
u"/Tests/test.c"
,
map
(
"/src/tests/test.c"
))
def
test_without_double_slashes
(
self
):
self
.
assertEqual
(
u"/Generated/gen/gen.c"
,
map
(
"/gen/gen.c"
))
def
test_middle_double_slash
(
self
):
self
.
assertEqual
(
u"/Generated/gen/gen.c"
,
map
(
"/gen2/gen/gen.c"
))
def
test_initial_double_slash
(
self
):
self
.
assertEqual
(
u"/Misc/thirdmisc/misc.c"
,
map
(
"/thirdmisc/misc.c"
))
def
test_map_directories
(
self
):
self
.
assertEqual
(
u"/Generated/gen"
,
map
(
"/gen"
))
self
.
assertEqual
(
u"/Generated/gen/"
,
map
(
"/gen/"
))
self
.
assertEqual
(
u"/Source"
,
map
(
"/src"
))
self
.
assertEqual
(
u"/Misc/thirdmisc"
,
map
(
"/thirdmisc"
))
def
test_missing_initial_slash
(
self
):
self
.
assertEqual
(
u"/Misc"
,
map
(
"/misc"
))
self
.
assertEqual
(
u"/Misc/othermisc"
,
map
(
"/othermisc"
))
def
test_minimal_layout
(
self
):
self
.
assertEqual
(
u"/included/path/foo.c"
,
MINIMAL_LAYOUT
.
artificial_path
(
"/included/path/foo.c"
))
assert
MINIMAL_LAYOUT
.
artificial_path
(
u"/excluded/path/name"
)
is
None
def
test_project_names
(
self
):
self
.
assertEqual
(
u"Example"
,
PROJECT_LAYOUT
.
project_name
())
self
.
assertEqual
(
u"Example"
,
PROJECT_LAYOUT
.
project_name
(
"Something else"
))
self
.
assertRaises
(
Exception
,
lambda
:
MINIMAL_LAYOUT
.
project_name
())
self
.
assertEqual
(
u"My project"
,
MINIMAL_LAYOUT
.
project_name
(
"My project"
))
def
test_cs
(
self
):
self
.
assertEqual
(
u"/Production code"
,
CS_LAYOUT
.
artificial_path
(
u""
))
self
.
assertEqual
(
u"/Production code/"
,
CS_LAYOUT
.
artificial_path
(
u"/"
));
self
.
assertEqual
(
u"/Production code/AppAuth/ear/App/src"
,
CS_LAYOUT
.
artificial_path
(
u"/AppAuth/ear/App/src"
));
self
.
assertEqual
(
u"/Testing code/BUILD/bun/BUILD/src.test"
,
CS_LAYOUT
.
artificial_path
(
u"/BUILD/bun/BUILD/src.test"
));
if
__name__
==
"__main__"
:
unittest
.
main
()
Back
|
FazBrowse Home
|
New Git URL