Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
Macao Legacy
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
MACAO
Macao Legacy
Commits
f514de52
Commit
f514de52
authored
Jul 18, 2024
by
Eliott Sammier
Browse files
Options
Downloads
Patches
Plain Diff
Refactor to use subtests instead of test suites
parent
81ebc110
Branches
Branches containing commit
No related tags found
Loading
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
tetras_extraction/macao_12/script/src/test.py
+28
-42
28 additions, 42 deletions
tetras_extraction/macao_12/script/src/test.py
with
28 additions
and
42 deletions
tetras_extraction/macao_12/script/src/test.py
+
28
−
42
View file @
f514de52
...
...
@@ -8,19 +8,17 @@ TESTS_DIR = Path(RESULT_DIR + "/../tests").resolve()
class
CompareFiles
(
unittest
.
TestCase
):
"""
A test case that
takes a
file
from
`TESTS_DIR`, finds the corresponding
"""
A test case that
checks every
file
in
`TESTS_DIR`, finds the corresponding
file in the generated results (in `RESULT_DIR`) and compares them using
`diff`, printing the full diff if they
'
re not identical.
"""
`diff`, printing the full diff if they
'
re not identical.
"""
def
__init__
(
self
,
expected
:
Path
)
->
None
:
super
().
__init__
()
self
.
expected
=
expected
def
runTest
(
self
):
def
runTest
(
self
)
->
None
:
for
file
in
TESTS_DIR
.
rglob
(
"
*
"
):
# Recursively find all files
if
file
.
is_file
():
with
self
.
subTest
():
# ex: for a file `TESTS_DIR/pg60/index.md`, will find the first file in
# `RESULT_DIR` whose path ends with `pg60/index.md`
relative
=
self
.
expected
.
relative_to
(
TESTS_DIR
)
relative
=
file
.
relative_to
(
TESTS_DIR
)
cmd
=
subprocess
.
run
(
[
"
find
"
,
...
...
@@ -35,26 +33,14 @@ class CompareFiles(unittest.TestCase):
actual
=
cmd
.
stdout
.
splitlines
()[
0
]
# Any exceptions in the lookup above cause the test case to fail, this
# is what we want.
self
.
compare_files
(
str
(
file
),
actual
)
def
compare_files
(
self
,
expected
:
str
,
actual
:
str
):
# Run the diff between the two files, without `capture_output=True`,
# therefore the diff is printed to the console
diffcmd
=
subprocess
.
run
(
[
"
diff
"
,
"
--color=always
"
,
"
-u
"
,
self
.
expected
,
actual
]
)
diffcmd
=
subprocess
.
run
([
"
diff
"
,
"
--color=always
"
,
"
-u
"
,
expected
,
actual
])
self
.
assertEqual
(
diffcmd
.
returncode
,
0
,
"
see diff output above.
"
)
class
ConversionTests
(
unittest
.
TestSuite
):
"""
A test suite that checks all files in the tests directory, and tries
to compare it with its generated counterpart
"""
def
__init__
(
self
,
tests
)
->
None
:
super
().
__init__
(
tests
)
for
file
in
TESTS_DIR
.
rglob
(
"
*
"
):
# Recursively find all files
if
file
.
is_file
():
self
.
addTest
(
CompareFiles
(
file
))
if
__name__
==
"
__main__
"
:
runner
=
unittest
.
TextTestRunner
()
runner
.
run
(
ConversionTests
([]))
unittest
.
main
()
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment