Beispiel #1
0
    def test_errors(self):
        document_loader, avsc_names, schema_metadata, metaschema_loader = load_schema(
            get_data(u"tests/test_schema/CommonWorkflowLanguage.yml"))

        for t in ("test_schema/test1.cwl",
                  "test_schema/test2.cwl",
                  "test_schema/test3.cwl",
                  "test_schema/test4.cwl",
                  "test_schema/test5.cwl",
                  "test_schema/test6.cwl",
                  "test_schema/test7.cwl",
                  "test_schema/test8.cwl",
                  "test_schema/test9.cwl",
                  "test_schema/test10.cwl",
                  "test_schema/test11.cwl",
                  "test_schema/test12.cwl",
                  "test_schema/test13.cwl",
                  "test_schema/test14.cwl",
                  "test_schema/test15.cwl"):
            with self.assertRaises(ValidationException):
                try:
                    load_and_validate(document_loader, avsc_names,
                            six.text_type(get_data("tests/"+t)), True)
                except ValidationException as e:
                    print("\n", e)
                    raise
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument("swagger")
    parser.add_argument("annotations")
    parser.add_argument("url")

    parser.add_argument("--print-rdf", action="store_true", default=False)
    parser.add_argument("--serve", action="store_true", default=False)
    parser.add_argument("--fuseki-path", type=str, default=".")

    args = parser.parse_args()
    warnings.simplefilter('ignore', yaml.error.UnsafeLoaderWarning)

    with open(args.annotations) as f2:
        annotations = yaml.load(f2)

    with open(args.swagger) as f:
        sld = swg2salad.swg2salad(yaml.load(f), annotations)

    sld["$base"] = "http://ga4gh.org/schemas/tool-registry-schemas"
    sld["name"] = "file://" + os.path.realpath(args.swagger)

    document_loader, avsc_names, schema_metadata, metaschema_loader = load_schema(
        cmap(sld))

    txt = document_loader.fetch_text(
        urlparse.urljoin(
            "file://" +
            os.getcwd() +
            "/",
            args.url))
    r = yaml.load(txt)

    validate_doc(avsc_names, r, document_loader, True)

    sys.stderr.write("API returned valid response\n")

    toolreg = Namespace("http://ga4gh.org/schemas/tool-registry-schemas#")
    td = Namespace(
        "http://ga4gh.org/schemas/tool-registry-schemas#ToolDescriptor/")

    if args.print_rdf or args.serve:
        g = jsonld_context.makerdf(args.url, r, document_loader.ctx)
        for s, _, o in g.triples((None, td["type"], Literal("CWL"))):
            for _, _, d in g.triples((s, toolreg["descriptor"], None)):
                expand_cwl(d, unicode(s), g)

    if args.print_rdf:
        print(g.serialize(format="turtle"))

    if args.serve:
        t = tempfile.NamedTemporaryFile(suffix=".ttl")
        g.serialize(t, format="turtle")
        t.flush()
        subprocess.check_call(
            ["./fuseki-server", "--file=" + t.name, "/tools"], cwd=args.fuseki_path)
Beispiel #3
0
def get_schema(version):
    # type: (Text) -> Tuple[Loader, Union[schema.Names, schema.SchemaParseException], Dict[Text,Any], Loader]

    if version in SCHEMA_CACHE:
        return SCHEMA_CACHE[version]

    cache = {}  # type: Dict[Text, Union[bytes, Text]]
    version = version.split("#")[-1]
    if '.dev' in version:
        version = ".".join(version.split(".")[:-1])
    for f in cwl_files:
        try:
            res = resource_stream(__name__, 'schemas/%s/%s' % (version, f))
            cache["https://w3id.org/cwl/" + f] = res.read()
            res.close()
        except IOError:
            pass

    for f in salad_files:
        try:
            res = resource_stream(
                __name__, 'schemas/{}/salad/schema_salad/metaschema/{}'.format(
                    version, f))
            cache["https://w3id.org/cwl/salad/schema_salad/metaschema/"
                  + f] = res.read()
            res.close()
        except IOError:
            pass

    if version in custom_schemas:
        cache[custom_schemas[version][0]] = custom_schemas[version][1]
        SCHEMA_CACHE[version] = schema.load_schema(
            custom_schemas[version][0], cache=cache)
    else:
        SCHEMA_CACHE[version] = schema.load_schema(
            "https://w3id.org/cwl/CommonWorkflowLanguage.yml", cache=cache)

    return SCHEMA_CACHE[version]
