Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions tests/args.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import sys
import json
import os

args = [os.path.basename(a) for a in sys.argv[1:]]
with open("cwl.output.json", "w") as f:
json.dump({"args": args}, f)
59 changes: 35 additions & 24 deletions tests/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,44 @@

import sys
import os
from pathlib import Path

words = {}

mainfile = sys.argv[1]
indexfile = sys.argv[1] + ".idx1"

main = open(mainfile)
index = open(indexfile, "w")

linenum = 0
for l in main:
linenum += 1
l = l.rstrip().lower().replace(".", "").replace(",", "").replace(";", "").replace("-", " ")
for w in l.split(" "):
if w:
if w not in words:
words[w] = set()
words[w].add(linenum)

for w in sorted(words.keys()):
index.write("%s: %s" % (w, ", ".join((str(i) for i in sorted(words[w])))) + "\n")

open(os.path.splitext(sys.argv[1])[0] + ".idx2", "w")
open(sys.argv[1] + ".idx3", "w")
open(sys.argv[1] + ".idx4", "w")
open(sys.argv[1] + ".idx5", "w")
open(os.path.splitext(sys.argv[1])[0] + ".idx6" + os.path.splitext(sys.argv[1])[1], "w")
open(sys.argv[1] + ".idx7", "w")
os.mkdir(sys.argv[1] + "_idx8")
open(sys.argv[1] + "_idx8/index", "w")
with open(mainfile) as main:
for line in main:
linenum += 1
line = (
line.rstrip()
.lower()
.replace(".", "")
.replace(",", "")
.replace(";", "")
.replace("-", " ")
)
for word in line.split(" "):
if word:
if word not in words:
words[word] = set()
words[word].add(linenum)

with open(indexfile, "w") as index:
for w in sorted(words.keys()):
index.write(
"%s: %s" % (w, ", ".join((str(i) for i in sorted(words[w])))) + "\n"
)

Path(os.path.splitext(sys.argv[1])[0] + ".idx2").touch(exist_ok=False)
Path(sys.argv[1] + ".idx3").touch(exist_ok=False)
Path(sys.argv[1] + ".idx4").touch(exist_ok=False)
Path(sys.argv[1] + ".idx5").touch(exist_ok=False)
Path(
os.path.splitext(sys.argv[1])[0] + ".idx6" + os.path.splitext(sys.argv[1])[1]
).touch(exist_ok=False)
Path(sys.argv[1] + ".idx7").touch(exist_ok=False)
subdir = Path(sys.argv[1] + "_idx8")
subdir.mkdir()
(subdir / "index").touch(exist_ok=False)
8 changes: 5 additions & 3 deletions tests/iwd/loadit.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import json
import sys
j = json.load(open(sys.argv[1]))
json.dump({"class": j["class"],
"basename": j["basename"]}, sys.stdout, sort_keys=True)

with open(sys.argv[1]) as target:
j = json.load(target)

json.dump({"class": j["class"], "basename": j["basename"]}, sys.stdout, sort_keys=True)
59 changes: 42 additions & 17 deletions tests/json_schema/test_cwl_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,13 @@
from ruamel.yaml.scanner import ScannerError

# https://raw.githubusercontent.com/common-workflow-language/cwl-v1.2/1.2.1_proposed/conformance_tests.yaml
CONFORMANCE_TESTS_FILE = os.path.join(os.path.dirname(__file__), "../../conformance_tests.yaml")
CONFORMANCE_TESTS_FILE = os.path.join(
os.path.dirname(__file__), "../../conformance_tests.yaml"
)
# https://raw.githubusercontent.com/common-workflow-language/cwl-v1.2/1.2.1_proposed/json-schema/cwl.yaml
CWL_JSON_SCHEMA_FILE = os.path.join(os.path.dirname(__file__), "../../json-schema/cwl.yaml")
CWL_JSON_SCHEMA_FILE = os.path.join(
os.path.dirname(__file__), "../../json-schema/cwl.yaml"
)
CWL_JSON_SCHEMA_REF = f"{CWL_JSON_SCHEMA_FILE}#/$defs/CWL"

