Skip to content

Commit

Permalink
WIP: refactoring to use a separate read method implementing a context…
Browse files Browse the repository at this point in the history
… manager for the actrisebas reader
  • Loading branch information
Jan Griesfeller committed Oct 29, 2024
1 parent 979cc27 commit 91f2502
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 38 deletions.
4 changes: 3 additions & 1 deletion src/pyaro_readers/actrisebas/ActrisEbasReader.py
Original file line number Diff line number Diff line change
Expand Up @@ -496,5 +496,7 @@ def description(self):
def url(self):
return "https://github.com/metno/pyaro-readers"

@contextmanager
def read(self):
return reader_class().reader.read
with self.reader_class().read() as ts:
yield ts
51 changes: 14 additions & 37 deletions tests/test_ActrisEbasReader.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class TestActrisEbasTimeSeriesReader(unittest.TestCase):

def test_api_online(self, url=TEST_URL):
try:
req = urllib.request.Request(TEST_URL, method="HEAD")
req = urllib.request.Request(url, method="HEAD")
resp = urllib.request.urlopen(req)
resp.url
return True
Expand Down Expand Up @@ -58,22 +58,14 @@ def test_flag_list_online(self):
engine.description()
assert engine.args()

# def test_api_reading(self):
# # test access to the EBAS API
# filters={"variables": {"include": ["ozone mass concentration", ]}}
# engine = pyaro.list_timeseries_engines()[self.engine]
# with engine.open(filters=filters) as ts:
# # test that the definitions file could be read properly
# self.assertGreaterEqual(len(ts.variables()), 2)
#
def test_api_reading_small_data_set(self):
# test access to the EBAS API
filters = {
"stations": {"include": ["Birkenes II", "Jungfraujoch"]},
# "variables": {
# "include": self.vars_to_read,
# },
}
# filters = {
# "stations": {"include": ["Birkenes II", "Jungfraujoch"]},
# # "variables": {
# # "include": self.vars_to_read,
# # },
# }
engine = pyaro.list_timeseries_engines()[self.engine]
read_obj = engine.open(
filters=self.station_filter, vars_to_read=self.vars_to_read
Expand Down Expand Up @@ -108,12 +100,6 @@ def test_api_reading_small_data_set(self):

def test_api_reading_pyaerocom_naming(self):
# test access to the EBAS API
filters = {
"stations": {"include": ["Birkenes II", "Jungfraujoch"]},
# "variables": {
# "include": self.vars_to_read,
# },
}
# test variable by variable
for _var in self.pyaerocom_vars_to_read:
engine = pyaro.list_timeseries_engines()[self.engine]
Expand All @@ -127,28 +113,19 @@ def test_api_reading_pyaerocom_naming(self):
self.assertIn("revision", ts.metadata())


#
# #
# def test_wrappers(self):
# engine = pyaro.list_timeseries_engines()[self.engine]
# new_var_name = "vmro3"
# with VariableNameChangingReader(
# engine.open(vars_to_read=self.vars_to_read, filters=self.station_filter),
# {self.vars_to_read[0]: new_var_name}
# ) as ts:
# self.assertEqual(ts.data(new_var_name).variable, new_var_name)
# pass
# #
def test_wrappers(self):
engine = pyaro.list_timeseries_engines()[self.engine]
new_var_name = "vmro3"
ebas_var_name = "ozone mass concentration"
# read_obj = engine.open(filters=self.station_filter, vars_to_read=[ebas_var_name])
blubb = VariableNameChangingReader(engine.open(filters=self.station_filter, vars_to_read=[ebas_var_name]), reader_to_new={ebas_var_name: new_var_name})
# with VariableNameChangingReader.
# with blubb.reader.read() as ts:
with blubb.read() as ts:
read_obj = VariableNameChangingReader(engine.open(filters=self.station_filter, vars_to_read=[ebas_var_name]),
reader_to_new={ebas_var_name: new_var_name})
with read_obj.read() as ts:
self.assertEqual(ts.data(new_var_name).variable, new_var_name)
self.assertGreaterEqual(len(ts.variables()), 1)
self.assertGreaterEqual(len(ts.stations()), 2)
self.assertGreaterEqual(len(ts.data(read_obj.variables()[0])), 1000)
self.assertIn("revision", ts.metadata())
pass

if __name__ == "__main__":
Expand Down

0 comments on commit 91f2502

Please sign in to comment.