def test_error_message3():
    document_loader, avsc_names, schema_metadata, metaschema_loader = load_schema(
        get_data(u"tests/test_schema/CommonWorkflowLanguage.yml")
    )

    t = "test_schema/test3.cwl"
    match = r"""
^.+test3\.cwl:5:1: checking field\s+`outputs`
.+test3\.cwl:6:3:   checking object\s+`.+test3\.cwl#bar`
\s+Field `type`\s+references\s+unknown\s+identifier\s+`xstring`,\s+tried
\s+file://.+/tests/test_schema/test3\.cwl#xstring$"""[
        1:
    ]
    with pytest.raises(ValidationException, match=match):
        load_and_validate(
            document_loader, avsc_names, six.text_type(get_data("tests/" + t)), True
        )
def test_error_message1():
    document_loader, avsc_names, schema_metadata, metaschema_loader = load_schema(
        get_data(u"tests/test_schema/CommonWorkflowLanguage.yml")
    )

    t = "test_schema/test1.cwl"
    match = (
        r"""^.+test1\.cwl:2:1: Object\s+`.+test1\.cwl`\s+is\s+not valid """
        + r"""because\s+tried `Workflow`\s+but
\s+\* missing\s+required\s+field\s+`inputs`
\s+\* missing\s+required\s+field\s+`outputs`
\s+\* missing\s+required\s+field\s+`steps`$"""
    )
    with pytest.raises(ValidationException, match=match):
        load_and_validate(
            document_loader, avsc_names, six.text_type(get_data("tests/" + t)), True
        )
def dotnet_codegen(file_uri: str,
                   target: Path,
                   examples: Optional[Path] = None) -> None:
    document_loader, avsc_names, schema_metadata, metaschema_loader = load_schema(
        file_uri)
    schema_raw_doc = metaschema_loader.fetch(file_uri)
    schema_doc, schema_metadata = metaschema_loader.resolve_all(
        schema_raw_doc, file_uri)
    codegen.codegen(
        "dotnet",
        cast(List[Dict[str, Any]], schema_doc),
        schema_metadata,
        document_loader,
        package="DotnetTest",
        target=str(target),
        examples=str(examples) if examples else None,
    )
def test_error_message11():
    document_loader, avsc_names, schema_metadata, metaschema_loader = load_schema(
        get_data(u"tests/test_schema/CommonWorkflowLanguage.yml")
    )

    t = "test_schema/test11.cwl"
    match = r"""
^.+test11\.cwl:7:1: checking field\s+`steps`
.+test11\.cwl:8:3:   checking object\s+`.+test11\.cwl#step1`
.+test11\.cwl:9:5:     Field `run`\s+contains\s+undefined\s+reference to
\s+`file://.+/tests/test_schema/blub\.cwl`$"""[
        1:
    ]
    with pytest.raises(ValidationException, match=match):
        load_and_validate(
            document_loader, avsc_names, six.text_type(get_data("tests/" + t)), True
        )
Beispiel #8
0
def test_fp() -> None:
    path = get_data("tests/test_schema/CommonWorkflowLanguage.yml")
    assert path
    document_loader, avsc_names, schema_metadata, metaschema_loader = load_schema(
        path)
    assert isinstance(avsc_names, Names)
    for t in (
            "foreign/foreign_prop1.cwl",
            "foreign/foreign_prop2.cwl",
            "foreign/foreign_prop3.cwl",
            "foreign/foreign_prop4.cwl",
            "foreign/foreign_prop5.cwl",
            "foreign/foreign_prop6.cwl",
            "foreign/foreign_prop7.cwl",
    ):
        path2 = get_data("tests/" + t)
        assert path2
        load_and_validate(
            document_loader,
            avsc_names,
            path2,
            True,
            strict_foreign_properties=False,
        )

    for t in (
            "foreign/foreign_prop1.cwl",
            "foreign/foreign_prop2.cwl",
            "foreign/foreign_prop4.cwl",
            "foreign/foreign_prop5.cwl",
    ):
        path3 = get_data("tests/" + t)
        assert path3
        with pytest.raises(ValidationException):
            try:
                print(t)
                load_and_validate(
                    document_loader,
                    avsc_names,
                    path3,
                    True,
                    strict_foreign_properties=True,
                )
            except ValidationException as e:
                print("\n", e)
                raise
