-
Notifications
You must be signed in to change notification settings - Fork 172
Expand file tree
/
Copy pathtest_scheme.py
More file actions
85 lines (61 loc) · 2.68 KB
/
Copy pathtest_scheme.py
File metadata and controls
85 lines (61 loc) · 2.68 KB
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import pytest
from frictionless import FrictionlessException, Resource
BASEURL = "https://raw.githubusercontent.com/frictionlessdata/frictionless-py/master/%s"
# General
def test_resource_scheme_file():
with Resource("data/table.csv") as resource:
assert resource.scheme == "file"
@pytest.mark.vcr
def test_resource_scheme_https():
with Resource(BASEURL % "data/table.csv") as resource:
assert resource.scheme == "https"
def test_resource_scheme_stream():
with open("data/table.csv", mode="rb") as file:
with Resource(file, format="csv") as resource:
assert resource.scheme == "stream"
def test_resource_scheme_buffer():
with Resource(b"a\nb", format="csv") as resource:
assert resource.scheme == "buffer"
def test_resource_scheme_error_bad_scheme():
resource = Resource("bad", scheme="bad")
with pytest.raises(FrictionlessException) as excinfo:
resource.open()
error = excinfo.value.error
assert error.type == "scheme-error"
assert error.note.count('scheme "bad" is not supported')
def test_resource_scheme_error_bad_scheme_and_format():
resource = Resource("bad://bad.bad")
with pytest.raises(FrictionlessException) as excinfo:
resource.open()
error = excinfo.value.error
assert error.type == "scheme-error"
assert error.note.count('scheme "bad" is not supported')
def test_resource_scheme_error_file_not_found():
resource = Resource("bad.csv")
with pytest.raises(FrictionlessException) as excinfo:
resource.open()
error = excinfo.value.error
assert error.type == "scheme-error"
assert error.note.count("[Errno 2]") and error.note.count("bad.csv")
@pytest.mark.vcr
def test_resource_scheme_error_file_not_found_remote():
resource = Resource("https://example.com/bad.csv")
with pytest.raises(FrictionlessException) as excinfo:
resource.open()
error = excinfo.value.error
assert error.type == "scheme-error"
assert error.note[18:] == "Not Found for url: https://example.com/bad.csv"
def test_resource_scheme_error_file_not_found_bad_format():
resource = Resource("bad.bad")
with pytest.raises(FrictionlessException) as excinfo:
resource.open()
error = excinfo.value.error
assert error.type == "scheme-error"
assert error.note.count("[Errno 2]") and error.note.count("bad.bad")
def test_resource_scheme_error_file_not_found_bad_compression():
resource = Resource("bad.csv", compression="bad")
with pytest.raises(FrictionlessException) as excinfo:
resource.open()
error = excinfo.value.error
assert error.type == "scheme-error"
assert error.note.count("[Errno 2]") and error.note.count("bad.csv")