Skip to content
Snippets Groups Projects
Commit 2de3fcbf authored by Kien Le's avatar Kien Le
Browse files

Add tests for readText

parent 3f72f6aa
No related branches found
No related tags found
1 merge request!27Draft: Add tests for functions in handling_data.py
...@@ -17,6 +17,7 @@ from sohstationviewer.model.handling_data import ( ...@@ -17,6 +17,7 @@ from sohstationviewer.model.handling_data import (
readWaveformMSeed, readWaveformMSeed,
readWaveformReftek, readWaveformReftek,
readASCII, readASCII,
readText,
) )
from sohstationviewer.model.reftek.from_rt2ms.core import Reftek130 from sohstationviewer.model.reftek.from_rt2ms.core import Reftek130
...@@ -322,8 +323,7 @@ class TestReadWaveformReftek(TestCase): ...@@ -322,8 +323,7 @@ class TestReadWaveformReftek(TestCase):
def test_read_data_existing_channel_appended_to(self): def test_read_data_existing_channel_appended_to(self):
self.read_data = { self.read_data = {
'DS1-1': 'DS1-1':
{'tracesInfo': {'tracesInfo': [{'startTmEpoch': 0, 'endTmEpoch': 0}],
[{'startTmEpoch': 0, 'endTmEpoch': 0}],
'samplerate': 40.0} 'samplerate': 40.0}
} }
readWaveformReftek(self.rt130_waveform, self.key, self.read_data, readWaveformReftek(self.rt130_waveform, self.key, self.read_data,
...@@ -421,7 +421,8 @@ class TestReadASCII(TestCase): ...@@ -421,7 +421,8 @@ class TestReadASCII(TestCase):
) )
def test_trace_does_not_contain_log_data(self): def test_trace_does_not_contain_log_data(self):
raise NotImplementedError(self.test_trace_does_not_contain_log_data.__qualname__) # noqa raise NotImplementedError(
self.test_trace_does_not_contain_log_data.__qualname__)
# We are only reassigning the data reference of the trace and are not # We are only reassigning the data reference of the trace and are not
# modifying the stored data. As a result, we only need a shallow copy # modifying the stored data. As a result, we only need a shallow copy
# of the trace. # of the trace.
...@@ -441,3 +442,40 @@ class TestReadASCII(TestCase): ...@@ -441,3 +442,40 @@ class TestReadASCII(TestCase):
self.assertEqual(log_string, self.assertEqual(log_string,
self.log_data[self.station_id][self.channel_id][0]) self.log_data[self.station_id][self.channel_id][0])
class TestReadText(TestCase):
def setUp(self):
self.text_file = tempfile.NamedTemporaryFile(mode='w+t')
self.text_file.write('Test text')
self.text_file.flush()
self.text_file_name = Path(self.text_file.name).name
self.non_text_file = TEST_DATA_DIR.joinpath('Q330-sample/'
'day_vols_AX08/'
'AX08.XA..HHE.2021.186')
self.text_logs = []
def tearDown(self) -> None:
self.text_file.close()
def test_log_appended_to(self):
readText(self.text_file.name, self.text_file.name, self.text_logs)
self.assertGreater(len(self.text_logs), 0)
def test_text_file(self):
readText(self.text_file.name, Path(self.text_file.name).name,
self.text_logs)
self.assertEqual(
self.text_logs[0],
f'\n\n** STATE OF HEALTH: {Path(self.text_file.name).name}\nTest text') # noqa: E501
def test_non_text_file(self):
with self.assertRaises(Exception):
readText(self.non_text_file, self.non_text_file.name,
self.text_logs)
def test_non_existent_file(self):
non_existent_file = TEST_DATA_DIR.joinpath('non_existent_file')
with self.assertRaises(FileNotFoundError):
readText(str(non_existent_file),
non_existent_file.name,
self.text_logs)
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment