# Path: siptools/scripts/define_xml_schemas.py
# def main(**kwargs):
# def define_schemas(uri_pairs,
#                    base_path='.',
#                    workspace='./workspace/',
#                    stdout=False):
#     def add_premis_md(self, schemas):
#     def write(self, mdtype="PREMIS:OBJECT", mdtypeversion="2.3",
#               othermdtype=None, section=None, stdout=False,
#               file_metadata_dict=None,
#               ref_file="define-xml-schemas-md-references.jsonl"):
# def create_premis_representation(schemas):
# def _check_filepaths(schemas=None, base='.'):
# class PremisCreator(MetsSectionCreator):
#     RETVAL = main()  # pylint: disable=no-value-for-parameter
# 
# Path: siptools/utils.py
# def read_md_references(workspace, ref_file):
#     """Read all the MD IDs as a dictionary.
# 
#     :workspace: path to workspace directory
#     :ref_file: Metadata reference file
#     :returns: A dict of references or None if reference file doesn't
#               exist
#     """
#     reference_file = os.path.join(workspace, ref_file)
# 
#     if os.path.isfile(reference_file):
#         references = {}
#         with open(reference_file) as in_file:
#             for line in in_file:
#                 references.update(json.loads(line))
#         return references
#     return None
# 
# Path: siptools/xml/mets.py
# NAMESPACES = {
#     'mets': 'http://www.loc.gov/METS/',
#     'xsi': 'http://www.w3.org/2001/XMLSchema-instance',
#     'premis': 'info:lc/xmlns/premis-v2',
#     'fi': 'http://digitalpreservation.fi/schemas/mets/fi-extensions',
#     'xlink': 'http://www.w3.org/1999/xlink',
#     'mix': 'http://www.loc.gov/mix/v20',
#     'ead3': 'http://ead3.archivists.org/schema/',
#     'addml': 'http://www.arkivverket.no/standarder/addml',
#     'audiomd': 'http://www.loc.gov/audioMD/',
#     'videomd': 'http://www.loc.gov/videoMD/'
# }


import os
import lxml.etree as ET
from siptools.scripts import define_xml_schemas
from siptools.utils import read_md_references
from siptools.xml.mets import NAMESPACES
        assert dependency.xpath(
            './premis:dependencyIdentifier/premis:dependencyIdentifierType',
            namespaces=NAMESPACES)[0].text == id_type


def test_define_xml_schemas_base_path_ok(testpath, run_cli):
    """Test define_xml_schemas.main funtion with valid test data using
    the base_path argument.
    """
    input_file = 'mets_valid_minimal.xml'
    arguments = ['--workspace', testpath, '--uri_pairs',
                 'myuri', input_file,
                 '--base_path', 'tests/data']
    run_cli(define_xml_schemas.main, arguments)

    output = get_amd_file(testpath)
    tree = ET.parse(output[0])
    root = tree.getroot()

    assert len(root.xpath('/mets:mets/mets:amdSec/mets:techMD',
                          namespaces=NAMESPACES)) == 1


def test_define_xml_schemas_invalid(testpath, run_cli):
    """Test define_xml_schemas.main funtion with an invalid schema
    path. An exception should be raised.
    """
    input_file = 'tests/data/non-existing-file.xml'
    arguments = ['--workspace', testpath, '--uri_pairs',
                 'myuri', input_file]

# Path: siptools/scripts/define_xml_schemas.py
# def main(**kwargs):
# def define_schemas(uri_pairs,
#                    base_path='.',
#                    workspace='./workspace/',
#                    stdout=False):
#     def add_premis_md(self, schemas):
#     def write(self, mdtype="PREMIS:OBJECT", mdtypeversion="2.3",
#               othermdtype=None, section=None, stdout=False,
#               file_metadata_dict=None,
#               ref_file="define-xml-schemas-md-references.jsonl"):
# def create_premis_representation(schemas):
# def _check_filepaths(schemas=None, base='.'):
# class PremisCreator(MetsSectionCreator):
#     RETVAL = main()  # pylint: disable=no-value-for-parameter
# 
# Path: siptools/utils.py
# def read_md_references(workspace, ref_file):
#     """Read all the MD IDs as a dictionary.
# 
#     :workspace: path to workspace directory
#     :ref_file: Metadata reference file
#     :returns: A dict of references or None if reference file doesn't
#               exist
#     """
#     reference_file = os.path.join(workspace, ref_file)
# 
#     if os.path.isfile(reference_file):
#         references = {}
#         with open(reference_file) as in_file:
#             for line in in_file:
#                 references.update(json.loads(line))
#         return references
#     return None
# 
# Path: siptools/xml/mets.py
# NAMESPACES = {
#     'mets': 'http://www.loc.gov/METS/',
#     'xsi': 'http://www.w3.org/2001/XMLSchema-instance',
#     'premis': 'info:lc/xmlns/premis-v2',
#     'fi': 'http://digitalpreservation.fi/schemas/mets/fi-extensions',
#     'xlink': 'http://www.w3.org/1999/xlink',
#     'mix': 'http://www.loc.gov/mix/v20',
#     'ead3': 'http://ead3.archivists.org/schema/',
#     'addml': 'http://www.arkivverket.no/standarder/addml',
#     'audiomd': 'http://www.loc.gov/audioMD/',
#     'videomd': 'http://www.loc.gov/videoMD/'
# }


# Path: tests/scripts/test_define_xml_schemas.py
import os
import lxml.etree as ET
from siptools.scripts import define_xml_schemas
from siptools.utils import read_md_references
from siptools.xml.mets import NAMESPACES

        assert dependency.xpath(
            './premis:dependencyIdentifier/premis:dependencyIdentifierType',
            namespaces=NAMESPACES)[0].text == id_type


def test_define_xml_schemas_base_path_ok(testpath, run_cli):
    """Test define_xml_schemas.main funtion with valid test data using
    the base_path argument.
    """
    input_file = 'mets_valid_minimal.xml'
    arguments = ['--workspace', testpath, '--uri_pairs',
                 'myuri', input_file,
                 '--base_path', 'tests/data']
    run_cli(define_xml_schemas.main, arguments)

    output = get_amd_file(testpath)
    tree = ET.parse(output[0])
    root = tree.getroot()

    assert len(root.xpath('/mets:mets/mets:amdSec/mets:techMD',
                          namespaces=NAMESPACES)) == 1


def test_define_xml_schemas_invalid(testpath, run_cli):
    """Test define_xml_schemas.main funtion with an invalid schema
    path. An exception should be raised.
    """
    input_file = 'tests/data/non-existing-file.xml'
    arguments = ['--workspace', testpath, '--uri_pairs',
                 'myuri', input_file]

    result = run_cli(define_xml_schemas.main, arguments, success=False)