Skip to content
Snippets Groups Projects

Write log file

Merged Kien Le requested to merge feature-write_log_file into master
All threads resolved!
1 file
+ 26
6
Compare changes
  • Side-by-side
  • Inline
from datetime import datetime
from unittest import TestCase
from pathlib import Path
from unittest.mock import patch
from sohstationviewer.conf.constants import SOFTWARE_VERSION
from sohstationviewer.model.reftek_data.reftek import RT130
from sohstationviewer.model.general_data.general_data import \
ProcessingDataError
@@ -12,6 +15,19 @@ reftek_data = TEST_DATA_DIR.joinpath("RT130-sample")
reftek_gap_data = TEST_DATA_DIR.joinpath("RT130-gap")
# noinspection PyMissingOrEmptyDocstring
class Mock_datetime(datetime): # noqa: N801
@classmethod
def now(cls, tz=None) -> datetime:
"""
Mock datetime.now to return a static datetime object.
:return: a static datetime object
"""
# The formatting method we used does not take millisecond into
# account, so we can omit it.
return datetime(2023, 10, 5, 15, 8, 5)
class TestReftek(TestCase):
def test_path_not_exist(self):
# raise exception when path not exist
@@ -28,6 +44,7 @@ class TestReftek(TestCase):
"Path '_' not exist"
)
@patch('datetime.datetime', Mock_datetime)
def test_read_soh(self):
args = {
'data_type': 'RT130',
@@ -50,11 +67,12 @@ class TestReftek(TestCase):
self.assertEqual(len(obj.log_data['TEXT']), 0)
self.assertEqual(list(obj.log_data[('92EB', '25')].keys()), ['SOH'])
self.assertEqual(len(obj.log_data[('92EB', '25')]['SOH']), 1)
formatted_time = 'Thu Oct 5 15:08:05 2023'
self.assertEqual(
obj.log_data[('92EB', '25')]['SOH'][0][:100],
'\nState of Health 17:150:00:00:00:000 ST: 92EB'
'\n150:00:00:00 REF TEK 130'
'\r\n150:00:00:00 CPU SOFTWARE')
f'SOHStationViewer: v{SOFTWARE_VERSION} '
f'Run time (UTC): {formatted_time}'
'\n\nState of Health 17:150:00:0')
self.assertEqual(list(obj.soh_data.keys()), [('92EB', '25')])
self.assertEqual(sorted(list(obj.soh_data[('92EB', '25')].keys())),
sorted(expected_soh))
@@ -149,6 +167,7 @@ class TestReftek(TestCase):
self.assertEqual(obj.gaps[('98AD', '0')],
[[1648493999.64, 1648508400.64]])
@patch('datetime.datetime', Mock_datetime)
def test_select_2_folders(self):
args = {
'data_type': 'RT130',
@@ -176,11 +195,12 @@ class TestReftek(TestCase):
self.assertEqual(len(obj.log_data['TEXT']), 0)
self.assertEqual(list(obj.log_data[('92EB', '25')].keys()), ['SOH'])
self.assertEqual(len(obj.log_data[('92EB', '25')]['SOH']), 1)
formatted_time = 'Thu Oct 5 15:08:05 2023'
self.assertEqual(
obj.log_data[('92EB', '25')]['SOH'][0][:100],
'\nState of Health 17:150:00:00:00:000 ST: 92EB'
'\n150:00:00:00 REF TEK 130'
'\r\n150:00:00:00 CPU SOFTWARE')
f'SOHStationViewer: v{SOFTWARE_VERSION} '
f'Run time (UTC): {formatted_time}'
'\n\nState of Health 17:150:00:0')
self.assertEqual(list(obj.soh_data.keys()),
[('92EB', '25'), ('98AD', '0')])
self.assertEqual(sorted(list(obj.soh_data[('92EB', '25')].keys())),
Loading