comparison env/lib/python3.9/site-packages/cwltool/tests/test_validate_js.py @ 0:4f3585e2f14b draft default tip

"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
author shellac
date Mon, 22 Mar 2021 18:12:50 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:4f3585e2f14b
1 from typing import Any
2
3 from ruamel import yaml
4 from schema_salad.avro.schema import Names
5
6 from cwltool import process, validate_js
7 from cwltool.sandboxjs import code_fragment_to_js
8
9 TEST_CWL = """
10 cwlVersion: v1.0
11 class: CommandLineTool
12 baseCommand: echo
13
14 requirements:
15 - class: InlineJavascriptRequirement
16 inputs:
17 - id: parameter
18 inputBinding:
19 valueFrom: string before $(kjdbfkjd) string after
20 type: string?
21
22 outputs: []
23 """
24
25
26 def test_get_expressions() -> None:
27 test_cwl_yaml = yaml.main.round_trip_load(TEST_CWL)
28 schema = process.get_schema("v1.0")[1]
29 assert isinstance(schema, Names)
30 clt_schema = schema.names["CommandLineTool"]
31
32 exprs = validate_js.get_expressions(test_cwl_yaml, clt_schema)
33
34 assert len(exprs) == 1
35
36
37 def test_validate_js_expressions(mocker: Any) -> None:
38 test_cwl_yaml = yaml.main.round_trip_load(TEST_CWL)
39 schema = process.get_schema("v1.0")[1]
40 assert isinstance(schema, Names)
41 clt_schema = schema.names["CommandLineTool"]
42
43 mocker.patch("cwltool.validate_js._logger")
44 # mocker.patch("cwltool.validate_js.print_js_hint_messages")
45 validate_js.validate_js_expressions(test_cwl_yaml, clt_schema)
46
47 validate_js._logger.warning.assert_called_with(" JSHINT: (function(){return ((kjdbfkjd));})()\n JSHINT: ^\n JSHINT: W117: 'kjdbfkjd' is not defined.") # type: ignore
48
49
50 def test_js_hint_basic() -> None:
51 result = validate_js.jshint_js(
52 """
53 function funcName(){
54 }
55 """,
56 [],
57 )
58
59 assert result.errors == []
60 assert result.globals == ["funcName"]
61
62
63 def test_js_hint_reports_invalid_js() -> None:
64 assert len(validate_js.jshint_js("<INVALID JS>").errors) > 1
65
66
67 def test_js_hint_warn_on_es6() -> None:
68 assert (
69 len(validate_js.jshint_js(code_fragment_to_js("((() => 4)())"), []).errors) == 1
70 )
71
72
73 def test_js_hint_error_on_undefined_name() -> None:
74 assert (
75 len(validate_js.jshint_js(code_fragment_to_js("undefined_name()")).errors) == 1
76 )
77
78
79 def test_js_hint_set_defined_name() -> None:
80 assert (
81 len(
82 validate_js.jshint_js(
83 code_fragment_to_js("defined_name()"), ["defined_name"]
84 ).errors
85 )
86 == 0
87 )