-
Notifications
You must be signed in to change notification settings - Fork 1
/
test_parse_logs.py
37 lines (26 loc) · 1.29 KB
/
test_parse_logs.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# Some tests of the log parsing code.
import parse_logs as pl
import unittest
class TestParseLogs(unittest.TestCase):
def test_filename_to_list_of_strings(self):
self.assertEqual(pl.filename_to_list_of_strings('example_data_1.txt'), [['This', 'is', 'a'], ['test.']])
def test_filter_by_2nd_item(self):
logs = pl.filename_to_list_of_strings('example_short_log.txt')
filtered_logs = pl.filter_by_2nd_item(logs, 'TRACE_WAYPOINTS')
for log_entry in filtered_logs:
self.assertEqual(log_entry[1], 'TRACE_WAYPOINTS')
def test_make_list_of_waypoints(self):
logs = pl.filename_to_list_of_strings('example_short_log.txt')
waypoints_only = pl.filter_by_2nd_item(logs, 'TRACE_WAYPOINTS')
waypoints = pl.make_list_of_waypoints(waypoints_only)
for each_dict in waypoints:
keys_list = list(each_dict.keys())
keys_list.sort()
self.assertEqual(keys_list, ['waypoint', 'x', 'y'])
def test_make_list_of_statuses(self):
logs = pl.filename_to_list_of_strings('example_short_log.txt')
statuses_only = pl.filter_by_2nd_item(logs, 'TRACE_STATUS')
los = pl.make_list_of_statuses(statuses_only)
self.assertEqual(len(los), 4)
if __name__ == '__main__':
unittest.main()