rapids/tests/scripts/test_sensor_features.py

55 lines
1.8 KiB
Python
Raw Normal View History

2020-09-03 18:04:29 +02:00
from snakemake.io import expand
2020-04-29 17:44:31 +02:00
import unittest
import hashlib
import pandas as pd
import utils
import yaml
import sys
2020-04-29 17:44:31 +02:00
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/frequency/testing_config.yaml') as file:
2020-04-29 17:44:31 +02:00
configs = yaml.full_load(file)
def test_sensors_files_exist(self):
# Loop through the file_list dictionary and check if the files exist.
2020-09-03 18:04:29 +02:00
#print("Testing existance of files")
2020-04-29 17:44:31 +02:00
file_lists = utils.generate_sensor_file_lists(configs)
for each in file_lists:
2020-09-03 18:04:29 +02:00
#for out_file, _ in file_lists[each]:
self.assertEqual(os.path.exists( each[0]), 1)
2020-04-29 17:44:31 +02:00
def test_sensors_features_calculations(self):
2020-09-03 18:04:29 +02:00
# print("Testing calculations..")
2020-09-03 18:04:29 +02:00
sensor_file_list = utils.generate_sensor_file_lists(configs)
for each in sensor_file_list:
for act_result, exp_result in sensor_file_list:
2020-04-29 17:44:31 +02:00
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()