def test_parse_json(self):
     for json_file, str_num in self.get_test_files('dic'):
         parsed = globals()[f'parsed{str_num}']
         to_excel = ToExcel(json_file)
         to_excel.set_sheet_format()
         with self.subTest(to_excel.sheet_format):
             self.assertEqual(parsed, to_excel.sheet_format)
 def test_serialize(self):
     for json_file, str_num in self.get_test_files('dic'):
         serialized = globals()[f'serialized{str_num}']
         to_excel = ToExcel(json_file)
         for record in to_excel.get_records():
             result = {(cell.key, cell.idx): cell.value for cell in record}
         with self.subTest(result):
             self.assertEqual(serialized, result)
Beispiel #3
0
 def test_selected_serialize(self):
     for json_file, str_num in self.get_test_files('dic'):
         if item := selected_test.get(int(str_num)):
             keys, expect = item
             to_excel = ToExcel(json_file)
             for record in to_excel.get_selected_records(keys):
                 result = {(cell.key, cell.idx): cell.value for cell in record}
             with self.subTest(result):
                 self.assertEqual(expect, result)
Beispiel #4
0
def setUpModule():
    global TEST_DIR
    TEST_DIR = TemporaryDirectory()
    TEST_PATH = Path(TEST_DIR.name)
    for key, val in globals().items():
        if key.startswith('dic'):
            file_path = os.path.join(TEST_PATH, f'{key}.json')
            with open(file_path, 'w', encoding='utf-8') as f:
                json.dump([val], f, ensure_ascii=False)
                f.flush()
    for json_file in glob.glob(f'{TEST_PATH}/*.json'):
        to_excel = ToExcel(json_file)
        to_excel.convert()
    for excel_file in glob.glob(f'{TEST_PATH}/*.xlsx'):
        from_excel = FromExcel(excel_file)
        from_excel.convert()
def setUpModule():
    global TEST_DIR, TEST_PATH
    TEST_DIR = TemporaryDirectory()
    TEST_PATH = Path(TEST_DIR.name)
    for key, val in globals().items():
        if key.startswith('dic'):
            file_path = os.path.join(TEST_PATH, f'{key}.json')
            with open(file_path, 'w', encoding='utf-8') as f:
                json.dump([val], f, ensure_ascii=False)
                f.flush()
    for json_file in glob.glob(f'{TEST_PATH}/*.json'):
        to_excel = ToExcel(json_file)
        to_excel.convert()
    for excel_file in glob.glob(f'{TEST_PATH}/*.xlsx'):
        obj_name = os.path.basename(excel_file).split('_')[0]
        num = obj_name.replace('dic', '')
        replacement = globals()[f'replacement{num}']
        from_excel = FromExcel(excel_file)
        from_excel.convert(replacement=replacement)