Skip to content

Commit

Permalink
locale: Fix metadata-sensitive tests. (#189)
Browse files Browse the repository at this point in the history
* Specify locale in metadata tests.

* Hardcode locale to yadg tests too.

* Fix more metadata.

* bump schemas to >= 120

* comma for ruff
  • Loading branch information
PeterKraus authored Oct 10, 2024
1 parent 097b578 commit 10b361b
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 4 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ dependencies = [
"pandas >= 2.0",
"babel >= 2.15",
"xarray-datatree >= 0.0.12",
"dgbowl-schemas >= 117",
"dgbowl-schemas >= 120",
]

[project.optional-dependencies]
Expand Down
2 changes: 1 addition & 1 deletion tests/test_extract.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
def test_yadg_extractors_extract_with_metadata(filetype, infile, datadir):
os.chdir(datadir)
outfile = f"{infile}.nc"
ret = extract(filetype=filetype, path=infile)
ret = extract(filetype=filetype, path=infile, locale="en_GB")
# ret.to_netcdf(f"C:/Users/Kraus/Code/yadg/tests/test_extract/{outfile}", engine="h5netcdf")
ref = datatree.open_datatree(outfile, engine="h5netcdf")
compare_datatrees(ret, ref, thislevel=True, descend=True)
26 changes: 26 additions & 0 deletions tests/test_process.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import pytest
import os
import json
import yadg.dgutils
import yadg.core
import datatree
from .utils import compare_datatrees


@pytest.mark.parametrize(
"input",
[
"test_locale_passthrough.json",
],
)
def test_process_locale_passthrough(input, datadir):
os.chdir(datadir)

with open(f"{input}") as infile:
obj = json.load(infile)

schema = yadg.dgutils.update_schema(obj)
ret = yadg.core.process_schema(schema)
# ret.to_netcdf(f"{input}.nc", engine="h5netcdf")
ref = datatree.open_datatree(f"{input}.nc", engine="h5netcdf")
compare_datatrees(ret, ref, thislevel=True, descend=True)
5 changes: 5 additions & 0 deletions tests/test_process/measurement.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
timestamp; elapsed time; T_f; T_fs; T_fo; T_c; T_cs; T_co; N2; O2; alkane; CO/CO2; saturator; pressure; flow low; flow high; cavity flush; heater flow; T_cal
; ; degC; degC; %; degC; degC; %; ml/min; ml/min; ml/min; ml/min; ml/min; mbar; ml/min; ml/min; ml/min; l/min; degC
2019-12-03-09-01-24; 0h 0m59s;20.9;23.9;8.0;18;18;-6;27.17;1.25;0.00;0.00;0.00;1300.0;0.629;1.00;15;11;20.1
2019-12-03-09-02-24; 0h 1m59s;25.6;28.9;15.1;18;18;-3;27.17;1.25;0.00;0.00;0.00;1299.7;0.630;1.00;15;11;19.9
2019-12-03-09-03-25; 0h 3m 0s;32.0;34.0;17.1;18;18;-11;27.17;1.25;0.00;0.00;0.00;1300.3;0.630;1.00;15;11;20.2
27 changes: 27 additions & 0 deletions tests/test_process/test_locale_passthrough.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"version": "5.1",
"metadata": {
"provenance": {"type": "manual"}
},
"step_defaults": {
"timezone": "Europe/Berlin",
"locale": "en_US"
},
"steps": [
{
"tag": "stepdefaults",
"input": {"files": ["measurement.csv"]},
"extractor": {
"filetype": "example"
}
},
{
"tag": "locale-de_DE",
"input": {"files": ["measurement.csv"]},
"extractor": {
"filetype": "example",
"locale": "de_DE"
}
}
]
}
Binary file not shown.
4 changes: 2 additions & 2 deletions tests/test_yadg.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ def test_yadg_preset_roundtrip_uts(datadir):
)
def test_yadg_extract_with_metadata(filetype, infile, datadir):
os.chdir(datadir)
command = ["yadg", "extract", filetype, infile, "test.nc"]
command = ["yadg", "extract", filetype, infile, "test.nc", "--locale", "en_GB"]
subprocess.run(command, check=True)
assert os.path.exists("test.nc")
ret = open_datatree("test.nc", engine="h5netcdf")
Expand All @@ -201,7 +201,7 @@ def test_yadg_extract_with_metadata(filetype, infile, datadir):
)
def test_yadg_extract_meta_only(filetype, infile, flag, datadir):
os.chdir(datadir)
command = ["yadg", "extract", filetype, infile, flag]
command = ["yadg", "extract", filetype, infile, flag, "--locale", "en_GB"]
subprocess.run(command, check=True)
outfile = infile.split(".")[0] + ".json"
assert os.path.exists(outfile)
Expand Down

0 comments on commit 10b361b

Please sign in to comment.