Пример #1
0
 def list_as_json(self) -> str:
     """Return data from a directory of populated templates as json."""
     excel_files = get_xlsx_files(Path(self.directory_path))
     if not self.state:
         self.state = extract(excel_files)
         return json.dumps(self.state)
     else:
         return json.dumps(self.state)
Пример #2
0
def test_group_data_by_source_file(resources):
    test_file_name = "test_template.xlsx"
    excel_files = get_xlsx_files(resources)
    test_file = [x for x in excel_files if x.name == test_file_name][0]
    digest_of_test_file = hashlib.md5(open(test_file,
                                           "rb").read()).digest().hex()
    dataset = extract_from_multiple_xlsx_files(excel_files)
    assert dataset["test_template.xlsx"]["checksum"] == digest_of_test_file
def test_extract_data_from_multiple_files_into_correct_structure(resources):
    xlsx_files = get_xlsx_files(resources)
    dataset = extract_from_multiple_xlsx_files(xlsx_files)
    test_filename = "test_template2.xlsx"
    assert (Path(dataset[test_filename]["data"]["Summary"]["B3"]
                 ["file_name"]).name == "test_template2.xlsx")
    assert (dataset[test_filename]["data"]["Summary"]["B3"]["value"] ==
            "This is a string")
Пример #4
0
def test_hash_of_target_files(resources):
    test_file_name = "test_template.xlsx"
    excel_files = get_xlsx_files(resources)
    test_file = [x for x in excel_files if x.name == test_file_name][0]
    digest_of_test_file = hashlib.md5(open(test_file,
                                           "rb").read()).digest().hex()
    get_hashes = _hash_target_files(excel_files)
    computed_hash = get_hashes[test_file_name]
    assert digest_of_test_file == computed_hash
def test_raise_exception_when_none_abs_path_passed():
    with pytest.raises(RuntimeError):
        list_of_template_paths = get_xlsx_files("tests/resources/")  # noqa
def test_parse_multiple_templates(resources):
    list_of_template_paths = get_xlsx_files(resources)
    for template in list_of_template_paths:
        return bool(
            Path(os.path.join(resources, "test_template.xlsx")) == template)