Beispiel #9
0
def test_error_message8():
    document_loader, avsc_names, schema_metadata, metaschema_loader = load_schema(
        get_data("tests/test_schema/CommonWorkflowLanguage.yml")
    )

    t = "test_schema/test8.cwl"
    match = r"""
^.+test8\.cwl:7:1: checking field\s+`steps`
.+test8\.cwl:8:3:   checking object\s+`.+test8\.cwl#step1`
.+test8\.cwl:9:5:     Field\s+`scatterMethod`\s+contains\s+undefined\s+reference\s+to
\s+`file:///.+/tests/test_schema/abc`$"""[
        1:
    ]
    with pytest.raises(ValidationException, match=match):
        load_and_validate(
            document_loader, avsc_names, str(get_data("tests/" + t)), True
        )
Beispiel #10
0
    def test_errors(self):
        document_loader, avsc_names, schema_metadata, metaschema_loader = load_schema(
            u"schema_salad/tests/test_schema/CommonWorkflowLanguage.yml")
        avsc_names = cast(Names, avsc_names)

        for t in ("test_schema/test1.cwl", "test_schema/test2.cwl",
                  "test_schema/test3.cwl", "test_schema/test4.cwl",
                  "test_schema/test5.cwl", "test_schema/test6.cwl",
                  "test_schema/test7.cwl", "test_schema/test8.cwl",
                  "test_schema/test9.cwl", "test_schema/test10.cwl",
                  "test_schema/test11.cwl"):
            with self.assertRaises(ValidationException):
                try:
                    load_and_validate(document_loader, avsc_names,
                                      unicode("schema_salad/tests/" + t), True)
                except ValidationException as e:
                    print "\n", e
                    raise
Beispiel #11
0
def test_error_message1() -> None:
    path = get_data("tests/test_schema/CommonWorkflowLanguage.yml")
    assert path
    document_loader, avsc_names, schema_metadata, metaschema_loader = load_schema(
        path)
    assert isinstance(avsc_names, Names)

    t = "test_schema/test1.cwl"
    match = (
        r"""^.+test1\.cwl:2:1: Object\s+`.+test1\.cwl`\s+is\s+not valid """ +
        r"""because\s+tried `Workflow`\s+but
\s+\* missing\s+required\s+field\s+`inputs`
\s+\* missing\s+required\s+field\s+`outputs`
\s+\* missing\s+required\s+field\s+`steps`$""")
    path2 = get_data("tests/" + t)
    assert path2
    with pytest.raises(ValidationException, match=match):
        load_and_validate(document_loader, avsc_names, path2, True)
Beispiel #12
0
    def test_errors(self):
        document_loader, avsc_names, schema_metadata, metaschema_loader = load_schema(
            get_data(u"tests/test_schema/CommonWorkflowLanguage.yml"))

        for t in ("test_schema/test1.cwl", "test_schema/test2.cwl",
                  "test_schema/test3.cwl", "test_schema/test4.cwl",
                  "test_schema/test5.cwl", "test_schema/test6.cwl",
                  "test_schema/test7.cwl", "test_schema/test8.cwl",
                  "test_schema/test9.cwl", "test_schema/test10.cwl",
                  "test_schema/test11.cwl", "test_schema/test15.cwl"):
            with self.assertRaises(ValidationException):
                try:
                    load_and_validate(document_loader, avsc_names,
                                      six.text_type(get_data("tests/" + t)),
                                      True)
                except ValidationException as e:
                    print("\n", e)
                    raise
