Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
finam-mhm
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
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
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Afid Nur Kholis
finam-mhm
Commits
0161f4ef
Commit
0161f4ef
authored
1 year ago
by
Sebastian Müller
🐈
Browse files
Options
Downloads
Patches
Plain Diff
add tests
parent
ff1e7cb7
No related branches found
No related tags found
No related merge requests found
Changes
3
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
.gitignore
+2
-1
2 additions, 1 deletion
.gitignore
tests/test_files/ref_runoff.csv
+8762
-0
8762 additions, 0 deletions
tests/test_files/ref_runoff.csv
tests/test_mhm.py
+79
-2
79 additions, 2 deletions
tests/test_mhm.py
with
8843 additions
and
3 deletions
.gitignore
+
2
−
1
View file @
0161f4ef
...
...
@@ -127,11 +127,12 @@ examples/test_domain
examples/qmod.nc
examples/qmod_couple.nc
examples/aet.nc
examples/*.csv
tests/runoff_out.csv
/docs/build/
/docs/finam_mhm.*
/docs/modules.rst
*.csv
*.DS_Store
...
...
This diff is collapsed.
Click to expand it.
tests/test_files/ref_runoff.csv
0 → 100644
+
8762
−
0
View file @
0161f4ef
This diff is collapsed.
Click to expand it.
tests/test_mhm.py
+
79
−
2
View file @
0161f4ef
import
os
import
shutil
import
unittest
from
datetime
import
datetime
,
timedelta
from
pathlib
import
Path
import
finam
as
fm
import
mhm
import
numpy
as
np
from
numpy.testing
import
assert_allclose
import
finam_mhm
as
fm_mhm
def
str2date
(
dtstr
):
return
datetime
.
fromisoformat
(
dtstr
)
class
TestMHM
(
unittest
.
TestCase
):
def
test_creation
(
self
):
pass
@classmethod
def
setUpClass
(
self
):
self
.
here
=
Path
(
__file__
).
parent
os
.
chdir
(
self
.
here
)
self
.
test_domain
=
self
.
here
/
"
test_domain
"
mhm
.
download_test
(
path
=
self
.
test_domain
)
def
tearDown
(
self
):
# move out of test-domain directory after each test
os
.
chdir
(
self
.
here
)
@classmethod
def
tearDownClass
(
self
):
shutil
.
rmtree
(
self
.
test_domain
)
def
test_run
(
self
):
start_date
=
datetime
(
1990
,
1
,
1
)
end_date
=
datetime
(
1991
,
1
,
1
)
mhm
=
fm_mhm
.
MHM
(
cwd
=
self
.
test_domain
)
csv
=
fm
.
modules
.
CsvWriter
(
path
=
self
.
here
/
"
runoff_out.csv
"
,
inputs
=
[
"
Runoff
"
],
time_column
=
"
Time
"
,
separator
=
"
,
"
,
start
=
start_date
,
step
=
timedelta
(
hours
=
1
),
)
composition
=
fm
.
Composition
([
mhm
,
csv
])
composition
.
initialize
()
(
mhm
.
outputs
[
"
L1_TOTAL_RUNOFF
"
]
>>
fm
.
adapters
.
GridToValue
(
func
=
lambda
x
:
x
[
0
,
8
,
4
])
>>
csv
[
"
Runoff
"
]
)
composition
.
run
(
start_time
=
start_date
,
end_time
=
end_date
)
ref
=
np
.
genfromtxt
(
self
.
here
/
"
test_files/ref_runoff.csv
"
,
names
=
True
,
converters
=
{
0
:
str2date
},
delimiter
=
"
,
"
,
dtype
=
None
,
encoding
=
"
utf-8
"
,
)
ref
=
np
.
array
([
i
[
1
]
for
i
in
ref
])
out
=
np
.
genfromtxt
(
self
.
here
/
"
runoff_out.csv
"
,
names
=
True
,
converters
=
{
0
:
str2date
},
delimiter
=
"
,
"
,
dtype
=
None
,
encoding
=
"
utf-8
"
,
)
out
=
np
.
array
([
i
[
1
]
for
i
in
out
])
assert_allclose
(
ref
,
out
)
if
__name__
==
"
__main__
"
:
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