-
Notifications
You must be signed in to change notification settings - Fork 172
Expand file tree
/
Copy pathtest_profile.py
More file actions
168 lines (142 loc) · 5.02 KB
/
Copy pathtest_profile.py
File metadata and controls
168 lines (142 loc) · 5.02 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
import pytest
import yaml
from frictionless import FrictionlessException, Package, Resource, system
# General
@pytest.mark.vcr
def test_package_profiles_invalid_local():
profile = "data/profiles/camtrap.json"
resource = Resource(name="table", path="data/table.csv")
package = Package(resources=[resource], profile=profile)
with pytest.raises(FrictionlessException) as excinfo:
package.to_descriptor(validate=True)
reasons = excinfo.value.reasons
assert len(reasons) == 5
for error in reasons:
assert "required" in error.message
@pytest.mark.vcr
def test_package_profiles_invalid_local_from_descriptor():
profile = "data/profiles/camtrap.json"
resource = Resource(name="table", path="data/table.csv")
with pytest.raises(FrictionlessException) as excinfo:
Package({"resources": [resource.to_descriptor()], "profile": profile})
reasons = excinfo.value.reasons
assert len(reasons) == 5
for error in reasons:
assert "required" in error.message
# TODO: recover
@pytest.mark.skip
@pytest.mark.vcr
def test_package_external_profile_invalid_remote():
profile = (
"https://raw.githubusercontent.com/tdwg/camtrap-dp/main/camtrap-dp-profile.json"
)
resource = Resource(name="table", path="data/table.csv")
package = Package(resources=[resource], profile=profile)
with pytest.raises(FrictionlessException) as excinfo:
package.to_descriptor(validate=True)
reasons = excinfo.value.reasons
assert len(reasons) == 5
for error in reasons:
assert "required" in error.message
# TODO: recover
@pytest.mark.skip
@pytest.mark.vcr
def test_package_external_profile_invalid_remote_from_descriptor():
profile = (
"https://raw.githubusercontent.com/tdwg/camtrap-dp/main/camtrap-dp-profile.json"
)
resource = Resource(name="table", path="data/table.csv")
with pytest.raises(FrictionlessException) as excinfo:
Package({"resources": [resource.to_descriptor()], "profile": profile})
reasons = excinfo.value.reasons
assert len(reasons) == 5
for error in reasons:
assert "required" in error.message
@pytest.mark.skip
@pytest.mark.parametrize("profile", ["data-package", "tabular-data-package"])
def test_package_profile_type(profile):
descriptor = {
"resources": [{"name": "table", "path": "data/table.csv"}],
"profile": profile,
}
package = Package.from_descriptor(descriptor)
descriptor = package.to_descriptor()
assert descriptor.get("profile") is None
# Legacy
@pytest.mark.vcr
def test_package_profiles_from_descriptor_standards_v1():
profile = "data/profiles/camtrap.json"
resource = Resource(name="table", path="data/table.csv")
with pytest.raises(FrictionlessException) as excinfo:
Package({"resources": [resource.to_descriptor()], "profile": profile})
reasons = excinfo.value.reasons
assert len(reasons) == 5
for error in reasons:
assert "required" in error.message
@pytest.mark.skip
@pytest.mark.vcr
def test_package_profiles_to_descriptor_standards_v1():
profile = "data/profiles/empty.json"
descriptor = {
"resources": [{"name": "table", "path": "data/table.csv"}],
"profiles": [profile],
}
package = Package.from_descriptor(descriptor)
with system.use_context(standards="v1"):
descriptor = package.to_descriptor()
assert descriptor["profile"] == profile
# Bugs
def test_package_preserver_profile_issue_1480():
descriptor = yaml.safe_load("""
profile: tabular-data-package
resources:
-
name: some-table
profile: tabular-data-resource
path: some-file.csv
format: csv
mediatype: text/csv
encoding: utf-8
schema: schema.json
""")
package = Package(descriptor)
assert package.profile == "tabular-data-package"
assert package.get_resource("some-table").profile == "tabular-data-resource"
def test_package_profile_tabular_requirements_issue_1484():
descriptor = yaml.safe_load("""
profile: tabular-data-package
resources:
-
name: some-table
path: some-file.csv
format: csv
mediatype: text/csv
encoding: utf-8
schema: schema.json
""")
report = Package.validate_descriptor(descriptor)
assert report.flatten(["type", "note"]) == [
[
"package-error",
'profile "tabular-data-package" requires all the resources to be "tabular-data-resource"',
]
]
def test_package_profile_tabular_requirements_schema_issue_1484():
descriptor = yaml.safe_load("""
profile: tabular-data-package
resources:
-
name: some-table
profile: tabular-data-resource
path: some-file.csv
format: csv
mediatype: text/csv
encoding: utf-8
""")
report = Package.validate_descriptor(descriptor)
assert report.flatten(["type", "note"]) == [
[
"resource-error",
'profile "tabular-data-resource" requires "schema" to be present',
]
]