Beispiel #13
0
def test_error_message10():
    document_loader, avsc_names, schema_metadata, metaschema_loader = load_schema(
        get_data(u"tests/test_schema/CommonWorkflowLanguage.yml"))

    t = "test_schema/test10.cwl"
    match = r"""
^.+test10\.cwl:2:1: Object\s+`.+test10\.cwl`\s+is not valid because
\s+tried `Workflow`\s+but
.+test10\.cwl:7:1:     the `steps`\s+field\s+is\s+not\s+valid\s+because
\s+tried array\s+of\s+<WorkflowStep>\s+but
.+test10\.cwl:8:3:         item is\s+invalid\s+because
\s+\* missing\s+required\s+field\s+`run`
.+test10\.cwl:9:5:           \* the\s+`scatterMethod`\s+field\s+is\s+not\s+valid\s+because
\s+value\s+is\s+a\s+CommentedSeq,\s+expected\s+null\s+or\s+ScatterMethod$"""[
        1:]
    with pytest.raises(ValidationException, match=match):
        load_and_validate(document_loader, avsc_names,
                          six.text_type(get_data("tests/" + t)), True)
Beispiel #14
0
    def test_error_message5(self):
        document_loader, avsc_names, schema_metadata, metaschema_loader = load_schema(
            get_data(u"tests/test_schema/CommonWorkflowLanguage.yml"))

        t = "test_schema/test5.cwl"
        with self.assertRaises(ValidationException) as e:
            load_and_validate(document_loader, avsc_names,
                              six.text_type(get_data("tests/" + t)), True)
        self.assertTrue(
            re.match(
                r'''
^.+test5\.cwl:2:1: Object\s+`.+test5\.cwl`\s+is\s+not valid because
\s+tried `Workflow`\s+but
.+test5\.cwl:7:1:     the `steps`\s+field\s+is\s+not valid\s+because
\s+tried array\s+of\s+<WorkflowStep>\s+but
.+test5\.cwl:7:9:         item is\s+invalid because
\s+is not a\s+dict$'''[1:], str(e.exception)),
            str(e.exception) + ' is not matched.')
Beispiel #15
0
def test_errors_previously_defined_dict_key():
    document_loader, avsc_names, schema_metadata, metaschema_loader = load_schema(
        get_data("tests/test_schema/CommonWorkflowLanguage.yml")
    )

    for t in (
        "test_schema/test12.cwl",
        "test_schema/test13.cwl",
        "test_schema/test14.cwl",
    ):
        with pytest.raises(ValidationException):
            try:
                load_and_validate(
                    document_loader, avsc_names, str(get_data("tests/" + t)), True,
                )
            except ValidationException as e:
                print("\n", e)
                raise
Beispiel #16
0
    def setup_class(cls) -> None:

        #filepath = pathlib.Path(__file__).resolve().parent
        print("here i am {}".format(os.getcwd()))
        #filepath = "schema_salad/tests/test_schema/" #/"+test_dir_name
        filepath = "."
        tf = tarfile.open(os.path.join(filepath, "v1.2.0.tar.gz"))
        tf.extractall(os.path.join(filepath))  #this becomes cwl-v1.2-1.2.0
        path = get_data(
            os.path.join(filepath,
                         "cwl-v1.2-1.2.0/CommonWorkflowLanguage.yml"))
        assert path
        (
            cls.document_loader,
            cls.avsc_names,
            schema_metadata,
            metaschema_loader,
        ) = load_schema(path)
Beispiel #17
0
def test_error_message5() -> None:
    path = get_data("tests/test_schema/CommonWorkflowLanguage.yml")
    assert path
    document_loader, avsc_names, schema_metadata, metaschema_loader = load_schema(
        path)
    assert isinstance(avsc_names, Names)

    t = "test_schema/test5.cwl"
    match = r"""
^.+test5\.cwl:2:1: Object\s+`.+test5\.cwl`\s+is\s+not valid because
\s+tried `Workflow`\s+but
.+test5\.cwl:7:1:     the `steps`\s+field\s+is\s+not\s+valid\s+because
\s+tried array\s+of\s+<WorkflowStep>\s+but
.+test5\.cwl:7:9:         item is\s+invalid\s+because
\s+is not a\s+dict$"""[1:]
    with pytest.raises(ValidationException, match=match):
        load_and_validate(document_loader, avsc_names,
                          str(get_data("tests/" + t)), True)
