Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
python_DSI_Parser
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
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
Benedikt
python_DSI_Parser
Commits
f4054794
Commit
f4054794
authored
1 year ago
by
Vanessa Stehr
Browse files
Options
Downloads
Patches
Plain Diff
Write some test cases
More will follow
parent
e568d84b
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
requirements.txt
+4
-0
4 additions, 0 deletions
requirements.txt
test_main.py
+64
-0
64 additions, 0 deletions
test_main.py
with
68 additions
and
0 deletions
requirements.txt
0 → 100644
+
4
−
0
View file @
f4054794
iniconfig
==2.0.0
packaging
==23.1
pluggy
==1.3.0
pytest
==7.4.1
This diff is collapsed.
Click to expand it.
test_main.py
0 → 100644
+
64
−
0
View file @
f4054794
import
pytest
from
dsiParser
import
dsiTree
def
test_baseCase
():
# Most basic case: one unit without prefix or exponent
tree
=
dsiTree
(
r
'
\metre
'
)
assert
tree
.
tree
==
[[[
''
,
'
metre
'
,
''
]]]
assert
tree
.
toLatex
()
==
r
'
\mathrm{m}
'
assert
tree
.
valid
assert
tree
.
warnings
==
[]
def
test_robustness
():
# Unknown unit
with
pytest
.
warns
(
RuntimeWarning
,
match
=
'
The identifier
\"
foo
\"
does not match any D-SI units!
'
):
tree
=
dsiTree
(
r
'
\foo
'
)
assert
tree
.
toLatex
()
==
r
'
{\color{red}\mathrm{foo}}
'
assert
not
tree
.
valid
assert
len
(
tree
.
warnings
)
==
1
assert
tree
.
warnings
==
[
'
The identifier
\"
foo
\"
does not match any D-SI units!
'
]
# Unknown string in the middle of input
with
pytest
.
warns
(
RuntimeWarning
,
match
=
'
The identifier
\"
mini
\"
does not match any D-SI units!
'
):
tree
=
dsiTree
(
r
'
\kilo\metre\per\mini\second
'
)
print
(
tree
.
toLatex
())
assert
tree
.
toLatex
()
==
r
'
\frac{\mathrm{k}\mathrm{m}}{{\color{red}\mathrm{mini}}\,\mathrm{s}}
'
assert
not
tree
.
valid
assert
len
(
tree
.
warnings
)
==
1
assert
tree
.
warnings
==
[
'
The identifier
\"
mini
\"
does not match any D-SI units!
'
]
def
test_power
():
# power
powerTree
=
dsiTree
(
r
'
\metre\tothe{2}
'
)
assert
powerTree
.
tree
==
[[[
''
,
'
metre
'
,
'
2
'
]]]
assert
powerTree
.
toLatex
()
==
r
'
\mathrm{m}^{2}
'
assert
powerTree
.
valid
assert
powerTree
.
warnings
==
[]
assert
dsiTree
(
r
'
\metre\tothe{0.5}
'
).
toLatex
()
==
r
'
\sqrt{\mathrm{m}}
'
assert
dsiTree
(
r
'
\metre\tothe{-2}
'
).
toLatex
()
==
r
'
\mathrm{m}^{-2}
'
assert
dsiTree
(
r
'
\metre\tothe{1337}
'
).
toLatex
()
==
r
'
\mathrm{m}^{1337}
'
def
test_prefix
():
# prefix
prefixTree
=
dsiTree
(
r
'
\kilo\metre
'
)
assert
prefixTree
.
tree
==
[[[
'
kilo
'
,
'
metre
'
,
''
]]]
assert
prefixTree
.
toLatex
()
==
r
'
\mathrm{k}\mathrm{m}
'
assert
prefixTree
.
valid
def
test_node
():
# full node
fullNodeTree
=
dsiTree
(
r
'
\kilo\metre\tothe{2}
'
)
assert
fullNodeTree
.
tree
==
[[[
'
kilo
'
,
'
metre
'
,
'
2
'
]]]
assert
fullNodeTree
.
toLatex
()
==
r
'
\mathrm{k}\mathrm{m}^{2}
'
assert
fullNodeTree
.
valid
def
test_fraction
():
fractionTree
=
dsiTree
(
r
'
\mega\metre\per\second\tothe{2}
'
)
assert
fractionTree
.
tree
==
[[[
'
mega
'
,
'
metre
'
,
''
]],[[
''
,
'
second
'
,
'
2
'
]]]
assert
fractionTree
.
toLatex
()
==
r
'
\frac{\mathrm{M}\mathrm{m}}{\mathrm{s}^{2}}
'
assert
fractionTree
.
valid
def
test_empty
():
with
pytest
.
warns
(
RuntimeWarning
,
match
=
'
Given D-SI string is empty!
'
):
assert
dsiTree
(
''
).
toLatex
()
==
''
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