Ejemplo n.º 1
0
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="")
Ejemplo n.º 2
0
 def test_toxls():
     expect = (('foo', 'bar'), ('A', 1), ('B', 2), ('C', 2))
     f = NamedTemporaryFile(delete=False)
     f.close()
     toxls(expect, f.name, 'Sheet1')
     actual = fromxls(f.name, 'Sheet1')
     ieq(expect, actual)
     ieq(expect, actual)
Ejemplo n.º 3
0
 def test_toxls_date():
     expect = (('foo', 'bar'),
               (u'é', datetime(2012, 1, 1)),
               (u'éé', datetime(2013, 2, 22)))
     f = NamedTemporaryFile(delete=False)
     f.close()
     toxls(expect, f.name, 'Sheet1',
           styles={'bar': xlwt.easyxf(num_format_str='DD/MM/YYYY')})
     actual = fromxls(f.name, 'Sheet1')
     ieq(expect, actual)
Ejemplo n.º 4
0
 def test_toxls_date():
     expect = (('foo', 'bar'),
               (u'é', datetime(2012, 1, 1)),
               (u'éé', datetime(2013, 2, 22)))
     f = NamedTemporaryFile(delete=False)
     f.close()
     toxls(expect, f.name, 'Sheet1',
           styles={'bar': xlwt.easyxf(num_format_str='DD/MM/YYYY')})
     actual = fromxls(f.name, 'Sheet1')
     ieq(expect, actual)
Ejemplo n.º 5
0
 def test_toxls():
     expect = (('foo', 'bar'),
               ('A', 1),
               ('B', 2),
               ('C', 2))
     f = NamedTemporaryFile(delete=False)
     f.close()
     toxls(expect, f.name, 'Sheet1')
     actual = fromxls(f.name, 'Sheet1')
     ieq(expect, actual)
     ieq(expect, actual)
Ejemplo n.º 6
0
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="")