def test_for_invalid_yaml2():
    # Issue 143
    document_loader, avsc_names, schema_metadata, metaschema_loader = load_schema(
        get_data(u"tests/test_schema/CommonWorkflowLanguage.yml"))

    src = "test19.cwl"
    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)))
        assert msg.endswith(
            src + ":2:1: expected <block end>, but found ':'") or msg.endswith(
                src + ":2:1: expected <block end>, but found u':'")
        return
    except ValidationException as e:
        msgs = str(strip_dup_lineno(six.text_type(e)))
        print(msgs)
        # weird splits due to differing path length on MS Windows
        # & during the release tests
        assert "{}:2:1: Object".format(src) in msgs
        assert "is not valid because" in msgs
        assert "`CommandLineTool`" in msgs
        assert "mapping with" in msgs
        assert "implicit" in msgs
        assert "null key" in msgs
        return
    assert False, "Missing RuntimeError or ValidationException"
    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_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_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