Beispiel #18
0
def test_error_message7():
    document_loader, avsc_names, schema_metadata, metaschema_loader = load_schema(
        get_data(u"tests/test_schema/CommonWorkflowLanguage.yml"))

    t = "test_schema/test7.cwl"
    match = (
        r"""^.+test7\.cwl:2:1: Object\s+`.+test7\.cwl`\s+is\s+not valid because
\s+tried `Workflow`\s+but
.+test7\.cwl:7:1:     the `steps`\s+field\s+is\s+not\s+valid\s+because
\s+tried array\s+of\s+<WorkflowStep>\s+but
.+test7\.cwl:8:3:         item is\s+invalid\s+because
\s+\* missing\s+required\s+field\s+`run`
.+test7\.cwl:9:5:           \* invalid\s+field\s+`scatter_method`,\s+expected\s+one """
        + r"""of:\s+'id',\s+'in', 'out',\s+'requirements',\s+'hints',\s+""" +
        r"""'label',\s+'doc',\s+'run',\s+'scatter',\s+'scatterMethod'$""")
    with pytest.raises(ValidationException, match=match):
        load_and_validate(document_loader, avsc_names,
                          six.text_type(get_data("tests/" + t)), True)
    def test_print_oneline_for_invalid_yaml(self):
        # Issue #137
        document_loader, avsc_names, schema_metadata, metaschema_loader = load_schema(
            get_data(u"tests/test_schema/CommonWorkflowLanguage.yml"))

        src = "test16.cwl"
        with self.assertRaises(RuntimeError):
            try:
                load_and_validate(
                    document_loader, avsc_names,
                    six.text_type(get_data("tests/test_schema/" + src)), True)
            except RuntimeError as e:
                msg = reformat_yaml_exception_message(
                    strip_dup_lineno(six.text_type(e)))
                msg = to_one_line_messages(msg)
                self.assertTrue(
                    msg.endswith(src + ":10:1: could not find expected \':\'"))
                print("\n", e)
                raise
def test_print_oneline_for_invalid_yaml():
    # Issue #137
    document_loader, avsc_names, schema_metadata, metaschema_loader = load_schema(
        get_data("tests/test_schema/CommonWorkflowLanguage.yml"))

    src = "test16.cwl"
    with pytest.raises(ValidationException):
        try:
            load_and_validate(
                document_loader,
                avsc_names,
                str(get_data("tests/test_schema/" + src)),
                True,
            )
        except ValidationException as e:
            msg = to_one_line_messages(e)
            assert msg.endswith(src + ":11:1: could not find expected ':'")
            print("\n", e)
            raise
    def test_for_invalid_yaml2(self):
        # Issue 143
        document_loader, avsc_names, schema_metadata, metaschema_loader = load_schema(
            get_data(u"tests/test_schema/CommonWorkflowLanguage.yml"))

        src = "test19.cwl"
        with self.assertRaises(RuntimeError):
            try:
                load_and_validate(
                    document_loader, avsc_names,
                    six.text_type(get_data("tests/test_schema/" + src)), True)
            except RuntimeError as e:
                msg = reformat_yaml_exception_message(
                    strip_dup_lineno(six.text_type(e)))
                self.assertTrue(
                    msg.endswith(src +
                                 ":1:1: expected <block end>, but found ':'"))
                print("\n", e)
                raise
def test_print_oneline_for_errors_in_resolve_ref():
    # Issue #141
    document_loader, avsc_names, schema_metadata, metaschema_loader = load_schema(
        get_data("tests/test_schema/CommonWorkflowLanguage.yml"))

    src = "test18.cwl"
    fullpath = normpath(get_data("tests/test_schema/" + src))
    with pytest.raises(ValidationException):
        try:
            load_and_validate(document_loader, avsc_names, str(fullpath), True)
        except ValidationException as e:
            msg = to_one_line_messages(e)
            # convert Windows path to Posix path
            if "\\" in fullpath:
                fullpath = "/" + fullpath.lower().replace("\\", "/")
            print("\n", e)
            assert msg.endswith(
                src + ":14:5: Field `type` references unknown identifier "
                "`Filea`, tried file://%s#Filea" % (fullpath))
            raise
