# Path: schema_salad/avro/schema.py
# class Names:
#     """Track name set and default namespace during parsing."""
# 
#     def __init__(self, default_namespace: Optional[str] = None) -> None:
#         self.names = {}  # type: Dict[str, NamedSchema]
#         self.default_namespace = default_namespace
# 
#     def has_name(self, name_attr: str, space_attr: Optional[str]) -> bool:
#         test = Name(name_attr, space_attr, self.default_namespace).fullname
#         return test in self.names
# 
#     def get_name(
#         self, name_attr: str, space_attr: Optional[str]
#     ) -> Optional["NamedSchema"]:
#         test = Name(name_attr, space_attr, self.default_namespace).fullname
#         if test not in self.names:
#             return None
#         return self.names[test]
# 
#     def add_name(
#         self, name_attr: str, space_attr: Optional[str], new_schema: "NamedSchema"
#     ) -> Name:
#         """
#         Add a new schema object to the name set.
# 
#           @arg name_attr: name value read in schema
#           @arg space_attr: namespace value read in schema.
# 
#           @return: the Name that was just added.
#         """
#         to_add = Name(name_attr, space_attr, self.default_namespace)
# 
#         if to_add.fullname in VALID_TYPES:
#             fail_msg = f"{to_add.fullname} is a reserved type name."
#             raise SchemaParseException(fail_msg)
#         elif to_add.fullname in self.names:
#             fail_msg = f'The name "{to_add.fullname}" is already in use.'
#             raise SchemaParseException(fail_msg)
#         elif to_add.fullname is None:
#             fail_msg = f"{to_add.fullname} is missing, but this is impossible."
#             raise SchemaParseException(fail_msg)
# 
#         self.names[to_add.fullname] = new_schema
#         return to_add
# 
# Path: schema_salad/exceptions.py
# class ValidationException(SchemaSaladException):
#     """Indicates error with document against the provided schema."""
# 
# Path: schema_salad/schema.py
# def load_and_validate(
#     document_loader: Loader,
#     avsc_names: Names,
#     document: Union[CommentedMap, str],
#     strict: bool,
#     strict_foreign_properties: bool = False,
# ) -> Tuple[Any, Dict[str, Any]]:
#     """Load a document and validate it with the provided schema.
# 
#     return data, metadata
#     """
#     try:
#         if isinstance(document, CommentedMap):
#             data, metadata = document_loader.resolve_all(
#                 document,
#                 document["id"],
#                 checklinks=True,
#                 strict_foreign_properties=strict_foreign_properties,
#             )
#         else:
#             data, metadata = document_loader.resolve_ref(
#                 document,
#                 checklinks=True,
#                 strict_foreign_properties=strict_foreign_properties,
#             )
# 
#         validate_doc(
#             avsc_names,
#             data,
#             document_loader,
#             strict,
#             strict_foreign_properties=strict_foreign_properties,
#         )
#     except ValidationException as exc:
#         raise ValidationException("", None, [exc]) from exc
#     return data, metadata
# 
# def load_schema(
#     schema_ref: ResolveType,
#     cache: Optional[CacheType] = None,
# ) -> schema_type:
#     """
#     Load a schema that can be used to validate documents using load_and_validate.
# 
#     return: document_loader, avsc_names, schema_metadata, metaschema_loader
#     """
# 
#     metaschema_names, _metaschema_doc, metaschema_loader = get_metaschema()
#     if cache is not None:
#         metaschema_loader.cache.update(cache)
#     schema_doc, schema_metadata = metaschema_loader.resolve_ref(schema_ref, "")
# 
#     if not isinstance(schema_doc, MutableSequence):
#         raise ValidationException("Schema reference must resolve to a list.")
# 
#     validate_doc(metaschema_names, schema_doc, metaschema_loader, True)
#     metactx = schema_metadata.get("@context", {})
#     metactx.update(collect_namespaces(schema_metadata))
#     schema_ctx = jsonld_context.salad_to_jsonld_context(schema_doc, metactx)[0]
# 
#     # Create the loader that will be used to load the target document.
#     document_loader = Loader(schema_ctx, cache=cache)
# 
#     # Make the Avro validation that will be used to validate the target
#     # document
#     avsc_names = make_avro_schema(schema_doc, document_loader, metaschema_loader.vocab)
# 
#     return document_loader, avsc_names, schema_metadata, metaschema_loader
# 
# Path: schema_salad/tests/util.py
# def get_data(filename):  # type: (Text) -> Optional[Text]
#     filename = os.path.normpath(filename)  # normalizing path depending on OS
#     # or else it will cause problem when joining path
#     filepath = None
#     try:
#         filepath = resource_filename(Requirement.parse("schema-salad"), filename)
#     except ResolutionError:
#         pass
#     if not filepath or not os.path.isfile(filepath):
#         filepath = os.path.join(os.path.dirname(__file__), os.pardir, filename)
#     return filepath


import pytest
from schema_salad.avro.schema import Names
from schema_salad.exceptions import ValidationException
from schema_salad.schema import load_and_validate, load_schema
from .util import get_data
        "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,
                )