LOGGER = logging.getLogger(__name__)
Expand All @@ -35,22 +39,30 @@
_JSON: TypeAlias = "JSON"
_JsonObjectItemAlias: TypeAlias = "_JsonObjectItem"
_JsonListItemAlias: TypeAlias = "_JsonListItem"
_JsonObjectItem = Dict[str, Union[AnyValueType, _JSON, _JsonObjectItemAlias, _JsonListItemAlias]]
_JsonObjectItem = Dict[
str, Union[AnyValueType, _JSON, _JsonObjectItemAlias, _JsonListItemAlias]
]
_JsonListItem = List[Union[AnyValueType, _JSON, _JsonObjectItem, _JsonListItemAlias]]
_JsonItem = Union[AnyValueType, _JSON, _JsonObjectItem, _JsonListItem]
JSON = Union[Dict[str, Union[_JSON, _JsonItem]], List[Union[_JSON, _JsonItem]], AnyValueType]
JSON = Union[
Dict[str, Union[_JSON, _JsonItem]], List[Union[_JSON, _JsonItem]], AnyValueType
]

ConformanceTestDef = TypedDict(
"ConformanceTestDef",
{
"id": str,
"doc": str,
"tags": List[str], # should contain 'json_schema_invalid' to XFAIL schema validation tests
"tags": List[
str
], # should contain 'json_schema_invalid' to XFAIL schema validation tests
"tool": str,
"job": NotRequired[str], # not used, for running the actual CWL
"output": JSON, # not used, output of CWL execution
"should_fail": NotRequired[bool], # indicates failure as "execute failing", but potentially still valid CWL
}
"should_fail": NotRequired[
bool
], # indicates failure as "execute failing", but potentially still valid CWL
},
)