Beispiel #23
0
    def test_error_message7(self):
        document_loader, avsc_names, schema_metadata, metaschema_loader = load_schema(
            get_data(u"tests/test_schema/CommonWorkflowLanguage.yml"))

        t = "test_schema/test7.cwl"
        with self.assertRaises(ValidationException) as e:
            load_and_validate(document_loader, avsc_names,
                              six.text_type(get_data("tests/" + t)), True)
        self.assertTrue(
            re.match(
                r'''
^.+test7\.cwl:2:1: Object\s+`.+test7\.cwl`\s+is\s+not valid because
\s+tried `Workflow`\s+but
.+test7\.cwl:7:1:     the `steps`\s+field\s+is\s+not valid\s+because
\s+tried array\s+of\s+<WorkflowStep>\s+but
.+test7\.cwl:8:3:         item is\s+invalid because
\s+\* missing\s+required\s+field `run`
.+test7\.cwl:9:5:           \* invalid\s+field\s+`scatter_method`,\s+expected one of:\s+'id', 'in', 'out',\s+'requirements',\s+'hints', 'label',\s+'doc',\s+'run',\s+'scatter',\s+'scatterMethod'$'''[
                    1:], str(e.exception)),
            str(e.exception) + ' is not matched.')
Beispiel #24
0
def test_fp():
    document_loader, avsc_names, schema_metadata, metaschema_loader = load_schema(
        get_data(u"tests/test_schema/CommonWorkflowLanguage.yml")
    )

    for t in (
        "foreign/foreign_prop1.cwl",
        "foreign/foreign_prop2.cwl",
        "foreign/foreign_prop3.cwl",
        "foreign/foreign_prop4.cwl",
        "foreign/foreign_prop5.cwl",
        "foreign/foreign_prop6.cwl",
        "foreign/foreign_prop7.cwl",
    ):
        load_and_validate(
            document_loader,
            avsc_names,
            six.text_type(get_data("tests/" + t)),
            True,
            strict_foreign_properties=False,
        )

    for t in (
        "foreign/foreign_prop1.cwl",
        "foreign/foreign_prop2.cwl",
        "foreign/foreign_prop4.cwl",
        "foreign/foreign_prop5.cwl",
    ):
        with pytest.raises(ValidationException):
            try:
                print (t)
                load_and_validate(
                    document_loader,
                    avsc_names,
                    six.text_type(get_data("tests/" + t)),
                    True,
                    strict_foreign_properties=True,
                )
            except ValidationException as e:
                print ("\n", e)
                raise
Beispiel #25
0
def python_codegen(
    file_uri: str,
    target: Path,
    parser_info: Optional[str] = None,
    package: Optional[str] = None,
) -> None:
    document_loader, avsc_names, schema_metadata, metaschema_loader = load_schema(
        file_uri)
    assert isinstance(avsc_names, Names)
    schema_raw_doc = metaschema_loader.fetch(file_uri)
    schema_doc, schema_metadata = metaschema_loader.resolve_all(
        schema_raw_doc, file_uri)
    codegen.codegen(
        "python",
        cast(List[Dict[str, Any]], schema_doc),
        schema_metadata,
        document_loader,
        target=str(target),
        parser_info=parser_info,
        package=package,
    )
Beispiel #26
0
    def test_error_message15(self):
        document_loader, avsc_names, schema_metadata, metaschema_loader = load_schema(
            get_data(u"tests/test_schema/CommonWorkflowLanguage.yml"))

        t = "test_schema/test15.cwl"
        with self.assertRaises(ValidationException) as e:
            load_and_validate(document_loader, avsc_names,
                              six.text_type(get_data("tests/" + t)), True)
        self.assertTrue(
            re.match(
                r'''
^.+test15\.cwl:3:1:\s+Object\s+`.+test15\.cwl`\s+is not valid because
\s+tried\s+`CommandLineTool`\s+but
.+test15\.cwl:6:1:\s+the `inputs`\s+field\s+is not valid\s+because
.+test15\.cwl:7:3:\s+item is\s+invalid\s+because
.+test15\.cwl:9:5:\s+the\s+`inputBinding`\s+field is not\s+valid\s+because
.+tried\s+CommandLineBinding\s+but
.+test15\.cwl:11:7:             \*\s+invalid field\s+`invalid_field`,\s+expected one\s+of:\s+'loadContents',\s+'position',\s+'prefix',\s+'separate',\s+'itemSeparator',\s+'valueFrom',\s+'shellQuote'
.+test15\.cwl:12:7:             \*\s+invalid field\s+`another_invalid_field`,\s+expected one\s+of:\s+'loadContents',\s+'position',\s+'prefix',\s+'separate',\s+'itemSeparator',\s+'valueFrom',\s+'shellQuote'$'''[
                    1:], str(e.exception)),
            str(e.exception) + ' is not matched.')
