def test_read_data(): dict1 = pd.DataFrame({"A": [0, 0, 0], "B": [1, 1, 1], "C": [2, 2, 2]}) filly = Filly(remote='s3', bucket_name='tmp') filly.read_data(filename='test_csv_read.csv', filepath='tests/data', download=False) assert_frame_equal(filly.data, dict1)
def test_pickle_handler(filename, filepath, fullpath, mode): dict1 = pd.DataFrame({"A": [0, 0, 0], "B": [1, 1, 1], "C": [2, 2, 2]}) if mode == 'w': try: file_handler = Filly() file_handler.write_data(filename=filename, filepath=filepath, fullpath=fullpath, data=dict1) dict2 = pd.read_csv(open(os.path.join(filepath, filename), 'r')) assert_frame_equal(dict1, dict2) except Exception as err: print(err) finally: os.remove(file_handler.fullpath) elif mode == 'r': file_handler = Filly(remote=None) file_handler.read_data(filename=filename, filepath=filepath, fullpath=fullpath) assert_frame_equal(file_handler.data, dict1)
def test_write_output(filename, filepath, fullpath, data): file_handler = Filly() file_handler.write_output(data=data, filepath=filepath, filename=filename, fullpath=fullpath) output = '' with open(fullpath, 'r') as results_file: for line in results_file: output += line assert output == data
def test_json_handler(filename, filepath, mode): dict1 = {"A": 1, "B": 2, "C": 3} if mode == 'w': try: file_handler = Filly() file_handler.write_data(filename=filename, filepath=filepath, data=dict1) dict2 = json.loads( open(os.path.join(filepath, filename), 'r').read()) assert dict1 == dict2 except Exception as err: print(err) finally: os.remove(file_handler.fullpath) elif mode == 'r': file_handler = Filly(remote=None) file_handler.read_data(filename=filename, filepath=filepath) assert file_handler.data == dict1
def test_remote(remote, bucket_name): with pytest.raises(ValueError): Filly(remote=remote, bucket_name=bucket_name)
def test_read_input(): tmp = Filly().read_input(filepath='tests/data', filename='tmp') assert tmp == 'true'