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

Add tests for findTPSTm

parent 73bbdf5b
No related branches found
No related tags found
1 merge request!27Draft: Add tests for functions in handling_data.py
Pipeline #1869 failed with stage
in 4 minutes and 22 seconds
...@@ -38,6 +38,7 @@ from sohstationviewer.model.handling_data import ( ...@@ -38,6 +38,7 @@ from sohstationviewer.model.handling_data import (
chunk_minmax, chunk_minmax,
trim_downsample_SOHChan, trim_downsample_SOHChan,
get_eachDay5MinList, get_eachDay5MinList,
findTPSTm
) )
from sohstationviewer.model.reftek.from_rt2ms.core import Reftek130 from sohstationviewer.model.reftek.from_rt2ms.core import Reftek130
from sohstationviewer.conf.constants import SEC_5M, SEC_DAY, NO_5M_DAY from sohstationviewer.conf.constants import SEC_5M, SEC_DAY, NO_5M_DAY
...@@ -1234,3 +1235,77 @@ class TestGetTrimTpsData(TestCase): ...@@ -1234,3 +1235,77 @@ class TestGetTrimTpsData(TestCase):
@expectedFailure @expectedFailure
def test(self): def test(self):
raise NotImplementedError(type(self)) raise NotImplementedError(type(self))
class TestFindTpsTime(TestCase):
def test_given_time_not_in_list(self):
each_day_5_min_list = get_eachDay5MinList(
ZERO_EPOCH_TIME,
UTCDateTime(1970, 1, 2, 0, 0, 1).timestamp
)
given_time = UTCDateTime(1990, 1, 1, 0, 0, 0).timestamp
time_idx, day_idx = findTPSTm(given_time, each_day_5_min_list)
self.assertIsNone(time_idx)
self.assertIsNone(day_idx)
def test_given_time_is_the_start_of_a_five_minute_interval(self):
with self.subTest('test_list_contains_one_day'):
each_day_5_min_list = get_eachDay5MinList(
ZERO_EPOCH_TIME,
UTCDateTime(1970, 1, 1, 0, 0, 1).timestamp
)
given_time = UTCDateTime(1970, 1, 1, 11, 0, 0).timestamp
time_idx, day_idx = findTPSTm(given_time, each_day_5_min_list)
self.assertEqual(time_idx, 132)
self.assertEqual(day_idx, 0)
with self.subTest('test_list_contains_multiple_days'):
each_day_5_min_list = get_eachDay5MinList(
ZERO_EPOCH_TIME,
UTCDateTime(1970, 1, 5, 0, 0, 1).timestamp
)
given_time = UTCDateTime(1970, 1, 3, 12, 15, 0).timestamp
time_idx, day_idx = findTPSTm(given_time, each_day_5_min_list)
self.assertEqual(time_idx, 147)
self.assertEqual(day_idx, -2)
def test_given_time_is_not_the_start_of_a_five_minute_interval(self):
with self.subTest('test_list_contains_one_day'):
each_day_5_min_list = get_eachDay5MinList(
ZERO_EPOCH_TIME,
UTCDateTime(1970, 1, 1, 0, 0, 1).timestamp
)
given_time = UTCDateTime(1970, 1, 1, 0, 1, 0).timestamp
time_idx, day_idx = findTPSTm(given_time, each_day_5_min_list)
self.assertEqual(time_idx, 0)
self.assertEqual(day_idx, 0)
with self.subTest('test_list_contains_multiple_days'):
each_day_5_min_list = get_eachDay5MinList(
ZERO_EPOCH_TIME,
UTCDateTime(1970, 1, 5, 0, 0, 1).timestamp
)
given_time = UTCDateTime(1970, 1, 3, 6, 13, 0).timestamp
time_idx, day_idx = findTPSTm(given_time, each_day_5_min_list)
self.assertEqual(time_idx, 74)
self.assertEqual(day_idx, -2)
def test_given_time_is_start_of_day(self):
each_day_5_min_list = get_eachDay5MinList(
ZERO_EPOCH_TIME,
UTCDateTime(1970, 1, 5, 0, 0, 1).timestamp
)
given_time = UTCDateTime(1970, 1, 3, 0, 0, 0).timestamp
time_idx, day_idx = findTPSTm(given_time, each_day_5_min_list)
self.assertEqual(time_idx, 0)
self.assertEqual(day_idx, -2)
def test_given_time_is_in_last_five_minutes_of_day(self):
each_day_5_min_list = get_eachDay5MinList(
ZERO_EPOCH_TIME,
UTCDateTime(1970, 1, 5, 0, 0, 1).timestamp
)
given_time = UTCDateTime(1970, 1, 3, 23, 57, 0).timestamp
time_idx, day_idx = findTPSTm(given_time, each_day_5_min_list)
self.assertEqual(time_idx, 287)
self.assertEqual(day_idx, -2)
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