def test_batch_to_csv(tmpdir, sas_file_1, sas_file_2, sas_file_3): converted_file_1 = Path(tmpdir).joinpath('file1.csv') converted_file_2 = Path(tmpdir).joinpath('file2.csv') converted_file_3 = Path(tmpdir).joinpath('file3.csv') 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_csv(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
def test_batch_to_csv_str(tmp_path, sas_file_1, sas_file_2, sas_file_3): converted_file_1 = tmp_path.joinpath("file1.csv") converted_file_2 = tmp_path.joinpath("file2.csv") converted_file_3 = tmp_path.joinpath("file3.csv") 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_csv(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
def test_batch_to_csv_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.csv") converted_file = tmp_path.joinpath("file1.csv") file_dict = [ { "sas7bdat_file": bad_sas_file, "export_file": bad_converted_file }, { "sas7bdat_file": sas_file_1, "export_file": converted_file }, ] with pytest.raises(Exception) as execinfo: converter.batch_to_csv(file_dict, continue_on_error=False) assert execinfo.value
def test_batch_to_csv_continue(tmp_path, caplog, sas_file_1): bad_sas_file = tmp_path.joinpath("bad_file.sas7bdat") bad_converted_file = tmp_path.joinpath("bad_file.csv") converted_file = tmp_path.joinpath("file1.csv") file_dict = [ { "sas7bdat_file": bad_sas_file, "export_file": bad_converted_file }, { "sas7bdat_file": sas_file_1, "export_file": converted_file }, ] converter.batch_to_csv(file_dict, continue_on_error=True) assert converted_file.is_file() assert "Error converting" in caplog.text
def test_batch_to_csv_invalid_key(file_dict): with pytest.raises(KeyError) as execinfo: converter.batch_to_csv(file_dict) assert 'Invalid key provided' in str(execinfo.value)