Skip to content

Commit 99aa7c4

Browse files
committed
add tests
1 parent 13308fe commit 99aa7c4

File tree

3 files changed

+67
-3
lines changed

3 files changed

+67
-3
lines changed

src/projspec/proj/datapackage.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,30 @@ def parse(self) -> None:
4545
for _ in conf["resources"]
4646
]
4747

48+
@staticmethod
49+
def _create(path: str) -> None:
50+
with open(path + "/datapackage.json", "wt") as f:
51+
# https://github.com/frictionlessdata/examples/tree/main/text-file
52+
f.write(
53+
"""
54+
{
55+
"name": "text-file",
56+
"title": "Text File Data Package",
57+
"description": "An example of a text file in a non-tabular data package",
58+
"licenses": [{
59+
"name": "CC0-1.0",
60+
"path": "https://creativecommons.org/publicdomain/zero/1.0/"
61+
}],
62+
"resources": [{
63+
"name": "text-file",
64+
"path": "text-file.txt",
65+
"title": "Text File Data Resource",
66+
"format": "txt"
67+
}]
68+
}
69+
"""
70+
)
71+
4872

4973
class DVCRepo(ProjectSpec):
5074
"""Git management of data assets within a repo"""
@@ -102,3 +126,32 @@ def parse(self) -> None:
102126
IntakeSource(proj=self.proj, name=_, artifacts=set())
103127
for _ in meta.get("sources", [])
104128
]
129+
130+
@staticmethod
131+
def _create(path: str) -> None:
132+
with open(f"{path}/catalog.yaml", "w") as f:
133+
# doesn't actually create data
134+
f.write(
135+
"""
136+
aliases: {}
137+
data:
138+
35b33d80d511b79c:
139+
datatype: intake.readers.datatypes:Text
140+
kwargs:
141+
storage_options: null
142+
url: text-file.txt
143+
metadata: {}
144+
user_parameters: {}
145+
entries:
146+
text:
147+
kwargs:
148+
data: '{data(35b33d80d511b79c)}'
149+
metadata: {}
150+
output_instance: builtins:str
151+
reader: intake.readers.readers:FileTextReader
152+
user_parameters: {}
153+
metadata: {}
154+
user_parameters: {}
155+
version: 2
156+
"""
157+
)

src/projspec/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ def get_get_cls(registry="proj"):
349349
return reg_map[registry]
350350

351351

352-
def get_cls(name, registry="proj"):
352+
def get_cls(name: str, registry: str = "proj") -> type:
353353
"""Find class by name and type
354354
355355
name: str

tests/test_roundtrips.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,24 @@
66

77
@pytest.mark.parametrize(
88
"cls_name",
9-
["django", "streamlit", "python_code", "python_library", "JLabExtension"],
9+
[
10+
"django",
11+
"streamlit",
12+
"python_code",
13+
"python_library",
14+
"JLabExtension",
15+
"IntakeCatalog",
16+
"DataPackage",
17+
],
1018
)
1119
def test_compliant(tmpdir, cls_name):
1220
path = str(tmpdir)
1321
cls = get_cls(cls_name)
1422
proj = cls.create(path)
15-
assert cls_name in proj
23+
if not issubclass(cls, projspec.proj.ProjectExtra):
24+
assert cls_name in proj
25+
else:
26+
cls(proj).parse()
1627

1728

1829
def test_cant_create(tmpdir):

0 commit comments

Comments
 (0)