Example #1
0
 def test_toxlsx_append():
     tbl = (('foo', 'bar'),
            ('A', 1),
            ('B', 2),
            ('C', 2),
            (u'é', datetime(2012, 1, 1)))
     f = NamedTemporaryFile(delete=False, suffix='.xlsx')
     f.close()
     toxlsx(tbl, f.name, 'Sheet1')
     toxlsx(tbl, f.name, 'Sheet2')
     actual1 = fromxlsx(f.name, 'Sheet1')
     actual2 = fromxlsx(f.name, 'Sheet1')
     ieq(tbl, actual1)
     ieq(tbl, actual2)
Example #2
0
 def test_fromxlsx_offset():
     filename = pkg_resources.resource_filename('petl',
                                                'test/resources/test.xlsx')
     tbl = fromxlsx(filename, 'Sheet1', min_row=2, min_col=2)
     expect = ((1, ), (2, ), (2, ), (datetime(2012, 1, 1, 0, 0), ))
     ieq(expect, tbl)
     ieq(expect, tbl)
Example #3
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="")
Example #4
0
 def test_fromxlsx_offset():
     filename = _get_test_xlsx()
     if filename is None:
         return
     tbl = fromxlsx(filename, 'Sheet1', min_row=2, min_col=2)
     expect = ((1, ), (2, ), (2, ), (datetime(2012, 1, 1, 0, 0), ))
     ieq(expect, tbl)
     ieq(expect, tbl)
Example #5
0
 def test_fromxlsx_nosheet():
     filename = pkg_resources.resource_filename('petl',
                                                'test/resources/test.xlsx')
     tbl = fromxlsx(filename)
     expect = (('foo', 'bar'), ('A', 1), ('B', 2), ('C', 2),
               (u'é', datetime(2012, 1, 1)))
     ieq(expect, tbl)
     ieq(expect, tbl)
Example #6
0
 def test_fromxlsx_range():
     filename = pkg_resources.resource_filename('petl',
                                                'test/resources/test.xlsx')
     tbl = fromxlsx(filename, 'Sheet2', range_string='B2:C6')
     expect = (('foo', 'bar'), ('A', 1), ('B', 2), ('C', 2),
               (u'é', datetime(2012, 1, 1)))
     ieq(expect, tbl)
     ieq(expect, tbl)
Example #7
0
 def test_toxlsx_nosheet():
     tbl = (('foo', 'bar'), ('A', 1), ('B', 2), ('C', 2),
            (u'é', datetime(2012, 1, 1)))
     f = NamedTemporaryFile(delete=True, suffix='.xlsx')
     f.close()
     toxlsx(tbl, f.name)
     actual = fromxlsx(f.name)
     ieq(tbl, actual)
Example #8
0
 def test_toxlsx():
     tbl = (('foo', 'bar'), ('A', 1), ('B', 2), ('C', 2),
            (u'é', datetime(2012, 1, 1)))
     f = NamedTemporaryFile(delete=False)
     f.close()
     toxlsx(tbl, f.name, 'Sheet1')
     actual = fromxlsx(f.name, 'Sheet1')
     ieq(tbl, actual)
Example #9
0
 def test_fromxlsx_nosheet():
     filename = _get_test_xlsx()
     if filename is None:
         return
     tbl = fromxlsx(filename)
     expect = (('foo', 'bar'), ('A', 1), ('B', 2), ('C', 2),
               (u'é', datetime(2012, 1, 1)))
     ieq(expect, tbl)
     ieq(expect, tbl)
Example #10
0
 def test_fromxlsx_range():
     filename = _get_test_xlsx()
     if filename is None:
         return
     tbl = fromxlsx(filename, 'Sheet2', range_string='B2:C6')
     expect = (('foo', 'bar'), ('A', 1), ('B', 2), ('C', 2),
               (u'é', datetime(2012, 1, 1)))
     ieq(expect, tbl)
     ieq(expect, tbl)
Example #11
0
 def test_fromxlsx_read_only():
     filename = _get_test_xlsx()
     if filename is None:
         return
     tbl = fromxlsx(filename, sheet='Sheet1', read_only=True)
     expect = (('foo', 'bar'), ('A', 1), ('B', 2), ('C', 2),
               (u'é', datetime(2012, 1, 1)))
     ieq(expect, tbl)
     ieq(expect, tbl)
Example #12
0
 def test_toxlsx_nosheet():
     tbl = (('foo', 'bar'),
            ('A', 1),
            ('B', 2),
            ('C', 2),
            (u'é', datetime(2012, 1, 1)))
     f = NamedTemporaryFile(delete=False)
     f.close()
     toxlsx(tbl, f.name)
     actual = fromxlsx(f.name)
     ieq(tbl, actual)
