Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
esde
toar-public
toarstats
Commits
34eb056b
Commit
34eb056b
authored
Dec 23, 2021
by
Niklas Selke
Browse files
Fixed the current tests.
parent
bac01398
Changes
2
Hide whitespace changes
Inline
Side-by-side
tests/create_sample_data_and_reference_results.py
View file @
34eb056b
...
...
@@ -135,14 +135,15 @@ def create_sample_data(sample_data_dir):
values
[
np
.
random
.
default_rng
().
choice
(
values
.
size
,
size
=
int
(
0.085
*
values
.
size
),
replace
=
False
)]
=
np
.
nan
pd
.
Series
(
values
,
datetime_index
).
to_csv
(
pd
.
Series
(
values
,
datetime_index
).
dropna
().
to_csv
(
Path
(
sample_data_dir
,
"sample_data.csv"
),
header
=
False
)
Path
(
sample_data_dir
,
"sample_metadata.cfg"
).
write_text
(
"[METADATA]
\n
"
"station_lat: 50.906389
\n
"
"station_lon: 6.403889
\n
"
"station_climatic_zone: 3
\n
"
"station_climatic_zone: 3
\n
"
,
encoding
=
"utf-8"
)
...
...
tests/test_toarstats.py
View file @
34eb056b
...
...
@@ -23,7 +23,7 @@ import numpy as np
import
pandas
as
pd
import
pytest
from
toarstats
import
toarstat
s
from
toarstats
.interface
import
calculate_statistic
s
def
get_all_statistics
():
...
...
@@ -82,7 +82,8 @@ def sample_metadata():
"""
parser
=
ConfigParser
()
with
open
(
Path
(
Path
(
__file__
).
resolve
().
parent
,
"sample_data/sample_metadata.cfg"
))
as
file
:
"sample_data/sample_metadata.cfg"
),
encoding
=
"utf-8"
)
as
file
:
parser
.
read_file
(
file
)
Metadata
=
namedtuple
(
"Metadata"
,
[
"station_lat"
,
"station_lon"
,
"station_climatic_zone"
])
...
...
@@ -110,19 +111,22 @@ def test_results_match_reference_results(statistic, sampling, sample_data,
sample_metadata
):
"""Test if the results match old package versions."""
if
statistic
==
"drmdmax1h"
and
sampling
==
"monthly"
:
with
pytest
.
raises
(
ValueError
,
match
=
"Invalid mtype"
):
result
=
toarstats
(
sampling
,
[
statistic
],
sample_data
,
sample_metadata
)
with
pytest
.
raises
(
ValueError
,
match
=
"The drmdmax1h statistic cannot"
" be evaluated with monthly"
" sampling"
):
result
=
calculate_statistics
(
sampling
,
statistic
,
sample_data
,
sample_metadata
)
else
:
result
=
toarstats
(
sampling
,
[
statistic
],
sample_data
,
sample_metadata
)
result
=
calculate_statistics
(
sampling
,
statistic
,
sample_data
,
sample_metadata
)
for
file
in
Path
(
Path
(
__file__
).
resolve
().
parent
,
"reference_results"
Path
(
__file__
).
resolve
().
parent
,
"reference_results"
).
rglob
(
f
"
{
statistic
}
-
{
sampling
}
.csv"
):
expected_result
=
pd
.
read_csv
(
file
,
header
=
None
,
index_col
=
0
,
parse_dates
=
True
)
pd
.
testing
.
assert_index_equal
(
result
.
index
,
expected_result
.
index
,
check_names
=
False
)
if
statistic
==
"w90"
:
if
statistic
==
"w90"
and
sampling
==
"seasonal"
:
with
pytest
.
raises
(
AssertionError
):
np
.
testing
.
assert_allclose
(
result
.
values
,
expected_result
.
values
,
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment