forked from ecmwf/eccodes-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_bufr_examples.py
More file actions
85 lines (70 loc) · 2.28 KB
/
test_bufr_examples.py
File metadata and controls
85 lines (70 loc) · 2.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# Copyright 2022- ECMWF.
#
# This software is licensed under the terms of the Apache Licence Version 2.0
# which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
# In applying this licence, ECMWF does not waive the privileges and immunities
# granted to it by virtue of its status as an intergovernmental organisation
# nor does it submit to any jurisdiction.
import io
import sys
from pathlib import Path
import pytest
if sys.platform.startswith("win32"):
pytest.skip("Not applicable on Windows", allow_module_level=True)
@pytest.fixture(autouse=True)
def fixture(monkeypatch):
this_dir = Path(__file__).parent
monkeypatch.syspath_prepend(this_dir.parent)
# monkeypatch.chdir(this_dir.parent / 'data')
monkeypatch.chdir(this_dir / "sample-data")
def compare(output: str, reference: Path):
if not reference.exists():
reference.write_text(output)
try:
assert output == reference.read_text()
except AssertionError as error:
reference.with_suffix(reference.suffix + ".bad").write_text(output)
raise error
else:
reference.with_suffix(reference.suffix + ".bad").unlink(missing_ok=True)
inputs = [
"acars.bufr",
"ahi-himawari-8.bufr",
"amsu-a-noaa-19.bufr",
"amv-goes-9.bufr",
"amv-insat-3d.bufr",
"amv-meteosat-9.bufr",
"amv-noaa-20.bufr",
"aura-omi-ak.bufr",
"buoy-drifting.bufr",
"geos-abi-goes-16.bufr",
"geos-mviri-meteosat-7.bufr",
"hdob.bufr",
"rwp.bufr",
"rwp_jma.bufr",
"saral-altika.bufr",
"sral_sentinel_3a.bufr",
"synop.bufr",
"synop_multi_subset.bufr",
"temp.bufr",
"terra-modis-aerosol.bufr",
"wave.bufr",
]
@pytest.mark.parametrize("input", inputs)
def test_attributes_example(input):
from examples.attributes import run_example
input = Path(input)
stream = io.StringIO()
run_example(input, output=stream)
output = stream.getvalue()
reference = input.with_suffix(".attributes")
compare(output, reference)
@pytest.mark.parametrize("input", inputs)
def test_items_example(input):
from examples.items import run_example
input = Path(input)
stream = io.StringIO()
run_example(input, stream)
output = stream.getvalue()
reference = input.with_suffix(".items")
compare(output, reference)