FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
codeql/python/extractor/tests/test_patterns.py at codeql-cli/v2.25.5 · 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
997
Pull requests
455
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_patterns.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
27 lines (22 loc) · 1.24 KB
Breadcrumbs
codeql
/
python
/
extractor
/
tests
/
test_patterns.py
Copy path
File metadata and controls
27 lines (22 loc) · 1.24 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
import
os
import
json
import
subprocess
import
semmle
.
path_filters
from
tests
import
test_utils
class
ExtractorPatternsTest
(
test_utils
.
ExtractorTest
):
def
__init__
(
self
,
name
):
super
(
ExtractorPatternsTest
,
self
).
__init__
(
name
)
def
test
(
self
):
repo_dir
=
subprocess
.
Popen
([
"git"
,
"rev-parse"
,
"--show-toplevel"
],
stdout
=
subprocess
.
PIPE
).
communicate
()[
0
].
rstrip
().
decode
(
"utf-8"
)
test_file_path
=
os
.
path
.
abspath
(
os
.
path
.
join
(
repo_dir
,
".."
,
"unit-tests"
,
"files"
,
"pattern-matching"
,
"patterns.json"
))
with
open
(
test_file_path
)
as
test_file
:
test_patterns
=
json
.
load
(
test_file
)
for
test_pattern
in
test_patterns
:
pattern
=
test_pattern
[
"pattern"
]
regex
=
semmle
.
path_filters
.
glob_to_regex
(
pattern
)
for
matching_path
in
test_pattern
[
"should_match"
]:
self
.
assertTrue
(
regex
.
match
(
matching_path
),
"Pattern
\"
%s
\"
did not match path
\"
%s
\"
."
%
(
pattern
,
matching_path
))
for
matching_path
in
test_pattern
[
"shouldnt_match"
]:
self
.
assertFalse
(
regex
.
match
(
matching_path
),
"Pattern
\"
%s
\"
matched path
\"
%s
\"
."
%
(
pattern
,
matching_path
))
def
test_escape_prefix
(
self
):
semmle
.
path_filters
.
glob_to_regex
(
"x"
,
prefix
=
"foo
\\
"
)
Back
|
FazBrowse Home
|
New Git URL