Expand All @@ -76,7 +88,7 @@ def load_file(file_path: str, text: bool = False) -> Union[JSON, str]:
:returns: loaded contents either parsed and converted to Python objects or as plain text.
:raises ValueError: if YAML or JSON cannot be parsed or loaded from location.
"""
yaml = YAML(typ='safe', pure=True)
yaml = YAML(typ="safe", pure=True)
try:
if is_remote_file(file_path):
headers = {"Accept": "text/plain"}
Expand Down Expand Up @@ -131,10 +143,11 @@ def load_conformance_tests(test_file: str) -> List[ConformanceTestDef]:


@pytest.mark.parametrize(
"conformance_test",
load_conformance_tests(CONFORMANCE_TESTS_FILE)
"conformance_test", load_conformance_tests(CONFORMANCE_TESTS_FILE)
)
def test_conformance(conformance_test: ConformanceTestDef, request: pytest.FixtureRequest) -> None:
def test_conformance(
conformance_test: ConformanceTestDef, request: pytest.FixtureRequest
) -> None:
LOGGER.debug(
"Testing [%s] (%s) with [%s]",
conformance_test["id"],
Expand All @@ -149,11 +162,17 @@ def test_conformance(conformance_test: ConformanceTestDef, request: pytest.Fixtu
instance_file = conformance_test["tool"].rsplit("#")[0]
instance = load_file(instance_file)
instance_xfail = "json_schema_invalid" in conformance_test.get("tags", [])
request.applymarker(pytest.mark.xfail(reason="Test tagged with 'json_schema_invalid'.", condition=instance_xfail))
request.applymarker(
pytest.mark.xfail(
reason="Test tagged with 'json_schema_invalid'.", condition=instance_xfail
)
)

schema_uri, schema_base, schema_test = resolve_ref(CWL_JSON_SCHEMA_REF)
validator: Type[Validator] = jsonschema.validators.validator_for(schema_base)
validator.resolver = jsonschema.RefResolver(base_uri=schema_uri, referrer=schema_base)
validator.resolver = jsonschema.RefResolver(
base_uri=schema_uri, referrer=schema_base
)

try:
# similar to 'validate()' call that raises directly, but obtain the error for more context
Expand All @@ -164,15 +183,21 @@ def test_conformance(conformance_test: ConformanceTestDef, request: pytest.Fixtu
if len(errors) == 1 and "oneOf" in errors[0].schema:
error = errors[0]
error.message += "\n\nFor each case under oneOf:\n" + "\n".join(
f"- {err.message}"
if not err.message.endswith("is not valid under any of the given schemas")
else f"- all invalid under oneOf {err.validator_value}"
(
f"- {err.message}"
if not err.message.endswith(
"is not valid under any of the given schemas"
)
else f"- all invalid under oneOf {err.validator_value}"
)
for err in error.context
)
raise error
main_error = cast(
ValidationError,
best_match(errors), # what 'validate()' normally does using 'iter_errors()'
best_match(
errors
), # what 'validate()' normally does using 'iter_errors()'
)
raise main_error
except Exception as exc:
Expand Down
5 changes: 3 additions & 2 deletions tests/loadContents/mkfilelist.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import json

ls = []
for i in range(1, 10000):
ls.append("example_input_file%i.txt" % i)
f = open("cwl.output.json", "w")
json.dump({"filelist": ls, "bigstring": "\n".join(ls)}, f)
with open("cwl.output.json", "w") as f:
json.dump({"filelist": ls, "bigstring": "\n".join(ls)}, f)
23 changes: 11 additions & 12 deletions tests/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,16 @@
indexfile = sys.argv[1] + ".idx1"
term = sys.argv[2]

main = open(mainfile)
index = open(indexfile)

st = term + ": "

for a in index:
if a.startswith(st):
n = [int(i) for i in a[len(st):].split(", ") if i]
linenum = 0
for l in main:
linenum += 1
if linenum in n:
print(f"{linenum} {l.rstrip()}")
break
with open(mainfile) as main:
with open(indexfile) as index:
for a in index:
if a.startswith(st):
n = [int(i) for i in a[len(st) :].split(", ") if i]
linenum = 0
for line in main:
linenum += 1
if linenum in n:
print(f"{linenum} {line.rstrip()}")
break
57 changes: 33 additions & 24 deletions tests/subdirsecondaries/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,42 @@

import sys
import os
from pathlib import Path

words = {}

mainfile = sys.argv[1]
indexfile = sys.argv[1] + ".idx1"

main = open(mainfile)
index = open(indexfile, "w")

linenum = 0
for l in main:
linenum += 1
l = l.rstrip().lower().replace(".", "").replace(",", "").replace(";", "").replace("-", " ")
for w in l.split(" "):
if w:
if w not in words:
words[w] = set()
words[w].add(linenum)

for w in sorted(words.keys()):
index.write("%s: %s" % (w, ", ".join((str(i) for i in words[w]))) + "\n")

open(os.path.splitext(sys.argv[1])[0] + ".idx2", "w")
open(sys.argv[1] + ".idx3", "w")
open(sys.argv[1] + ".idx4", "w")
open(sys.argv[1] + ".idx5", "w")
open(os.path.splitext(sys.argv[1])[0] + ".idx6" + os.path.splitext(sys.argv[1])[1], "w")
open(sys.argv[1] + ".idx7", "w")
os.mkdir(sys.argv[1] + "_idx8")
open(sys.argv[1] + "_idx8/index", "w")
with open(mainfile) as main:
for line in main:
linenum += 1
line = (
line.rstrip()
.lower()
.replace(".", "")
.replace(",", "")
.replace(";", "")
.replace("-", " ")
)
for word in line.split(" "):
if word:
if word not in words:
words[word] = set()
words[word].add(linenum)

with open(indexfile, "w") as index:
for w in sorted(words.keys()):
index.write("%s: %s" % (w, ", ".join((str(i) for i in words[w]))) + "\n")

Path(os.path.splitext(sys.argv[1])[0] + ".idx2").touch(exist_ok=False)
Path(sys.argv[1] + ".idx3").touch(exist_ok=False)
Path(sys.argv[1] + ".idx4").touch(exist_ok=False)
Path(sys.argv[1] + ".idx5").touch(exist_ok=False)
Path(
os.path.splitext(sys.argv[1])[0] + ".idx6" + os.path.splitext(sys.argv[1])[1]
).touch(exist_ok=False)
Path(sys.argv[1] + ".idx7").touch(exist_ok=False)
subdir = Path(sys.argv[1] + "_idx8")
subdir.mkdir(exist_ok=False)
(subdir / "index").touch(exist_ok=False)
10 changes: 5 additions & 5 deletions tests/updateval.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import sys
f = open(sys.argv[1], "r+")
val = int(f.read())
f.seek(0)
f.write(str(val+1))
f.close()

with open(sys.argv[1], "r+") as f:
val = int(f.read())
f.seek(0)
f.write(str(val + 1))