comparison planemo/lib/python3.7/site-packages/cwltool/tests/test_validate_js.py @ 0:d30785e31577 draft

"planemo upload commit 6eee67778febed82ddd413c3ca40b3183a3898f1"
author guerler
date Fri, 31 Jul 2020 00:18:57 -0400
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:d30785e31577
1 from ruamel import yaml
2
3 from cwltool import process
4 from cwltool.sandboxjs import code_fragment_to_js
5 from cwltool import validate_js
6
7 TEST_CWL = """
8 cwlVersion: v1.0
9 class: CommandLineTool
10 baseCommand: echo
11
12 requirements:
13 - class: InlineJavascriptRequirement
14 inputs:
15 - id: parameter
16 inputBinding:
17 valueFrom: string before $(kjdbfkjd) string after
18 type: string?
19
20 outputs: []
21 """
22
23 def test_get_expressions():
24 test_cwl_yaml = yaml.round_trip_load(TEST_CWL)
25 schema = process.get_schema("v1.0")[1].names["CommandLineTool"]
26
27 exprs = validate_js.get_expressions(test_cwl_yaml, schema)
28
29 assert len(exprs) == 1
30
31
32 def test_validate_js_expressions(mocker):
33 test_cwl_yaml = yaml.round_trip_load(TEST_CWL)
34 schema = process.get_schema("v1.0")[1].names["CommandLineTool"]
35
36 mocker.patch("cwltool.validate_js.print_js_hint_messages")
37 validate_js.validate_js_expressions(test_cwl_yaml, schema)
38
39 assert validate_js.print_js_hint_messages.call_args is not None
40 assert len(validate_js.print_js_hint_messages.call_args[0]) > 0
41
42 def test_js_hint_basic():
43 result = validate_js.jshint_js("""
44 function funcName(){
45 }
46 """, [])
47
48 assert result.errors == []
49 assert result.globals == ["funcName"]
50
51 def test_js_hint_reports_invalid_js():
52 assert len(validate_js.jshint_js("<INVALID JS>").errors) > 1
53
54 def test_js_hint_warn_on_es6():
55 assert len(validate_js.jshint_js(code_fragment_to_js("((() => 4)())"), []).errors) == 1
56
57 def test_js_hint_error_on_undefined_name():
58 assert len(validate_js.jshint_js(code_fragment_to_js("undefined_name()")).errors) == 1
59
60 def test_js_hint_set_defined_name():
61 assert len(validate_js.jshint_js(code_fragment_to_js("defined_name()"), ["defined_name"]).errors) == 0