# Path: schema_salad/avro/schema.py
# class Names:
#     """Track name set and default namespace during parsing."""
# 
#     def __init__(self, default_namespace: Optional[str] = None) -> None:
#         self.names = {}  # type: Dict[str, NamedSchema]
#         self.default_namespace = default_namespace
# 
#     def has_name(self, name_attr: str, space_attr: Optional[str]) -> bool:
#         test = Name(name_attr, space_attr, self.default_namespace).fullname
#         return test in self.names
# 
#     def get_name(
#         self, name_attr: str, space_attr: Optional[str]
#     ) -> Optional["NamedSchema"]:
#         test = Name(name_attr, space_attr, self.default_namespace).fullname
#         if test not in self.names:
#             return None
#         return self.names[test]
# 
#     def add_name(
#         self, name_attr: str, space_attr: Optional[str], new_schema: "NamedSchema"
#     ) -> Name:
#         """
#         Add a new schema object to the name set.
# 
#           @arg name_attr: name value read in schema
#           @arg space_attr: namespace value read in schema.
# 
#           @return: the Name that was just added.
#         """
#         to_add = Name(name_attr, space_attr, self.default_namespace)
# 
#         if to_add.fullname in VALID_TYPES:
#             fail_msg = f"{to_add.fullname} is a reserved type name."
#             raise SchemaParseException(fail_msg)
#         elif to_add.fullname in self.names:
#             fail_msg = f'The name "{to_add.fullname}" is already in use.'
#             raise SchemaParseException(fail_msg)
#         elif to_add.fullname is None:
#             fail_msg = f"{to_add.fullname} is missing, but this is impossible."
#             raise SchemaParseException(fail_msg)
# 
#         self.names[to_add.fullname] = new_schema
#         return to_add
# 
# Path: schema_salad/exceptions.py
# class ValidationException(SchemaSaladException):
#     """Indicates error with document against the provided schema."""
# 
# Path: schema_salad/schema.py
# def load_and_validate(
#     document_loader: Loader,
#     avsc_names: Names,
#     document: Union[CommentedMap, str],
#     strict: bool,
#     strict_foreign_properties: bool = False,
# ) -> Tuple[Any, Dict[str, Any]]:
#     """Load a document and validate it with the provided schema.
# 
#     return data, metadata
#     """
#     try:
#         if isinstance(document, CommentedMap):
#             data, metadata = document_loader.resolve_all(
#                 document,
#                 document["id"],
#                 checklinks=True,
#                 strict_foreign_properties=strict_foreign_properties,
#             )
#         else:
#             data, metadata = document_loader.resolve_ref(
#                 document,
#                 checklinks=True,
#                 strict_foreign_properties=strict_foreign_properties,
#             )
# 
#         validate_doc(
#             avsc_names,
#             data,
#             document_loader,
#             strict,
#             strict_foreign_properties=strict_foreign_properties,
#         )
#     except ValidationException as exc:
#         raise ValidationException("", None, [exc]) from exc
#     return data, metadata
# 
# def load_schema(
#     schema_ref: ResolveType,
#     cache: Optional[CacheType] = None,
# ) -> schema_type:
#     """
#     Load a schema that can be used to validate documents using load_and_validate.
# 
#     return: document_loader, avsc_names, schema_metadata, metaschema_loader
#     """
# 
#     metaschema_names, _metaschema_doc, metaschema_loader = get_metaschema()
#     if cache is not None:
#         metaschema_loader.cache.update(cache)
#     schema_doc, schema_metadata = metaschema_loader.resolve_ref(schema_ref, "")
# 
#     if not isinstance(schema_doc, MutableSequence):
#         raise ValidationException("Schema reference must resolve to a list.")
# 
#     validate_doc(metaschema_names, schema_doc, metaschema_loader, True)
#     metactx = schema_metadata.get("@context", {})
#     metactx.update(collect_namespaces(schema_metadata))
#     schema_ctx = jsonld_context.salad_to_jsonld_context(schema_doc, metactx)[0]
# 
#     # Create the loader that will be used to load the target document.
#     document_loader = Loader(schema_ctx, cache=cache)
# 
#     # Make the Avro validation that will be used to validate the target
#     # document
#     avsc_names = make_avro_schema(schema_doc, document_loader, metaschema_loader.vocab)
# 
#     return document_loader, avsc_names, schema_metadata, metaschema_loader
# 
# Path: schema_salad/tests/util.py
# def get_data(filename):  # type: (Text) -> Optional[Text]
#     filename = os.path.normpath(filename)  # normalizing path depending on OS
#     # or else it will cause problem when joining path
#     filepath = None
#     try:
#         filepath = resource_filename(Requirement.parse("schema-salad"), filename)
#     except ResolutionError:
#         pass
#     if not filepath or not os.path.isfile(filepath):
#         filepath = os.path.join(os.path.dirname(__file__), os.pardir, filename)
#     return filepath


# Path: schema_salad/tests/test_fp.py
import pytest
from schema_salad.avro.schema import Names
from schema_salad.exceptions import ValidationException
from schema_salad.schema import load_and_validate, load_schema
from .util import get_data

        "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: