Skip to content

Commit adfd3e9

Browse files
committed
tests: speed up the slowest tests (--durations=0)
1 parent 9ec618a commit adfd3e9

5 files changed

Lines changed: 34 additions & 38 deletions

File tree

schema_salad/tests/test_codegen_errors.py

Lines changed: 31 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
"""Tests of helpful error messages."""
22

33
import importlib
4+
import os
5+
import shutil
46
from collections.abc import MutableSequence
57
from pathlib import Path
68
from typing import Any, Optional, cast
@@ -16,7 +18,7 @@
1618
from .util import cwl_file_uri, get_path
1719

1820

19-
def test_error_message1(tmp_path: Path) -> None:
21+
def test_error_message1(cwl_v1_0: Any) -> None:
2022
t = "test_schema/test1.cwl"
2123
match = r"""^.*test1\.cwl:2:1:\s+Object\s+`.*test1\.cwl`\s+is\s+not\s+valid\s+because:
2224
\s+\*\s+missing\s+required\s+field\s+`inputs`
@@ -25,19 +27,19 @@ def test_error_message1(tmp_path: Path) -> None:
2527
path = get_path("tests/" + t)
2628
assert path.exists()
2729
with pytest.raises(ValidationException, match=match):
28-
load_document_by_uri(tmp_path, path)
30+
load_document_by_uri(cwl_v1_0, path)
2931

3032

31-
def test_error_message2(tmp_path: Path) -> None:
33+
def test_error_message2(cwl_v1_0: Any) -> None:
3234
t = "test_schema/test2.cwl"
3335
match = r"""^.*test2\.cwl:2:1:\s+Field\s+`class`\s+contains\s+undefined\s+reference\s+to\s+`file://.+/schema_salad/tests/test_schema/xWorkflow`$"""
3436
path = get_path("tests/" + t)
3537
assert path.exists()
3638
with pytest.raises(ValidationException, match=match):
37-
load_document_by_uri(tmp_path, path)
39+
load_document_by_uri(cwl_v1_0, path)
3840

3941

40-
def test_error_message4(tmp_path: Path) -> None:
42+
def test_error_message4(cwl_v1_0: Any) -> None:
4143
t = "test_schema/test4.cwl"
4244
match = r"""^.*test4.cwl:2:1:\s+Object\s+`.*test4.cwl`\s+is\s+not\s+valid\s+because:
4345
.*test4\.cwl:6:1:\s+the\s+`outputs`\s+field\s+is\s+not\s+valid\s+because:
@@ -48,10 +50,10 @@ def test_error_message4(tmp_path: Path) -> None:
4850
path = get_path("tests/" + t)
4951
assert path.exists()
5052
with pytest.raises(ValidationException, match=match):
51-
load_document_by_uri(tmp_path, path)
53+
load_document_by_uri(cwl_v1_0, path)
5254

5355

54-
def test_error_message5(tmp_path: Path) -> None:
56+
def test_error_message5(cwl_v1_0: Any) -> None:
5557
t = "test_schema/test5.cwl"
5658
match = r"""^.*test5\.cwl:2:1:\s+Object\s+`.*test5\.cwl`\s+is\s+not\s+valid\s+because:
5759
.+test5\.cwl:8:1:\s+the\s+`steps`\s+field\s+is\s+not\s+valid\s+because:
@@ -60,10 +62,10 @@ def test_error_message5(tmp_path: Path) -> None:
6062
path = get_path("tests/" + t)
6163
assert path.exists()
6264
with pytest.raises(ValidationException, match=match):
63-
load_document_by_uri(tmp_path, path)
65+
load_document_by_uri(cwl_v1_0, path)
6466

6567

66-
def test_error_message6(tmp_path: Path) -> None:
68+
def test_error_message6(cwl_v1_0: Any) -> None:
6769
t = "test_schema/test6.cwl"
6870
match = r"""\*\s+tried\s+`CommandLineTool`\s+but
6971
\s+missing\s+required\s+field\s+`class`
@@ -74,10 +76,10 @@ def test_error_message6(tmp_path: Path) -> None:
7476
path = get_path("tests/" + t)
7577
assert path.exists()
7678
with pytest.raises(ValidationException, match=match):
77-
load_document_by_uri(tmp_path, path)
79+
load_document_by_uri(cwl_v1_0, path)
7880

7981

80-
def test_error_message7(tmp_path: Path) -> None:
82+
def test_error_message7(cwl_v1_0: Any) -> None:
8183
t = "test_schema/test7.cwl"
8284
match = r"""^.*test7\.cwl:2:1:\s+Object\s+`.*test7\.cwl`\s+is\s+not\s+valid\s+because:
8385
.*test7\.cwl:8:1:\s+the\s+`steps`\s+field\s+is\s+not\s+valid\s+because:
@@ -88,10 +90,10 @@ def test_error_message7(tmp_path: Path) -> None:
8890
path = get_path("tests/" + t)
8991
assert path.exists()
9092
with pytest.raises(ValidationException, match=match):
91-
load_document_by_uri(tmp_path, path)
93+
load_document_by_uri(cwl_v1_0, path)
9294

9395

94-
def test_error_message8(tmp_path: Path) -> None:
96+
def test_error_message8(cwl_v1_0: Any) -> None:
9597
t = "test_schema/test8.cwl"
9698
match = r"""^.*test8.cwl:2:1:\s+Object\s+`.*test8.cwl`\s+is\s+not\s+valid\s+because:
9799
.*test8\.cwl:8:1:\s+the\s+`steps`\s+field\s+is\s+not\s+valid\s+because:
@@ -103,10 +105,10 @@ def test_error_message8(tmp_path: Path) -> None:
103105
path = get_path("tests/" + t)
104106
assert path.exists()
105107
with pytest.raises(ValidationException, match=match):
106-
load_document_by_uri(tmp_path, path)
108+
load_document_by_uri(cwl_v1_0, path)
107109

108110

109-
def test_error_message9(tmp_path: Path) -> None:
111+
def test_error_message9(cwl_v1_0: Any) -> None:
110112
t = "test_schema/test9.cwl"
111113
match = r"""^.*test9.cwl:2:1:\s+Object\s+`.*test9.cwl`\s+is\s+not\s+valid\s+because:
112114
.*test9\.cwl:8:1:\s+the\s+`steps`\s+field\s+is\s+not\s+valid\s+because:
@@ -118,10 +120,10 @@ def test_error_message9(tmp_path: Path) -> None:
118120
path = get_path("tests/" + t)
119121
assert path.exists()
120122
with pytest.raises(ValidationException, match=match):
121-
load_document_by_uri(tmp_path, path)
123+
load_document_by_uri(cwl_v1_0, path)
122124

123125

124-
def test_error_message10(tmp_path: Path) -> None:
126+
def test_error_message10(cwl_v1_0: Any) -> None:
125127
t = "test_schema/test10.cwl"
126128
match = r"""^.*test10\.cwl:2:1:\s+Object\s+`.*test10\.cwl`\s+is\s+not\s+valid\s+because:
127129
.*test10\.cwl:8:1:\s+the\s+`steps`\s+field\s+is\s+not\s+valid\s+because:
@@ -133,10 +135,10 @@ def test_error_message10(tmp_path: Path) -> None:
133135
path = get_path("tests/" + t)
134136
assert path.exists()
135137
with pytest.raises(ValidationException, match=match):
136-
load_document_by_uri(tmp_path, path)
138+
load_document_by_uri(cwl_v1_0, path)
137139

138140

139-
def test_error_message11(tmp_path: Path) -> None:
141+
def test_error_message11(cwl_v1_0: Any) -> None:
140142
t = "test_schema/test11.cwl"
141143
match = r"""^.*test11\.cwl:2:1:\s+Object\s+`.*test11.cwl`\s+is\s+not\s+valid\s+because:
142144
.*test11\.cwl:8:1:\s+the\s+`steps`\s+field\s+is\s+not\s+valid\s+because:
@@ -146,11 +148,10 @@ def test_error_message11(tmp_path: Path) -> None:
146148
path = get_path("tests/" + t)
147149
assert path.exists()
148150
with pytest.raises(ValidationException, match=match):
149-
load_document_by_uri(tmp_path, path)
151+
load_document_by_uri(cwl_v1_0, path)
150152

151153

152-
# `loadContents`,\s+`position`,\s+`prefix`,\s+`separate`,\s+`itemSeparator`,\s+`valueFrom`,\s+`shellQuote`
153-
def test_error_message15(tmp_path: Path) -> None:
154+
def test_error_message15(cwl_v1_0: Any) -> None:
154155
t = "test_schema/test15.cwl"
155156
match = r"""^.*test15\.cwl:3:1:\s+Object\s+`.*test15\.cwl`\s+is\s+not\s+valid\s+because:
156157
.*test15\.cwl:6:1:\s+the\s+`inputs`\s+field\s+is\s+not\s+valid\s+because:
@@ -163,10 +164,12 @@ def test_error_message15(tmp_path: Path) -> None:
163164
path = get_path("tests/" + t)
164165
assert path.exists()
165166
with pytest.raises(ValidationException, match=match):
166-
load_document_by_uri(tmp_path, path)
167+
load_document_by_uri(cwl_v1_0, path)
167168

168169

169-
def load_document_by_uri(tmp_path: Path, path: Path) -> Any:
170+
@pytest.fixture(scope="session")
171+
def cwl_v1_0(tmp_path_factory: pytest.TempPathFactory) -> Any:
172+
tmp_path = tmp_path_factory.mktemp("cwl_v1_0_pycode")
170173
src_target = tmp_path / "cwl_v1_0.py"
171174
python_codegen(cwl_file_uri, src_target)
172175
spec = importlib.util.spec_from_file_location("cwl_v1_0", src_target)
@@ -175,11 +178,13 @@ def load_document_by_uri(tmp_path: Path, path: Path) -> Any:
175178
temp_cwl_v1_0 = importlib.util.module_from_spec(spec)
176179
spec.loader.exec_module(temp_cwl_v1_0)
177180
cwl_v1_0: Any = temp_cwl_v1_0
181+
yield cwl_v1_0
182+
shutil.rmtree(os.path.join(tmp_path))
178183

179-
path_uri = path.resolve().as_uri()
180184

185+
def load_document_by_uri(cwl_v1_0: Any, path: Path) -> Any:
186+
path_uri = path.resolve().as_uri()
181187
baseuri = path_uri
182-
183188
loadingOptions = cwl_v1_0.LoadingOptions(fileuri=baseuri)
184189

185190
with open(path) as file:

schema_salad/tests/test_pickling.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from schema_salad import ref_resolver, schema
1111
from schema_salad.avro.schema import Names, RecordSchema
1212

13-
from .util import get_data_uri
13+
from .util import cwl_file_uri
1414

1515

1616
def test_recordschema_pickle() -> None:
@@ -30,7 +30,6 @@ def test_loader_pickle() -> None:
3030

3131

3232
def test_extend_and_specialize_enums(tmp_path: Path) -> None:
33-
cwl_file_uri = get_data_uri("tests/test_schema/CommonWorkflowLanguage.yml")
3433
_, avsc_names, _, _ = schema.load_schema(cwl_file_uri)
3534
print(avsc_names)
3635
print(pickle.loads(pickle.dumps(avsc_names)))

schema_salad/tests/test_real_cwl/bio-cwl-tools/picard_CreateSequenceDictionary.cwl

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ inputs:
3636
- doc: Input reference fasta or fasta.gz [synonymous with -R]
3737
id: REFERENCE
3838
type: File
39-
format: edam:format_1929 # FASTA
4039
inputBinding:
4140
valueFrom: REFERENCE=$(self.basename)
4241
- doc: Put into AS field of sequence dictionary entry if supplied [synonymous with
@@ -177,7 +176,6 @@ arguments:
177176
outputs:
178177
sequences_with_dictionary:
179178
type: File
180-
format: edam:format_2573 # SAM
181179
secondaryFiles:
182180
- ^.dict
183181
- .fai?
@@ -189,7 +187,3 @@ outputs:
189187
outputBinding:
190188
glob: $(inputs.REFERENCE.nameroot).dict
191189

192-
$namespaces:
193-
edam: http://edamontology.org/
194-
$schemas:
195-
- http://edamontology.org/EDAM_1.18.owl

schema_salad/tests/test_schema.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@
33

44
from schema_salad import schema
55

6-
from .util import get_data_uri
7-
8-
cwl_file_uri = get_data_uri("tests/test_schema/CommonWorkflowLanguage.yml")
6+
from .util import cwl_file_uri
97

108

119
def test_extend_and_specialize_enums(tmp_path: Path) -> None:

tox.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ envlist =
1010
skip_missing_interpreters = True
1111

1212
[pytest]
13-
addopts=-n auto
13+
addopts=-n auto --dist=loadscope
1414
testpaths=schema_salad/tests
1515

1616
[gh-actions]

0 commit comments

Comments
 (0)