This repository has been archived by the owner on Jul 11, 2023. It is now read-only.
/
test_validate.py
55 lines (47 loc) · 1.69 KB
/
test_validate.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# -*- coding: utf-8 -*-
from __future__ import division
from __future__ import print_function
from __future__ import absolute_import
from __future__ import unicode_literals
import io
import pytest
from tabulator import validate, exceptions
# Tests
def test_validate_test_schemes():
# Supported
assert validate('path.csv')
assert validate('file://path.csv')
assert validate('http://example.com/path.csv')
assert validate('https://example.com/path.csv')
assert validate('ftp://example.com/path.csv')
assert validate('ftps://example.com/path.csv')
assert validate('path.csv', scheme='file')
# Not supported
with pytest.raises(exceptions.SchemeError) as excinfo:
validate('ssh://example.com/path.csv')
with pytest.raises(exceptions.SchemeError) as excinfo:
validate('bad://example.com/path.csv')
def test_validate_test_formats():
# Supported
assert validate('path.csv')
assert validate('path.json')
assert validate('path.jsonl')
assert validate('path.ndjson')
assert validate('path.tsv')
assert validate('path.xls')
assert validate('path.ods')
assert validate('path.no-format', format='csv')
# Not supported
with pytest.raises(exceptions.FormatError) as excinfo:
validate('path.txt')
with pytest.raises(exceptions.FormatError) as excinfo:
validate('path.bad')
def test_validate_test_special():
# Gsheet
assert validate('https://docs.google.com/spreadsheets/d/id', format='csv')
# File-like
assert validate(io.open('data/table.csv', encoding='utf-8'), format='csv')
# Text
assert validate('text://name,value\n1,2', format='csv')
# Inline
assert validate([{'name': 'value'}])