# Path: siptools/utils.py
# def fsencode_path(filename):
#     """
#     Encode Unicode filenames using the file system encoding.
# 
#     :filename: File path to encode
#     :returns: Encoded path
#     :raises: TypeError if wrong type given
#     """
#     if isinstance(filename, six.text_type):
#         return filename.encode(encoding=sys.getfilesystemencoding())
#     if isinstance(filename, six.binary_type):
#         return filename
# 
#     raise TypeError("Value is not a (byte) string")
# 
# 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


import os.path
import json
import shutil
import pytest
import lxml.etree as ET
import siptools.scripts.create_videomd as create_videomd
from siptools.utils import fsencode_path, read_md_references
    assert os.path.isfile(os.path.join(testpath,
                                       'create-videomd-md-references.jsonl'))

    filepath = os.path.join(
        testpath, '36260c626dac2f82359d7c22ef378392-VideoMD-amd.xml'
    )

    assert os.path.isfile(filepath)


def test_main_utf8_files(testpath, run_cli):
    """Test for ``main`` function with filenames that contain non-ascii
    characters.
    """
    # Create sample data directory with file that has non-ascii characters in
    # filename
    os.makedirs(os.path.join(testpath, 'data'))
    relative_path = os.path.join('data', 'äöå.m1v')
    full_path = os.path.join(testpath, relative_path)
    shutil.copy('tests/data/video/valid_1.m1v', full_path)

    # Call main function with encoded filename as parameter
    run_cli(
        create_videomd.main, [
            '--workspace', testpath, '--base_path', testpath,
            fsencode_path(relative_path)
        ]
    )

    # Check that filename is found in md-reference file.

# Path: siptools/utils.py
# def fsencode_path(filename):
#     """
#     Encode Unicode filenames using the file system encoding.
# 
#     :filename: File path to encode
#     :returns: Encoded path
#     :raises: TypeError if wrong type given
#     """
#     if isinstance(filename, six.text_type):
#         return filename.encode(encoding=sys.getfilesystemencoding())
#     if isinstance(filename, six.binary_type):
#         return filename
# 
#     raise TypeError("Value is not a (byte) string")
# 
# 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: tests/scripts/test_create_videomd.py
import os.path
import json
import shutil
import pytest
import lxml.etree as ET
import siptools.scripts.create_videomd as create_videomd
from siptools.utils import fsencode_path, read_md_references

    assert os.path.isfile(os.path.join(testpath,
                                       'create-videomd-md-references.jsonl'))

    filepath = os.path.join(
        testpath, '36260c626dac2f82359d7c22ef378392-VideoMD-amd.xml'
    )

    assert os.path.isfile(filepath)


def test_main_utf8_files(testpath, run_cli):
    """Test for ``main`` function with filenames that contain non-ascii
    characters.
    """
    # Create sample data directory with file that has non-ascii characters in
    # filename
    os.makedirs(os.path.join(testpath, 'data'))
    relative_path = os.path.join('data', 'äöå.m1v')
    full_path = os.path.join(testpath, relative_path)
    shutil.copy('tests/data/video/valid_1.m1v', full_path)

    # Call main function with encoded filename as parameter
    run_cli(
        create_videomd.main, [
            '--workspace', testpath, '--base_path', testpath,
            fsencode_path(relative_path)
        ]
    )

    # Check that filename is found in md-reference file.

    refs = read_md_references(testpath, 'create-videomd-md-references.jsonl')