-
Notifications
You must be signed in to change notification settings - Fork 172
Expand file tree
/
Copy pathtest_dereference.py
More file actions
94 lines (80 loc) · 2.74 KB
/
Copy pathtest_dereference.py
File metadata and controls
94 lines (80 loc) · 2.74 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
86
87
88
89
90
91
92
93
94
import pytest
from frictionless import Resource, platform
BASEURL = "https://raw.githubusercontent.com/frictionlessdata/frictionless-py/master/%s"
# General
def test_resource_dereference():
resource = Resource(path="data/table.csv", schema="data/schema.json")
resource.infer(stats=True)
assert resource.to_descriptor() == {
"name": "table",
"type": "table",
"path": "data/table.csv",
"scheme": "file",
"format": "csv",
"mediatype": "text/csv",
"encoding": "utf-8",
"hash": "sha256:a1fd6c5ff3494f697874deeb07f69f8667e903dd94a7bc062dd57550cea26da8",
"bytes": 30,
"fields": 2,
"rows": 2,
"schema": "data/schema.json",
}
def test_resource_dereference_forced():
resource = Resource("data/resource-with-dereferencing.json")
resource.dereference()
descriptor = resource.to_descriptor()
assert isinstance(descriptor["dialect"], dict)
assert isinstance(descriptor["schema"], dict)
def test_resource_dialect_schema_from_path():
resource = Resource("data/resource-with-dereferencing.json")
assert resource.to_descriptor() == {
"name": "name",
"type": "table",
"path": "table.csv",
"scheme": "file",
"format": "csv",
"mediatype": "text/csv",
"dialect": "dialect.json",
"schema": "schema.json",
}
assert resource.dialect.to_descriptor() == {
"csv": {"delimiter": ";"},
}
assert resource.schema.to_descriptor() == {
"fields": [
{"name": "id", "type": "integer"},
{"name": "name", "type": "string"},
]
}
@pytest.mark.vcr
@pytest.mark.skipif(platform.type == "windows", reason="Fix on Windows")
def test_resource_dialect_schema_from_path_remote():
resource = Resource(BASEURL % "data/resource-with-dereferencing.json")
assert resource.to_descriptor() == {
"name": "name",
"type": "table",
"path": "table.csv",
"scheme": "file",
"format": "csv",
"mediatype": "text/csv",
"dialect": "dialect.json",
"schema": "schema.json",
}
assert resource.dialect.to_descriptor() == {
"csv": {"delimiter": ";"},
}
assert resource.schema.to_descriptor() == {
"fields": [
{"name": "id", "type": "integer"},
{"name": "name", "type": "string"},
]
}
def test_resource_schema_from_path_with_basepath():
descriptor = {"name": "name", "path": "table.csv", "schema": "schema.json"}
resource = Resource(descriptor, basepath="data")
assert resource.schema.to_descriptor() == {
"fields": [
{"name": "id", "type": "integer"},
{"name": "name", "type": "string"},
]
}