<commit_before>"""A module containing tests for the library implementation of accessing resources."""
from lxml import etree
import pytest
from six import string_types
import iati.core.resources


class TestResources(object):
    """A container for tests relating to resources."""

    @pytest.mark.parametrize('version, expected_version_foldername', [
        ('2.02', '202')
    ])
    def test_get_folder_name_for_version(self, version, expected_version_foldername):
        """Check that expected components are present within folder paths."""
        path = iati.core.resources.get_folder_name_for_version(version)
        assert expected_version_foldername == path

    @pytest.mark.parametrize('version', [
        '1.00',
        '1',
        1,
        1.01,  # A verion must be specified as a string
        'string'
    ])
    def test_get_folder_name_for_version_invalid_version(self, version):
        """Check that an invalid version of the Standard raises a ValueError exception."""
        with pytest.raises(ValueError):
            iati.core.resources.get_folder_name_for_version(version)

    @pytest.mark.parametrize('version', [
        '2.02',
    ])
    @pytest.mark.parametrize('path_component', [
        'resources',
        'standard'
    ])
    def test_get_folder_path_for_version(self, version, path_component):
        """Check that expected components are present within folder paths."""
        path = iati.core.resources.get_folder_path_for_version(version)
        assert path_component in path

    def test_codelist_flow_type(self):
        """Check that the FlowType codelist contains content."""
        path = iati.core.resources.get_codelist_path('FlowType')

        content = iati.core.resources.load_as_string(path)

        assert len(content) > 3200

    def test_find_codelist_paths(self):
        """Check that all codelist paths are being found.

        Todo:
            Add other tests relating to specific versions of the Standard.

        """
        paths = iati.core.resources.find_all_codelist_paths()

        assert len(paths) == 62
        for path in paths:
            assert path[-4:] == iati.core.resources.FILE_CODELIST_EXTENSION
            assert iati.core.resources.PATH_CODELISTS in path

    def test_find_schema_paths(self):
        """Check that all schema paths are being found.

        Todo:
            Add other tests relating to specific versions of the Standard.

            Handle all paths to schemas being found correctly.

        """
        paths = iati.core.resources.find_all_schema_paths()

        assert len(paths) == 1
        for path in paths:
            assert path[-4:] == iati.core.resources.FILE_SCHEMA_EXTENSION

    @pytest.mark.parametrize('codelist', [
        'Name',
        'Name.xml',
    ])
    def test_get_codelist_path_name(self, codelist):
        """Check that a codelist path is found from just a name."""
        path = iati.core.resources.get_codelist_path(codelist)

        assert path[-4:] == iati.core.resources.FILE_CODELIST_EXTENSION
        assert path.count(iati.core.resources.FILE_CODELIST_EXTENSION) == 1
        assert iati.core.resources.PATH_CODELISTS in path

    def test_load_as_bytes(self):
        """Test that resources.load_as_bytes returns a bytes object with the expected content."""
        path_test_data = iati.core.resources.get_test_data_path('invalid')

        result = iati.core.resources.load_as_bytes(path_test_data)

        assert isinstance(result, bytes)
        assert result == 'This is a string that is not valid XML\n'.encode()

    def test_load_as_string(self):
        """Test that resources.load_as_string returns a string (python3) or unicode (python2) object with the expected content."""
        path_test_data = iati.core.resources.get_test_data_path('invalid')

        result = iati.core.resources.load_as_string(path_test_data)

        assert isinstance(result, string_types)
        assert result == 'This is a string that is not valid XML\n'

    def test_resource_filename(self):<commit_msg>Reference six explicitly when using the module<commit_after>"""A module containing tests for the library implementation of accessing resources."""
from lxml import etree
import pytest
import six
import iati.core.resources


class TestResources(object):
    """A container for tests relating to resources."""

    @pytest.mark.parametrize('version, expected_version_foldername', [
        ('2.02', '202')
    ])
    def test_get_folder_name_for_version(self, version, expected_version_foldername):
        """Check that expected components are present within folder paths."""
        path = iati.core.resources.get_folder_name_for_version(version)
        assert expected_version_foldername == path

    @pytest.mark.parametrize('version', [
        '1.00',
        '1',
        1,
        1.01,  # A verion must be specified as a string
        'string'
    ])
    def test_get_folder_name_for_version_invalid_version(self, version):
        """Check that an invalid version of the Standard raises a ValueError exception."""
        with pytest.raises(ValueError):
            iati.core.resources.get_folder_name_for_version(version)

    @pytest.mark.parametrize('version', [
        '2.02',
    ])
    @pytest.mark.parametrize('path_component', [
        'resources',
        'standard'
    ])
    def test_get_folder_path_for_version(self, version, path_component):
        """Check that expected components are present within folder paths."""
        path = iati.core.resources.get_folder_path_for_version(version)
        assert path_component in path

    def test_codelist_flow_type(self):
        """Check that the FlowType codelist contains content."""
        path = iati.core.resources.get_codelist_path('FlowType')

        content = iati.core.resources.load_as_string(path)

        assert len(content) > 3200

    def test_find_codelist_paths(self):
        """Check that all codelist paths are being found.

        Todo:
            Add other tests relating to specific versions of the Standard.

        """
        paths = iati.core.resources.find_all_codelist_paths()

        assert len(paths) == 62
        for path in paths:
            assert path[-4:] == iati.core.resources.FILE_CODELIST_EXTENSION
            assert iati.core.resources.PATH_CODELISTS in path

    def test_find_schema_paths(self):
        """Check that all schema paths are being found.

        Todo:
            Add other tests relating to specific versions of the Standard.

            Handle all paths to schemas being found correctly.

        """
        paths = iati.core.resources.find_all_schema_paths()

        assert len(paths) == 1
        for path in paths:
            assert path[-4:] == iati.core.resources.FILE_SCHEMA_EXTENSION

    @pytest.mark.parametrize('codelist', [
        'Name',
        'Name.xml',
    ])
    def test_get_codelist_path_name(self, codelist):
        """Check that a codelist path is found from just a name."""
        path = iati.core.resources.get_codelist_path(codelist)

        assert path[-4:] == iati.core.resources.FILE_CODELIST_EXTENSION
        assert path.count(iati.core.resources.FILE_CODELIST_EXTENSION) == 1
        assert iati.core.resources.PATH_CODELISTS in path

    def test_load_as_bytes(self):
        """Test that resources.load_as_bytes returns a bytes object with the expected content."""
        path_test_data = iati.core.resources.get_test_data_path('invalid')

        result = iati.core.resources.load_as_bytes(path_test_data)

        assert isinstance(result, bytes)
        assert result == 'This is a string that is not valid XML\n'.encode()

    def test_load_as_string(self):
        """Test that resources.load_as_string returns a string (python3) or unicode (python2) object with the expected content."""
        path_test_data = iati.core.resources.get_test_data_path('invalid')

        result = iati.core.resources.load_as_string(path_test_data)

        assert isinstance(result, six.string_types)
        assert result == 'This is a string that is not valid XML\n'

    def test_resource_filename(self):
{'fraction_non_alphanumeric': 0.09242666012028967, 'fraction_numerical': 0.007364674113170492, 'mean_word_length': 2.966893865628043, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '106310', 'n_tokens_mistral': 2399, 'n_tokens_neox': 2310, 'n_words': 605}