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

Fix tests

parent 928cc0f6
No related branches found
No related tags found
No related merge requests found
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())),
......
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