Example #13
0
 def test_fromxlsx_range():
     filename = pkg_resources.resource_filename(
         'petl', 'test/resources/test.xlsx'
     )
     tbl = fromxlsx(filename, 'Sheet2', range_string='B2:C6')
     expect = (('foo', 'bar'),
               ('A', 1),
               ('B', 2),
               ('C', 2),
               (u'é', datetime(2012, 1, 1)))
     ieq(expect, tbl)
     ieq(expect, tbl)
Example #14
0
 def test_fromxlsx_nosheet():
     filename = pkg_resources.resource_filename(
         'petl', 'test/resources/test.xlsx'
     )
     tbl = fromxlsx(filename)
     expect = (('foo', 'bar'),
               ('A', 1),
               ('B', 2),
               ('C', 2),
               (u'é', datetime(2012, 1, 1)))
     ieq(expect, tbl)
     ieq(expect, tbl)
Example #15
0
def test_appendxlsx_with_non_str_header(xlsx_table_with_non_str_header,
                                        xlsx_test_table):

    f = NamedTemporaryFile(delete=True, suffix='.xlsx')
    f.close()

    # write first table
    toxlsx(xlsx_test_table, f.name, 'Sheet1')
    actual = fromxlsx(f.name, 'Sheet1')
    ieq(xlsx_test_table, actual)

    # test appendxlsx
    appendxlsx(xlsx_table_with_non_str_header, f.name, 'Sheet1')
    expect = etl.cat(xlsx_test_table, xlsx_table_with_non_str_header)
    ieq(expect, actual)
Example #16
0
def test_toxlsx_appendxlsx(xlsx_test_table):

    # setup
    f = NamedTemporaryFile(delete=True, suffix='.xlsx')
    f.close()

    # test toxlsx
    toxlsx(xlsx_test_table, f.name, 'Sheet1')
    actual = fromxlsx(f.name, 'Sheet1')
    ieq(xlsx_test_table, actual)

    # test appendxlsx
    appendxlsx(xlsx_test_table, f.name, 'Sheet1')
    expect = etl.cat(xlsx_test_table, xlsx_test_table)
    ieq(expect, actual)
Example #17
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="")
Example #18
0
    def test_toxlsx_appendxlsx():

        # setup
        tbl = (('foo', 'bar'), ('A', 1), ('B', 2), ('C', 2),
               (u'é', datetime(2012, 1, 1)))
        f = NamedTemporaryFile(delete=True, suffix='.xlsx')
        f.close()

        # test toxlsx
        toxlsx(tbl, f.name, 'Sheet1')
        actual = fromxlsx(f.name, 'Sheet1')
        ieq(tbl, actual)

        # test appendxlsx
        appendxlsx(tbl, f.name, 'Sheet1')
        expect = etl.cat(tbl, tbl)
        ieq(expect, actual)
Example #19
0
def test_fromxlsx(xlsx_test_table, xlsx_test_filename):
    tbl = fromxlsx(xlsx_test_filename, 'Sheet1')
    expect = xlsx_test_table
    ieq(expect, tbl)
    ieq(expect, tbl)
Example #20
0
def test_fromxlsx_read_only(xlsx_test_filename):
    tbl = fromxlsx(xlsx_test_filename, sheet='Sheet1', read_only=True)
    expect = (('foo', 'bar'), ('A', 1), ('B', 2), ('C', 2),
              (u'é', datetime(2012, 1, 1)))
    ieq(expect, tbl)
    ieq(expect, tbl)
Example #21
0
def test_fromxlsx_nosheet(xlsx_test_filename):
    tbl = fromxlsx(xlsx_test_filename)
    expect = (('foo', 'bar'), ('A', 1), ('B', 2), ('C', 2),
              (u'é', datetime(2012, 1, 1)))
    ieq(expect, tbl)
    ieq(expect, tbl)
Example #22
0
def test_fromxlsx_range(xlsx_test_filename):
    tbl = fromxlsx(xlsx_test_filename, 'Sheet2', range_string='B2:C6')
    expect = (('foo', 'bar'), ('A', 1), ('B', 2), ('C', 2),
              (u'é', datetime(2012, 1, 1)))
    ieq(expect, tbl)
    ieq(expect, tbl)
Example #23
0
def test_fromxlsx_offset(xlsx_test_filename):
    tbl = fromxlsx(xlsx_test_filename, 'Sheet1', min_row=2, min_col=2)
    expect = ((1, ), (2, ), (2, ), (datetime(2012, 1, 1, 0, 0), ))
    ieq(expect, tbl)
    ieq(expect, tbl)
Example #24
0
def test_toxlsx_nosheet(xlsx_test_table):
    f = NamedTemporaryFile(delete=True, suffix='.xlsx')
    f.close()
    toxlsx(xlsx_test_table, f.name)
    actual = fromxlsx(f.name)
    ieq(xlsx_test_table, actual)