Skip to content

Commit ea983fd

Browse files
authored
Merge pull request #47 from common-workflow-language/install-tests
make tests installable and runnable after install
2 parents 66b5ac6 + 7bd46e1 commit ea983fd

File tree

9 files changed

+78
-51
lines changed

9 files changed

+78
-51
lines changed

MANIFEST.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
include gittaggers.py ez_setup.py
2+
include schema_salad/tests/*.py schema_salad/tests/*.yml schema_salad/tests/*.owl
3+
global-exclude *.pyc
File renamed without changes.

tests/Process.yml renamed to schema_salad/tests/Process.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ $namespaces:
66

77
$graph:
88

9-
- $import: "../schema_salad/metaschema/metaschema_base.yml"
9+
- $import: "../metaschema/metaschema_base.yml"
1010

1111
- name: InputBinding
1212
type: record
@@ -33,4 +33,4 @@ $graph:
3333

3434
- name: Blurb
3535
type: record
36-
extends: InputBinding
36+
extends: InputBinding
File renamed without changes.
File renamed without changes.

tests/test_examples.py renamed to schema_salad/tests/test_examples.py

Lines changed: 59 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import schema_salad.main
44
import schema_salad.schema
55
from schema_salad.jsonld_context import makerdf
6+
from pkg_resources import Requirement, resource_filename, ResolutionError # type: ignore
67
import rdflib
78
import ruamel.yaml as yaml
89
import json
@@ -11,21 +12,33 @@
1112
try:
1213
from ruamel.yaml import CSafeLoader as SafeLoader
1314
except ImportError:
14-
from ruamel.yaml import SafeLoader
15+
from ruamel.yaml import SafeLoader # type: ignore
16+
17+
18+
def get_data(filename):
19+
filepath = None
20+
try:
21+
filepath = resource_filename(
22+
Requirement.parse("schema-salad"), filename)
23+
except ResolutionError:
24+
pass
25+
if not filepath or not os.path.isfile(filepath):
26+
filepath = os.path.join(os.path.dirname(__file__), os.pardir, filename)
27+
return filepath
1528

1629

1730
class TestSchemas(unittest.TestCase):
1831
def test_schemas(self):
1932
l = schema_salad.ref_resolver.Loader({})
2033

2134
ra, _ = l.resolve_all({
22-
u"$schemas": [u"tests/EDAM.owl"],
35+
u"$schemas": [get_data("tests/EDAM.owl")],
2336
u"$namespaces": {u"edam": u"http://edamontology.org/"},
2437
u"edam:has_format": u"edam:format_1915"
2538
}, "")
2639

2740
self.assertEqual({
28-
u"$schemas": [u"tests/EDAM.owl"],
41+
u"$schemas": [get_data("tests/EDAM.owl")],
2942
u"$namespaces": {u"edam": u"http://edamontology.org/"},
3043
u'http://edamontology.org/has_format': u'http://edamontology.org/format_1915'
3144
}, ra)
@@ -50,12 +63,15 @@ def test_schemas(self):
5063
# })
5164

5265
def test_self_validate(self):
53-
self.assertEqual(0, schema_salad.main.main(argsl=["schema_salad/metaschema/metaschema.yml"]))
54-
self.assertEqual(0, schema_salad.main.main(argsl=["schema_salad/metaschema/metaschema.yml",
55-
"schema_salad/metaschema/metaschema.yml"]))
66+
self.assertEqual(0, schema_salad.main.main(
67+
argsl=[get_data("metaschema/metaschema.yml")]))
68+
self.assertEqual(0, schema_salad.main.main(
69+
argsl=[get_data("metaschema/metaschema.yml"),
70+
get_data("metaschema/metaschema.yml")]))
5671

5772
def test_avro_regression(self):
58-
self.assertEqual(0, schema_salad.main.main(argsl=["tests/Process.yml"]))
73+
self.assertEqual(0, schema_salad.main.main(
74+
argsl=[get_data("tests/Process.yml")]))
5975

6076
def test_jsonld_ctx(self):
6177
ldr, _, _, _ = schema_salad.schema.load_schema({
@@ -76,8 +92,6 @@ def test_jsonld_ctx(self):
7692
'http://example.com/foo#bar': 'asym'
7793
})
7894

79-
maxDiff = None
80-
8195
def test_idmap(self):
8296
ldr = schema_salad.ref_resolver.Loader({})
8397
ldr.add_context({
@@ -107,7 +121,8 @@ def test_idmap(self):
107121
self.assertEqual("http://example2.com/#stuff", ra["id"])
108122
for item in ra["inputs"]:
109123
if item["a"] == 2:
110-
self.assertEquals('http://example2.com/#stuff/zing', item["id"])
124+
self.assertEquals(
125+
'http://example2.com/#stuff/zing', item["id"])
111126
else:
112127
self.assertEquals('http://example2.com/#stuff/zip', item["id"])
113128
self.assertEquals(['http://example2.com/#stuff/out'], ra['outputs'])
@@ -183,46 +198,44 @@ def test_scoped_ref(self):
183198
'id': 'http://example2.com/#inp2',
184199
'type': 'string'
185200
}],
186-
'outputs': [{
187-
'id': 'http://example2.com/#out',
188-
'type': 'string',
189-
'source': 'http://example2.com/#step2/out'
190-
}],
191-
'steps': [{
201+
'outputs': [{
202+
'id': 'http://example2.com/#out',
203+
'type': 'string',
204+
'source': 'http://example2.com/#step2/out'
205+
}],
206+
'steps': [{
192207
'id': 'http://example2.com/#step1',
193208
'scatter': 'http://example2.com/#step1/inp',
194209
'in': [{
195-
'id': 'http://example2.com/#step1/inp',
196-
'source': 'http://example2.com/#inp'
210+
'id': 'http://example2.com/#step1/inp',
211+
'source': 'http://example2.com/#inp'
197212
}, {
198-
'id': 'http://example2.com/#step1/inp2',
199-
'source': 'http://example2.com/#inp2'
213+
'id': 'http://example2.com/#step1/inp2',
214+
'source': 'http://example2.com/#inp2'
200215
}, {
201-
'id': 'http://example2.com/#step1/inp3',
202-
'source': ['http://example2.com/#inp', 'http://example2.com/#inp2']
216+
'id': 'http://example2.com/#step1/inp3',
217+
'source': ['http://example2.com/#inp', 'http://example2.com/#inp2']
203218
}],
204219
"out": ["http://example2.com/#step1/out"],
205-
}, {
220+
}, {
206221
'id': 'http://example2.com/#step2',
207222
'scatter': 'http://example2.com/#step2/inp',
208223
'in': [{
209-
'id': 'http://example2.com/#step2/inp',
210-
'source': 'http://example2.com/#step1/out'
224+
'id': 'http://example2.com/#step2/inp',
225+
'source': 'http://example2.com/#step1/out'
211226
}],
212227
"out": ["http://example2.com/#step2/out"],
213228
}]
214-
}, ra)
215-
229+
}, ra)
216230

217231
def test_examples(self):
218-
self.maxDiff = None
219232
for a in ["field_name", "ident_res", "link_res", "vocab_res"]:
220233
ldr, _, _, _ = schema_salad.schema.load_schema(
221-
"schema_salad/metaschema/%s_schema.yml" % a)
222-
with open("schema_salad/metaschema/%s_src.yml" % a) as src_fp:
234+
get_data("metaschema/%s_schema.yml" % a))
235+
with open(get_data("metaschema/%s_src.yml" % a)) as src_fp:
223236
src = ldr.resolve_all(
224237
yaml.load(src_fp, Loader=SafeLoader), "", checklinks=False)[0]
225-
with open("schema_salad/metaschema/%s_proc.yml" % a) as src_proc:
238+
with open(get_data("metaschema/%s_proc.yml" % a)) as src_proc:
226239
proc = yaml.load(src_proc, Loader=SafeLoader)
227240
self.assertEqual(proc, src)
228241

@@ -251,7 +264,8 @@ def test_typedsl_ref(self):
251264
self.assertEqual({'type': {'items': 'File', 'type': 'array'}}, ra)
252265

253266
ra, _ = ldr.resolve_all({"type": "File[]?"}, "")
254-
self.assertEqual({'type': ['null', {'items': 'File', 'type': 'array'}]}, ra)
267+
self.assertEqual(
268+
{'type': ['null', {'items': 'File', 'type': 'array'}]}, ra)
255269

256270
def test_scoped_id(self):
257271
ldr = schema_salad.ref_resolver.Loader({})
@@ -275,7 +289,7 @@ def test_scoped_id(self):
275289
self.assertEqual({'id': 'http://example.com/#foo',
276290
'bar': {
277291
'id': 'http://example.com/#foo/baz'},
278-
}, ra)
292+
}, ra)
279293

280294
g = makerdf(None, ra, ctx)
281295
print(g.serialize(format="n3"))
@@ -289,7 +303,7 @@ def test_scoped_id(self):
289303
self.assertEqual({'location': 'http://example.com/foo',
290304
'bar': {
291305
'location': 'http://example.com/baz'},
292-
}, ra)
306+
}, ra)
293307

294308
g = makerdf(None, ra, ctx)
295309
print(g.serialize(format="n3"))
@@ -303,7 +317,7 @@ def test_scoped_id(self):
303317
self.assertEqual({'id': 'http://example.com/#foo',
304318
'bar': {
305319
'location': 'http://example.com/baz'},
306-
}, ra)
320+
}, ra)
307321

308322
g = makerdf(None, ra, ctx)
309323
print(g.serialize(format="n3"))
@@ -317,37 +331,36 @@ def test_scoped_id(self):
317331
self.assertEqual({'location': 'http://example.com/foo',
318332
'bar': {
319333
'id': 'http://example.com/#baz'},
320-
}, ra)
334+
}, ra)
321335

322336
g = makerdf(None, ra, ctx)
323337
print(g.serialize(format="n3"))
324338

325-
326339
def test_mixin(self):
327340
ldr = schema_salad.ref_resolver.Loader({})
328-
ra = ldr.resolve_ref({"$mixin": "mixin.yml", "one": "five"},
329-
base_url="file://"+os.getcwd()+"/tests/")
341+
ra = ldr.resolve_ref({"$mixin": get_data("tests/mixin.yml"), "one": "five"},
342+
base_url="file://" + os.getcwd() + "/tests/")
330343
self.assertEqual({'id': 'four', 'one': 'five'}, ra[0])
331344

332345
ldr = schema_salad.ref_resolver.Loader({"id": "@id"})
333-
base_url="file://"+os.getcwd()+"/tests/"
346+
base_url = "file://" + os.getcwd() + "/tests/"
334347
ra = ldr.resolve_all([{
335348
"id": "a",
336-
"m": {"$mixin": "mixin.yml"}
349+
"m": {"$mixin": get_data("tests/mixin.yml")}
337350
}, {
338351
"id": "b",
339-
"m": {"$mixin": "mixin.yml"}
352+
"m": {"$mixin": get_data("tests/mixin.yml")}
340353
}], base_url=base_url)
341354
self.assertEqual([{
342-
'id': base_url+'#a',
355+
'id': base_url + '#a',
343356
'm': {
344-
'id': base_url+u'#a/four',
357+
'id': base_url + u'#a/four',
345358
'one': 'two'
346359
},
347360
}, {
348-
'id': base_url+'#b',
361+
'id': base_url + '#b',
349362
'm': {
350-
'id': base_url+u'#b/four',
363+
'id': base_url + u'#b/four',
351364
'one': 'two'}
352365
}], ra[0])
353366

setup.cfg

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,9 @@ ignore=E124,E128,E129,E201,E202,E225,E226,E231,E265,E271,E302,E303,F401,E402,E50
33

44
[bdist_wheel]
55
universal = 1
6+
7+
[aliases]
8+
test=pytest
9+
10+
[pytest]
11+
addopts=--pyarg schema_salad

setup.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
except ImportError:
1818
tagger = egg_info_cmd.egg_info
1919

20+
needs_pytest = {'pytest', 'test', 'ptr'}.intersection(sys.argv)
21+
pytest_runner = ['pytest-runner'] if needs_pytest else []
22+
2023
if os.path.exists("requirements.txt"):
2124
requirements = [
2225
r for r in open("requirements.txt").read().split("\n") if ";" not in r]
@@ -49,12 +52,14 @@
4952
url="https://github.com/common-workflow-language/common-workflow-language",
5053
download_url="https://github.com/common-workflow-language/common-workflow-language",
5154
license='Apache 2.0',
52-
packages=["schema_salad"],
55+
setup_requires=[] + pytest_runner,
56+
packages=["schema_salad", "schema_salad.tests"],
5357
package_data={'schema_salad': ['metaschema/*']},
58+
include_package_data=True,
5459
install_requires=install_requires,
5560
extras_require=extras_require,
5661
test_suite='tests',
57-
tests_require=[],
62+
tests_require=['pytest'],
5863
entry_points={
5964
'console_scripts': ["schema-salad-tool=schema_salad.main:main"]
6065
},

typeshed/2.7/ruamel/yaml/main.pyi

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@
44

55
from typing import Any, AnyStr, BinaryIO, IO, List, Tuple, Union
66
from ruamel.yaml.loader import *
7+
import StringIO
78

89
VersionType = Union[List[int], str, Tuple[int, int]]
9-
StreamType = Union[BinaryIO, IO[str]]
10+
StreamType = Union[BinaryIO, IO[str], StringIO.StringIO]
1011

1112
def load(stream: StreamType,
1213
Loader: Any =...,

0 commit comments

Comments
 (0)