def test_io(self): test_file = os.path.join(TEST_FILE_DIR, 'xTESLADIAG_000003_CH68.000') json_file = os.path.join(TEST_FILE_DIR, 'xTESLADIAG_000003_CH68.json') test_out = 'test1.000' procedure = Procedure.from_file(os.path.join(TEST_FILE_DIR, test_file)) with ScratchDir('.'): dumpfn(procedure, json_file) procedure.to_file(test_out) hash1 = hash_file(test_file) hash2 = hash_file(test_out) if hash1 != hash2: original = open(test_file).readlines() parsed = open(test_out).readlines() self.assertFalse(list(difflib.unified_diff(original, parsed))) for line in difflib.unified_diff(original, parsed): self.assertIsNotNone(line) test_file = os.path.join(TEST_FILE_DIR, 'xTESLADIAG_000004_CH69.000') json_file = os.path.join(TEST_FILE_DIR, 'xTESLADIAG_000004_CH69.json') test_out = 'test2.000' procedure = Procedure.from_file(os.path.join(TEST_FILE_DIR, test_file)) with ScratchDir('.'): dumpfn(procedure, json_file) procedure.to_file(test_out) hash1 = hash_file(test_file) hash2 = hash_file(test_out) if hash1 != hash2: original = open(test_file).readlines() parsed = open(test_out).readlines() self.assertFalse(list(difflib.unified_diff(original, parsed))) for line in difflib.unified_diff(original, parsed): self.assertIsNotNone(line)
def test_dict_to_file(self): filename = '20170630-3_6C_9per_5C.sdu' schedule = Schedule.from_file( os.path.join(SCHEDULE_TEMPLATE_DIR, filename)) testname = 'test1.sdu' with ScratchDir('.'): dumpfn(schedule, "schedule_test.json") schedule.to_file(testname) hash1 = hash_file(os.path.join(SCHEDULE_TEMPLATE_DIR, filename)) hash2 = hash_file(testname) if hash1 != hash2: original = open(os.path.join(SCHEDULE_TEMPLATE_DIR, filename), encoding='latin-1').read() parsed = open(testname, encoding='latin-1').read() self.assertFalse(list(difflib.unified_diff(original, parsed))) for line in difflib.unified_diff(original, parsed): print(line)
def test_generate_proc_exp(self): test_file = os.path.join(TEST_FILE_DIR, 'EXP.000') json_file = os.path.join(TEST_FILE_DIR, 'EXP.json') test_out = 'test_EXP.000' test_parameters = ["4.2", "2.0C", "2.0C"] procedure = Procedure.from_exp(*test_parameters) with ScratchDir('.'): dumpfn(procedure, json_file) procedure.to_file(test_out) hash1 = hash_file(test_file) hash2 = hash_file(test_out) if hash1 != hash2: original = open(test_file).readlines() parsed = open(test_out).readlines() self.assertFalse(list(difflib.unified_diff(original, parsed))) for line in difflib.unified_diff(original, parsed): self.assertIsNotNone(line)
def test_fastcharge(self): filename = '20170630-3_6C_9per_5C.sdu' test_file = 'test.sdu' sdu = Schedule.from_fast_charge( 1.1 * 3.6, 0.086, 1.1 * 5, os.path.join(SCHEDULE_TEMPLATE_DIR, filename)) with ScratchDir('.'): sdu.to_file(test_file) hash1 = hash_file(os.path.join(SCHEDULE_TEMPLATE_DIR, filename)) hash2 = hash_file(test_file) if hash1 != hash2: original = open(os.path.join(SCHEDULE_TEMPLATE_DIR, filename), encoding='latin-1').readlines() parsed = open(test_file, encoding='latin-1').readlines() udiff = list(difflib.unified_diff(original, parsed)) for line in udiff: print(line) self.assertFalse(udiff)