def _write_read_file_into_url(base_url, filename, compression=None, pkg=None): if not _is_installed(pkg, filename): return source_url = _build_source_url_from(base_url, filename, compression) if source_url is None: return actual = None if ".avro" in filename: toavro(_table, source_url) actual = fromavro(source_url) elif ".xlsx" in filename: toxlsx(_table, source_url, 'test1', mode='overwrite') toxlsx(_table2, source_url, 'test2', mode='add') actual = fromxlsx(source_url, 'test1') elif ".xls" in filename: toxls(_table, source_url, 'test') actual = fromxls(source_url, 'test') elif ".json" in filename: tojson(_table, source_url) actual = fromjson(source_url) elif ".csv" in filename: tocsv(_table, source_url, encoding="ascii", lineterminator="\n") actual = fromcsv(source_url, encoding="ascii") if actual is not None: _show__rows_from("Expected:", _table) _show__rows_from("Actual:", actual) ieq(_table, actual) ieq(_table, actual) # verify can iterate twice else: print("\n - %s SKIPPED " % filename, file=sys.stderr, end="")
def _write_read_file_into_url(base_url, filename, compression=None): if ".avro" in filename and not _has_avro: return is_local = base_url.startswith("./") if compression is not None: if is_local: return filename = filename + "." + compression codec = fsspec.utils.infer_compression(filename) if codec is None: print("\n - %s SKIPPED " % filename, file=sys.stderr, end="") return print("\n - %s " % filename, file=sys.stderr, end="") if is_local: source_url = base_url + filename else: source_url = os.path.join(base_url, filename) _show__rows_from("Expected:", _table) if ".avro" in filename: toavro(_table, source_url) actual = fromavro(source_url) else: tocsv(_table, source_url, encoding="ascii", lineterminator="\n") actual = fromcsv(source_url, encoding="ascii") _show__rows_from("Actual:", actual) ieq(_table, actual) ieq(_table, actual) # verify can iterate twice
def _write_to_avro_file(test_rows, test_schema, test_expect=None, print_tables=True): _show__expect_rows(test_rows, print_tables) test_filename = _write_temp_avro_file(test_rows, test_schema) test_actual = fromavro(test_filename) test_expect2 = test_rows if test_expect is None else test_expect _assert_rows_are_equals(test_expect2, test_actual, print_tables)
def _read_from_mavro_file(test_rows, test_schema, test_expect=None, print_tables=True): _show__expect_rows(test_rows, print_tables) test_filename = _create_avro_example(test_schema, test_rows) test_actual = fromavro(test_filename) test_expect2 = test_rows if test_expect is None else test_expect _assert_rows_are_equals(test_expect2, test_actual, print_tables) return test_filename
def _append_to_avro_file(test_rows1, test_rows2, test_schema, test_expect=None, print_tables=True): _show__expect_rows(test_rows1, print_tables) _show__expect_rows(test_rows2, print_tables) test_filename = _get_tempfile_path() toavro(test_rows1, test_filename, schema=test_schema) appendavro(test_rows2, test_filename, schema=test_schema) test_actual = fromavro(test_filename) if test_expect is not None: test_expect2 = test_expect else: test_expect2 = cat(test_rows1, test_rows2) _assert_rows_are_equals(test_expect2, test_actual, print_tables)
def _write_read_file_into_url(base_url, filename, compression=None, pkg=None): if pkg is not None: if not _is_installed(pkg): print("\n - %s SKIPPED " % filename, file=sys.stderr, end="") return is_local = base_url.startswith("./") if compression is not None: if is_local: return filename = filename + "." + compression codec = fsspec.utils.infer_compression(filename) if codec is None: print("\n - %s SKIPPED " % filename, file=sys.stderr, end="") return print("\n - %s " % filename, file=sys.stderr, end="") if is_local: source_url = base_url + filename else: source_url = os.path.join(base_url, filename) actual = None if ".avro" in filename: toavro(_table, source_url) actual = fromavro(source_url) elif ".xlsx" in filename: toxlsx(_table, source_url, 'test1', mode='overwrite') toxlsx(_table2, source_url, 'test2', mode='add') actual = fromxlsx(source_url, 'test1') elif ".xls" in filename: toxls(_table, source_url, 'test') actual = fromxls(source_url, 'test') elif ".json" in filename: tojson(_table, source_url) actual = fromjson(source_url) elif ".csv" in filename: tocsv(_table, source_url, encoding="ascii", lineterminator="\n") actual = fromcsv(source_url, encoding="ascii") if actual is not None: _show__rows_from("Expected:", _table) _show__rows_from("Actual:", actual) ieq(_table, actual) ieq(_table, actual) # verify can iterate twice else: print("\n - %s SKIPPED " % filename, file=sys.stderr, end="")