Example #1
0
def test_stream_skip_blank_at_the_end_issue_bco_dmo_33():
    source = 'data/special/skip-blank-at-the-end.csv'
    with Stream(source, headers=1, skip_rows=['#']) as stream:
        assert stream.headers == ['test1', 'test2']
        assert stream.read() == [['1', '2'], []]
Example #2
0
def test_stream_format_error_html():
    stream = Stream('data/special/table.csv.html', format='csv')
    with pytest.raises(exceptions.FormatError) as excinfo:
        stream.open()
Example #3
0
def test_stream_remote_csv_gz():
    source = 'https://raw.githubusercontent.com/frictionlessdata/tabulator-py/master/data/table.csv.gz'
    with Stream(source) as stream:
        assert stream.headers is None
        assert stream.read() == [['id', 'name'], ['1', 'english'],
                                 ['2', '中国人']]
Example #4
0
def test_stream_local_xls():
    with Stream('data/table.xls') as stream:
        assert stream.headers is None
        assert stream.read() == [['id', 'name'], [1, 'english'], [2, '中国人']]
Example #5
0
def test_stream_xls_sheet_by_name():
    source = 'data/special/sheet2.xls'
    with Stream(source, sheet='Sheet2') as stream:
        assert stream.fragment == 'Sheet2'
        assert stream.read() == [['id', 'name'], [1, 'english'], [2, '中国人']]
Example #6
0
def test_stream_inline_keyed():
    source = [{'id': '1', 'name': 'english'}, {'id': '2', 'name': '中国人'}]
    with Stream(source, format='inline') as stream:
        assert stream.headers is None
        assert stream.read() == [['1', 'english'], ['2', '中国人']]
Example #7
0
def test_stream_xlsx_merged_cells_fill_boolean():
    source = 'data/special/merged-cells-boolean.xls'
    with Stream(source, fill_merged_cells=True) as stream:
        assert stream.read() == [[True, True], [True, True], [True, True]]
Example #8
0
def test_stream_size_compressed():
    with Stream('data/special/doublequote.csv.zip') as stream:
        rows = stream.read()
        assert stream.size == 7346
Example #9
0
def test_stream_size_remote():
    with Stream(BASE_URL % 'data/special/doublequote.csv') as stream:
        rows = stream.read()
        assert stream.size == 7346
Example #10
0
def test_stream_io_error():
    stream = Stream('bad_path.csv')
    with pytest.raises(exceptions.IOError) as excinfo:
        stream.open()
    assert 'bad_path.csv' in str(excinfo.value)
Example #11
0
def test_stream_http_error():
    stream = Stream('http://github.com/bad_path.csv')
    with pytest.raises(exceptions.HTTPError) as excinfo:
        stream.open()
Example #12
0
def test_stream_bad_options_warning():
    Stream('', scheme='text', format='csv', bad_option=True).open()
    with pytest.warns(UserWarning) as record:
        Stream('', scheme='text', format='csv', bad_option=True).open()
    assert 'bad_option' in str(record[0].message.args[0])
Example #13
0
def test_stream_format_error():
    stream = Stream('', format='bad_format')
    with pytest.raises(exceptions.FormatError) as excinfo:
        stream.open()
    assert 'bad_format' in str(excinfo.value)
Example #14
0
def test_stream_scheme_error():
    stream = Stream('', scheme='bad_scheme')
    with pytest.raises(exceptions.SchemeError) as excinfo:
        stream.open()
    assert 'bad_scheme' in str(excinfo.value)
Example #15
0
def test_stream_ods_remote():
    source = BASE_URL % 'data/table.ods'
    with Stream(source) as stream:
        assert stream.read() == [['id', 'name'], [1.0, 'english'],
                                 [2.0, '中国人']]
Example #16
0
def test_stream_hash_compressed():
    with Stream('data/special/doublequote.csv.zip') as stream:
        rows = stream.read()
        assert stream.hash == '41fdde1d8dbcb3b2d4a1410acd7ad842781f076076a73b049863d6c1c73868db'
Example #17
0
def test_stream_inline_iterator():
    source = iter([['id', 'name'], ['1', 'english'], ['2', '中国人']])
    with Stream(source) as stream:
        assert stream.headers is None
        assert stream.read() == [['id', 'name'], ['1', 'english'],
                                 ['2', '中国人']]
Example #18
0
def test_stream_hash_remote():
    with Stream(BASE_URL % 'data/special/doublequote.csv') as stream:
        rows = stream.read()
        assert stream.hash == '41fdde1d8dbcb3b2d4a1410acd7ad842781f076076a73b049863d6c1c73868db'
def test_stream_stream():
    source = io.open('data/table.csv', mode='rb')
    with Stream(source, format='csv') as stream:
        assert stream.read() == [['id', 'name'], ['1', 'english'],
                                 ['2', '中国人']]
Example #20
0
def test_stream_read_closed():
    stream = Stream('data/table.csv')
    with pytest.raises(exceptions.TabulatorException) as excinfo:
        stream.read()
    assert 'stream.open()' in str(excinfo.value)
Example #21
0
def test_fix_for_2007_xls():
    source = 'https://ams3.digitaloceanspaces.com/budgetkey-files/spending-reports/2018-3-משרד התרבות והספורט-לשכת הפרסום הממשלתית-2018-10-22-c457.xls'
    with Stream(source) as stream:
        assert len(stream.read()) > 10
Example #22
0
def test_stream_local_csv_gz():
    with Stream('data/table.csv.gz') as stream:
        assert stream.headers is None
        assert stream.read() == [['id', 'name'], ['1', 'english'],
                                 ['2', '中国人']]
Example #23
0
def test_stream_remote_xls():
    with Stream(BASE_URL % 'data/table.xls') as stream:
        assert stream.headers is None
        assert stream.read() == [['id', 'name'], [1, 'english'], [2, '中国人']]
Example #24
0
def test_stream_filelike_csv_gz():
    with open('data/table.csv.gz', 'rb') as file:
        with Stream(file, format='csv', compression='gz') as stream:
            assert stream.headers is None
            assert stream.read() == [['id', 'name'], ['1', 'english'],
                                     ['2', '中国人']]
Example #25
0
def test_stream_xls_sheet_by_name_not_existent():
    source = 'data/special/sheet2.xls'
    with pytest.raises(exceptions.SourceError) as excinfo:
        Stream(source, sheet='not-existent').open()
    assert 'sheet "not-existent"' in str(excinfo.value)
Example #26
0
def test_stream_source_error_data():
    stream = Stream('[1,2]', scheme='text', format='json')
    with pytest.raises(exceptions.SourceError) as excinfo:
        stream.open()
        stream.read()