Exemple #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="")
Exemple #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)
Exemple #3
0
 def test_fromxls_nosheet():
     filename = pkg_resources.resource_filename('petl',
                                                'test/resources/test.xls')
     tbl = fromxls(filename)
     expect = (('foo', 'bar'), ('A', 1), ('B', 2), ('C', 2),
               (u'é', datetime(2012, 1, 1)))
     ieq(expect, tbl)
     ieq(expect, tbl)
Exemple #4
0
 def test_fromxls_use_view():
     filename = pkg_resources.resource_filename('petl',
                                                'test/resources/test.xls')
     tbl = fromxls(filename, 'Sheet1', use_view=False)
     expect = (('foo', 'bar'), ('A', 1), ('B', 2), ('C', 2), (u'é',
                                                              40909.0))
     ieq(expect, tbl)
     ieq(expect, tbl)
Exemple #5
0
 def test_fromxls_use_view():
     filename = _get_test_xls()
     if filename is None:
         return
     tbl = fromxls(filename, 'Sheet1', use_view=False)
     expect = (('foo', 'bar'), ('A', 1), ('B', 2), ('C', 2), (u'é',
                                                              40909.0))
     ieq(expect, tbl)
     ieq(expect, tbl)
Exemple #6
0
 def test_fromxls_nosheet():
     filename = _get_test_xls()
     if filename is None:
         return
     tbl = fromxls(filename)
     expect = (('foo', 'bar'), ('A', 1), ('B', 2), ('C', 2),
               (u'é', datetime(2012, 1, 1)))
     ieq(expect, tbl)
     ieq(expect, tbl)
Exemple #7
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)
Exemple #8
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)
Exemple #9
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)
Exemple #10
0
 def test_fromxls_use_view():
     filename = pkg_resources.resource_filename(
         'petl', 'test/resources/test.xls'
     )
     tbl = fromxls(filename, 'Sheet1', use_view=False)
     expect = (('foo', 'bar'),
               ('A', 1),
               ('B', 2),
               ('C', 2),
               (u'é', 40909.0))
     ieq(expect, tbl)
     ieq(expect, tbl)
Exemple #11
0
 def test_fromxls_nosheet():
     filename = pkg_resources.resource_filename(
         'petl', 'test/resources/test.xls'
     )
     tbl = fromxls(filename)
     expect = (('foo', 'bar'),
               ('A', 1),
               ('B', 2),
               ('C', 2),
               (u'é', datetime(2012, 1, 1)))
     ieq(expect, tbl)
     ieq(expect, tbl)
Exemple #12
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="")
Exemple #13
0
    def test_passing_kwargs_to_xlutils_view():
        filename = _get_test_xls()
        if filename is None:
            return

        from petl.io.xlutils_view import View
        org_init = View.__init__

        def wrapper(self, *args, **kwargs):
            assert "ignore_workbook_corruption" in kwargs
            return org_init(self, *args, **kwargs)

        with patch("petl.io.xlutils_view.View.__init__", wrapper):
            tbl = fromxls(filename,
                          'Sheet1',
                          use_view=True,
                          ignore_workbook_corruption=True)
            expect = (('foo', 'bar'), ('A', 1), ('B', 2), ('C', 2),
                      (u'é', datetime(2012, 1, 1)))
            ieq(expect, tbl)
            ieq(expect, tbl)