Beispiel #27
0
    def test_error_message10(self):
        document_loader, avsc_names, schema_metadata, metaschema_loader = load_schema(
            get_data(u"tests/test_schema/CommonWorkflowLanguage.yml"))

        t = "test_schema/test10.cwl"
        with self.assertRaises(ValidationException) as e:
            load_and_validate(document_loader, avsc_names,
                              six.text_type(get_data("tests/" + t)), True)
        self.assertTrue(
            re.match(
                r'''
^.+test10\.cwl:2:1: Object\s+`.+test10\.cwl`\s+is not valid because
\s+tried `Workflow`\s+but
.+test10\.cwl:7:1:     the `steps`\s+field is\s+not valid\s+because
\s+tried array\s+of\s+<WorkflowStep>\s+but
.+test10\.cwl:8:3:         item is\s+invalid because
\s+\* missing\s+required\s+field `run`
.+test10\.cwl:9:5:           \* the\s+`scatterMethod`\s+field is\s+not valid\s+because
\s+value\s+is a\s+CommentedSeq,\s+expected\s+null\s+or\s+ScatterMethod$'''[1:],
                str(e.exception)),
            str(e.exception) + ' is not matched.')
def test_for_invalid_yaml2():
    # Issue 143
    document_loader, avsc_names, schema_metadata, metaschema_loader = load_schema(
        get_data("tests/test_schema/CommonWorkflowLanguage.yml"))

    src = "test19.cwl"
    with pytest.raises(ValidationException):
        try:
            load_and_validate(
                document_loader,
                avsc_names,
                str(get_data("tests/test_schema/" + src)),
                True,
            )
        except ValidationException as e:
            msg = str(e)
            assert (msg.endswith("expected <block end>, but found ':'")
                    or msg.endswith("expected <block end>, but found u':'")
                    or re.search(r"mapping with\s+implicit\s+null key$", msg,
                                 re.M))
            print("\n", e)
            raise
def test_for_invalid_yaml1():
    # Issue 143
    document_loader, avsc_names, schema_metadata, metaschema_loader = load_schema(
        get_data("tests/test_schema/CommonWorkflowLanguage.yml"))

    src = "test16.cwl"
    with pytest.raises(ValidationException):
        try:
            load_and_validate(
                document_loader,
                avsc_names,
                str(get_data("tests/test_schema/" + src)),
                True,
            )
        except ValidationException as e:
            msg = str(e)
            assert re.search(src + r":10:7: while scanning a\s+simple\s+key",
                             msg, re.M)
            assert re.search(
                src + r":11:1:   could not\s+find\s+expected ':'$", msg, re.M)
            print("\n", e)
            raise
    def test_errors(self):
        document_loader, avsc_names, schema_metadata, metaschema_loader = load_schema(
            u"schema_salad/tests/test_schema/CommonWorkflowLanguage.yml")
        avsc_names = cast(Names, avsc_names)

        for t in ("test_schema/test1.cwl",
                  "test_schema/test2.cwl",
                  "test_schema/test3.cwl",
                  "test_schema/test4.cwl",
                  "test_schema/test5.cwl",
                  "test_schema/test6.cwl",
                  "test_schema/test7.cwl",
                  "test_schema/test8.cwl",
                  "test_schema/test9.cwl",
                  "test_schema/test10.cwl",
                  "test_schema/test11.cwl"):
            with self.assertRaises(ValidationException):
                try:
                    load_and_validate(document_loader, avsc_names, unicode("schema_salad/tests/"+t), True)
                except ValidationException as e:
                    print "\n", e
                    raise
