def test_validation_arbin_bad_data(self): path = "2017-12-04_4_65C-69per_6C_CH29.csv" path = os.path.join(TEST_FILE_DIR, path) v = ValidatorBeep() v.allow_unknown = True df = pd.read_csv(path, index_col=0) self.assertTrue(v.validate_arbin_dataframe(df)) # Alter the schema on-the-fly to induce error v.schema['discharge_capacity']['schema']['max'] = 1.8 self.assertFalse(v.validate_arbin_dataframe(df, schema=v.schema)) self.assertEqual(v.errors['discharge_capacity'][0][11264][0], 'max value is 1.8') # Alter the schema on-the-fly to move on to the next errors v.schema['discharge_capacity']['schema']['max'] = 2.1 v.schema['step_time'] = { "schema": { "min": 0.0, "type": "float" }, "type": "list" } self.assertFalse(v.validate_arbin_dataframe(df, schema=None)) self.assertEqual(v.errors['step_time'][0][206][0], 'min value is 0.0') # Alter schema once more to recover validation del v.schema['step_time']['schema']['min'] self.assertTrue(v.validate_arbin_dataframe(df, schema=None))
def test_validation_maccor_cerberus(self): path = "xTESLADIAG_000019_CH70.070" path = os.path.join(TEST_FILE_DIR, path) v = ValidatorBeep() v.allow_unknown = True df = pd.read_csv(path, delimiter="\t", skiprows=1) self.assertTrue(v.validate_maccor_dataframe(df))
def test_validation_maccor(self): path = "maccor_test_file_4267-66-6519.EDA0001.041" path = os.path.join(TEST_FILE_DIR, path) v = ValidatorBeep() v.allow_unknown = True df = pd.read_csv(path, delimiter='\t', skip_blank_lines=True, skiprows=10) self.assertTrue(v.validate_eis_dataframe(df))
def test_validation_arbin_bad_index(self): path = "2017-05-09_test-TC-contact_CH33.csv" path = os.path.join(TEST_FILE_DIR, path) v = ValidatorBeep() v.allow_unknown = True df = pd.read_csv(path, index_col=0) self.assertFalse(v.validate_arbin_dataframe(df)) self.assertEqual(v.errors['cycle_index'][0][0][0], 'must be of number type') # Test bigger file path = "2017-08-14_8C-5per_3_47C_CH44.csv" path = os.path.join(TEST_FILE_DIR, path) v = ValidatorBeep() v.allow_unknown = True df = pd.read_csv(path, index_col=0) self.assertFalse(v.validate_arbin_dataframe(df)) self.assertEqual(v.errors['cycle_index'][0][0][0], 'must be of number type')
def test_validation_many_from_paths(self): paths = [ "2017-05-09_test-TC-contact_CH33.csv", "2017-12-04_4_65C-69per_6C_CH29.csv" ] paths = [os.path.join(TEST_FILE_DIR, path) for path in paths] v = ValidatorBeep() temp_records = os.path.join(TEST_FILE_DIR, 'temp_records.json') with open(temp_records, 'w') as f: f.write("{}") results = v.validate_from_paths(paths, record_results=False) self.assertFalse( results["2017-05-09_test-TC-contact_CH33.csv"]["validated"]) errmsg = results["2017-05-09_test-TC-contact_CH33.csv"]["errors"][ 'cycle_index'][0][0][0] self.assertEqual(errmsg, 'must be of number type') self.assertTrue( results["2017-12-04_4_65C-69per_6C_CH29.csv"]["validated"]) v.validate_from_paths(paths, record_results=True, record_path=temp_records) with open(temp_records, 'r') as f: results_form_rec = json.load(f) self.assertFalse( results_form_rec["2017-05-09_test-TC-contact_CH33.csv"] ["validated"]) results = v.validate_from_paths(paths, record_results=True, skip_existing=True, record_path=temp_records) self.assertEqual(results, {})
def test_bad_file(self): paths = ["2017-08-14_8C-5per_3_47C_CH44.csv"] paths = [os.path.join(TEST_FILE_DIR, path) for path in paths] v = ValidatorBeep() results = v.validate_from_paths(paths, record_results=False)