def test_batch_to_excel(tmpdir, sas_file_1, sas_file_2, sas_file_3):
    converted_file_1 = Path(tmpdir).joinpath('file1.xlsx')
    converted_file_2 = Path(tmpdir).joinpath('file2.xlsx')
    converted_file_3 = Path(tmpdir).joinpath('file3.xlsx')

    file_dict = [
        {
            'sas7bdat_file': sas_file_1,
            'export_file': converted_file_1
        },
        {
            'sas7bdat_file': sas_file_2,
            'export_file': converted_file_2
        },
        {
            'sas7bdat_file': sas_file_3,
            'export_file': converted_file_3
        },
    ]

    converter.batch_to_excel(file_dict)
    files_created = False

    if (converted_file_1.is_file() and converted_file_2.is_file()
            and converted_file_3.is_file()):
        files_created = True

    assert (files_created)
示例#2
0
def test_batch_to_excel_str(tmp_path, sas_file_1, sas_file_2, sas_file_3):
    converted_file_1 = tmp_path.joinpath("file1.xlsx")
    converted_file_2 = tmp_path.joinpath("file2.xlsx")
    converted_file_3 = tmp_path.joinpath("file3.xlsx")

    file_dict = [
        {
            "sas7bdat_file": str(sas_file_1),
            "export_file": str(converted_file_1)
        },
        {
            "sas7bdat_file": str(sas_file_2),
            "export_file": str(converted_file_2)
        },
        {
            "sas7bdat_file": str(sas_file_3),
            "export_file": str(converted_file_3)
        },
    ]

    converter.batch_to_excel(file_dict)
    files_created = False

    if converted_file_1.is_file() and converted_file_2.is_file(
    ) and converted_file_3.is_file():
        files_created = True

    assert files_created
示例#3
0
def test_batch_to_excel_no_continue(tmp_path, caplog, sas_file_1):
    bad_sas_file = tmp_path.joinpath("bad_file.sas7bdat")
    bad_converted_file = tmp_path.joinpath("bad_file.xlsx")
    converted_file = tmp_path.joinpath("file1.xlsx")

    file_dict = [
        {
            "sas7bdat_file": bad_sas_file,
            "export_file": bad_converted_file
        },
        {
            "sas7bdat_file": sas_file_1,
            "export_file": converted_file
        },
    ]

    with pytest.raises(FileNotFoundError) as execinfo:
        converter.batch_to_excel(file_dict, continue_on_error=False)

    assert execinfo.value
示例#4
0
def test_batch_to_excel_continue(tmp_path, caplog, sas_file_1):
    bad_sas_file = tmp_path.joinpath("bad_file.sas7bdat")
    bad_converted_file = tmp_path.joinpath("bad_file.xlsx")
    converted_file = tmp_path.joinpath("file1.xlsx")

    file_dict = [
        {
            "sas7bdat_file": bad_sas_file,
            "export_file": bad_converted_file
        },
        {
            "sas7bdat_file": sas_file_1,
            "export_file": converted_file
        },
    ]

    converter.batch_to_excel(file_dict, continue_on_error=True)

    assert converted_file.is_file()
    assert "Error converting" in caplog.text
def test_batch_to_excel_invalid_key(file_dict):
    with pytest.raises(KeyError) as execinfo:
        converter.batch_to_excel(file_dict)

    assert 'Invalid key provided' in str(execinfo.value)