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
|
2020-09-19 01:14:07 +02:00
|
|
|
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
|
2020-09-19 01:14:07 +02:00
|
|
|
with open(r'tests/settings/periodic/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
|
|
|
|
2020-09-19 01:14:07 +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
|
|
|
|
2020-09-19 01:14:07 +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)
|
2020-06-26 22:47:31 +02:00
|
|
|
if df_act.empty:
|
|
|
|
self.assertTrue(df_exp.empty)
|
|
|
|
else:
|
2020-07-16 19:14:28 +02:00
|
|
|
# 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)
|
2020-06-26 22:47:31 +02:00
|
|
|
pd.testing.assert_frame_equal(df_exp, df_act, obj=df_exp)
|
2020-04-29 17:44:31 +02:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
|
2020-09-19 01:14:07 +02:00
|
|
|
unittest.main()
|
|
|
|
|