Beispiel #31
0
    def test_print_oneline_for_errors_in_resolve_ref(self):
        # Issue #141
        document_loader, avsc_names, schema_metadata, metaschema_loader = load_schema(
            get_data(u"tests/test_schema/CommonWorkflowLanguage.yml"))

        src = "test18.cwl"
        fullpath = normpath(get_data("tests/test_schema/" + src))
        with self.assertRaises(ValidationException):
            try:
                load_and_validate(document_loader, avsc_names,
                                  six.text_type(fullpath), True)
            except ValidationException as e:
                msgs = to_one_line_messages(
                    str(strip_dup_lineno(six.text_type(e)))).splitlines()
                # convert Windows path to Posix path
                if '\\' in fullpath:
                    fullpath = '/' + fullpath.lower().replace('\\', '/')
                self.assertEqual(len(msgs), 1)
                print("\n", e)
                assert msgs[0].endswith(
                    src + ':13:5: Field `type` references unknown identifier '
                    '`Filea`, tried file://%s#Filea' % (fullpath))
                raise
    def test_print_oneline_for_errors_in_the_same_line(self):
        # Issue #136
        document_loader, avsc_names, schema_metadata, metaschema_loader = load_schema(
            get_data(u"tests/test_schema/CommonWorkflowLanguage.yml"))

        src = "test17.cwl"
        with self.assertRaises(ValidationException):
            try:
                load_and_validate(
                    document_loader, avsc_names,
                    six.text_type(get_data("tests/test_schema/" + src)), True)
            except ValidationException as e:
                msgs = to_one_line_messages(str(e)).splitlines()
                self.assertEqual(len(msgs), 2)
                self.assertTrue(
                    msgs[0].endswith(src +
                                     ":13:5: missing required field `id`"))
                self.assertTrue(msgs[1].endswith(
                    src +
                    ":13:5: invalid field `aa`, expected one of: 'label', 'secondaryFiles', 'format', 'streamable', 'doc', 'id', 'outputBinding', 'type'"
                ))
                print("\n", e)
                raise
def test_error_message15():
    document_loader, avsc_names, schema_metadata, metaschema_loader = load_schema(
        get_data(u"tests/test_schema/CommonWorkflowLanguage.yml")
    )

    t = "test_schema/test15.cwl"
    match = (
        r"""^.+test15\.cwl:3:1:\s+Object\s+`.+test15\.cwl`\s+is not valid because
\s+tried\s+`CommandLineTool`\s+but
.+test15\.cwl:6:1:\s+the `inputs`\s+field\s+is not valid\s+because
.+test15\.cwl:7:3:\s+item is\s+invalid\s+because
.+test15\.cwl:9:5:\s+the\s+`inputBinding`\s+field is not\s+valid\s+because
.+tried\s+CommandLineBinding\s+but
.+test15\.cwl:11:7:             \*\s+invalid field\s+`invalid_field`,\s+expected """
        + r"""one\s+of:\s+'loadContents',\s+'position',\s+'prefix',\s+'separate',"""
        + r"""\s+'itemSeparator',\s+'valueFrom',\s+'shellQuote'
.+test15\.cwl:12:7:             \*\s+invalid field\s+`another_invalid_field`,"""
        + r"""\s+expected one\s+of:\s+'loadContents',\s+'position',\s+'prefix',"""
        + r"""\s+'separate',\s+'itemSeparator',\s+'valueFrom',\s+'shellQuote'$"""
    )
    with pytest.raises(ValidationException, match=match):
        load_and_validate(
            document_loader, avsc_names, six.text_type(get_data("tests/" + t)), True
        )
    def test_for_invalid_yaml1(self):
        # Issue 143
        document_loader, avsc_names, schema_metadata, metaschema_loader = load_schema(
            get_data(u"tests/test_schema/CommonWorkflowLanguage.yml"))

        src = "test16.cwl"
        with self.assertRaises(RuntimeError):
            try:
                load_and_validate(
                    document_loader, avsc_names,
                    six.text_type(get_data("tests/test_schema/" + src)), True)
            except RuntimeError as e:
                msg = reformat_yaml_exception_message(
                    strip_dup_lineno(six.text_type(e)))
                msgs = msg.splitlines()
                self.assertEqual(len(msgs), 2)
                self.assertTrue(
                    msgs[0].endswith(src +
                                     ":9:7: while scanning a simple key"))
                self.assertTrue(
                    msgs[1].endswith(src +
                                     ":10:1:   could not find expected ':'"))
                print("\n", e)
                raise