1
+ """Tests of cwl_utils.file_formats."""
2
+
1
3
import xml .sax
2
- from typing import Any , Optional
4
+ from typing import Optional
3
5
4
6
import requests
5
7
from pytest import raises
9
11
from schema_salad .fetcher import DefaultFetcher
10
12
11
13
from cwl_utils .file_formats import check_format
14
+ from cwl_utils .types import CWLObjectType
12
15
13
16
14
- def _create_file (format_ : Optional [str ] = None ) -> Any :
15
- obj = {
17
+ def _create_file (format_ : Optional [str ] = None ) -> CWLObjectType :
18
+ obj : CWLObjectType = {
16
19
"class" : "File" ,
17
20
"basename" : "example.txt" ,
18
21
"size" : 23 ,
@@ -38,15 +41,25 @@ def _load_format(fetchurl: str) -> Graph:
38
41
return graph
39
42
40
43
41
- def test_check_format () -> None :
44
+ def test_check_format ():
42
45
check_format (
43
46
actual_file = _create_file (format_ = "http://edamontology.org/format_2330" ),
44
47
input_formats = "http://edamontology.org/format_2330" ,
45
48
ontology = _load_format ("http://edamontology.org/EDAM.owl" ),
46
49
)
47
50
48
51
52
+ def test_check_format_subformat () -> None :
53
+ """Test of check_format with a subformat."""
54
+ check_format (
55
+ actual_file = _create_file (format_ = "http://edamontology.org/format_1929" ),
56
+ input_formats = "http://edamontology.org/format_2330" ,
57
+ ontology = _load_format ("http://edamontology.org/EDAM.owl" ),
58
+ )
59
+
60
+
49
61
def test_check_format_no_format () -> None :
62
+ """Confirm that a missing format produces the expected exception."""
50
63
with raises (ValidationException , match = r"File has no 'format' defined: .*" ):
51
64
check_format (
52
65
actual_file = _create_file (),
@@ -56,6 +69,7 @@ def test_check_format_no_format() -> None:
56
69
57
70
58
71
def test_check_format_no_input_formats () -> None :
72
+ """Unknown test."""
59
73
with raises (ValidationException , match = r"File has an incompatible format: .*" ):
60
74
check_format (
61
75
actual_file = _create_file (format_ = "http://edamontology.org/format_2330" ),
@@ -65,6 +79,7 @@ def test_check_format_no_input_formats() -> None:
65
79
66
80
67
81
def test_check_format_no_ontology () -> None :
82
+ """Confirm that precisely matching formats without an ontology still match."""
68
83
check_format (
69
84
actual_file = _create_file (format_ = "http://edamontology.org/format_2330" ),
70
85
input_formats = "http://edamontology.org/format_2330" ,
0 commit comments