rapids/tests/scripts/test_sensor_features.py

48 lines
1.6 KiB
Python
Raw Normal View History

2020-04-29 17:44:31 +02:00
import unittest
import hashlib
import pandas as pd
import utils
import yaml
import os
class TestSensorFeatures(unittest.TestCase):
# Hack to run code in positional order (not 100% full proof)
unittest.TestLoader.sortTestMethodsUsing = lambda self, a, b: (a < b) - (a > b)
@classmethod
def setUpClass(cls):
# Runs once to Setup env
global configs
with open(r'tests/settings/testing_config.yaml') as file:
configs = yaml.full_load(file)
def test_sensors_files_exist(self):
# Loop through the file_list dictionary and check if the files exist.
file_lists = utils.generate_sensor_file_lists(configs)
for each in file_lists:
for out_file, _ in file_lists[each]:
self.assertEqual(os.path.exists(out_file), 1)
def test_sensors_features_calculations(self):
calc_files = utils.generate_sensor_file_lists(configs)
for each in calc_files:
for act_result, exp_result in calc_files[each]:
df_act = pd.read_csv(act_result)
df_exp = pd.read_csv(exp_result)
if df_act.empty:
self.assertTrue(df_exp.empty)
else:
# The order in which the columns varies from time to time so
# the columns are sorted before doing the comparision
df_exp = df_exp.reindex(sorted(df_exp.columns), axis=1)
df_act = df_act.reindex(sorted(df_act.columns), axis=1)
pd.testing.assert_frame_equal(df_exp, df_act, obj=df_exp)
2020-04-29 17:44:31 +02:00
if __name__ == '__main__':
unittest.main()