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


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

    def test_resource_filename(self):
        """Check that resource file names are found correctly.

        Todo:
            Implement better assertions.

        """
        path = iati.resources.PATH_SCHEMAS
        filename = iati.resources.resource_filename(path)

        assert len(filename) > len(path)
        assert filename.endswith(path)


class TestResourceFolders(object):
    """A container for tests relating to resource folders."""

    @pytest.mark.parametrize('version, expected_version_foldername', [
        ('2.02', '2-02'),
        ('2.01', '2-01'),
        ('1.05', '1-05'),
        ('1.04', '1-04'),
        ('1.03', '1-03'),
        ('1.02', '1-02'),
        ('1.01', '1-01'),
        ('1', '1'),
        ('2', '2'),
        (None, 'version-independent')
    ])
    def test_get_folder_name_for_version(self, expected_version_foldername, version):
        """Check that expected components are present within folder paths."""
        path = iati.resources.get_folder_name_for_version(version)

        assert expected_version_foldername == path

    @pytest.mark.parametrize('version', [
        '1.00',
        1,
        1.01,  # A version 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.resources.get_folder_name_for_version(version)

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

    def test_get_test_data_paths_in_folder(self):
        """Check that test data is being found in specified subfolders.

        Todo:
            Deal with multiple versions.

        """
        paths = iati.tests.resources.get_test_data_paths_in_folder('ssot-activity-xml-fail', '2.02')

        assert len(paths) == 237


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

    @pytest.mark.parametrize('file_name', [
        'name',
        'Name.xml',
    ])
    def test_get_lib_data_path(self, file_name):
        """Check that library data can be located."""
        path = iati.resources.get_lib_data_path(file_name)
<commit_msg>Test that test data for various versions are being detected<commit_after>"""A module containing tests for the library implementation of accessing resources."""
from lxml import etree
import pytest
import iati.constants
import iati.resources
import iati.validator
import iati.tests.resources


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

    def test_resource_filename(self):
        """Check that resource file names are found correctly.

        Todo:
            Implement better assertions.

        """
        path = iati.resources.PATH_SCHEMAS
        filename = iati.resources.resource_filename(path)

        assert len(filename) > len(path)
        assert filename.endswith(path)


class TestResourceFolders(object):
    """A container for tests relating to resource folders."""

    @pytest.mark.parametrize('version, expected_version_foldername', [
        ('2.02', '2-02'),
        ('2.01', '2-01'),
        ('1.05', '1-05'),
        ('1.04', '1-04'),
        ('1.03', '1-03'),
        ('1.02', '1-02'),
        ('1.01', '1-01'),
        ('1', '1'),
        ('2', '2'),
        (None, 'version-independent')
    ])
    def test_get_folder_name_for_version(self, expected_version_foldername, version):
        """Check that expected components are present within folder paths."""
        path = iati.resources.get_folder_name_for_version(version)

        assert expected_version_foldername == path

    @pytest.mark.parametrize('version', [
        '1.00',
        1,
        1.01,  # A version 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.resources.get_folder_name_for_version(version)

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

    @pytest.mark.parametrize('version, expected_num_paths', [
        ('2.02', 237),
        ('2.01', 217),
        ('1.05', 17),
        ('1.04', 17),
        ('1.03', 17),
        ('1.02', 17),
        ('1.01', 16),
        ('1', 0),
        ('2', 0),
        (None, 0)
    ])
    def test_get_test_data_paths_in_folder(self, version, expected_num_paths):
        """Check that test data is being found in specified subfolders.

        Look for the number of paths in the `ssot-activity-xml-fail` folder.
        """
        paths = iati.tests.resources.get_test_data_paths_in_folder('ssot-activity-xml-fail', version)

        assert len(paths) == expected_num_paths


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

    @pytest.mark.parametrize('file_name', [
        'name',
        'Name.xml',
    ])
    def test_get_lib_data_path(self, file_name):
        """Check that library data can be located."""
        path = iati.resources.get_lib_data_path(file_name)

{'fraction_non_alphanumeric': 0.11955289162481776, 'fraction_numerical': 0.02494735136886441, 'mean_word_length': 2.8611632270168856, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 7}, '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': '1853113', 'n_tokens_mistral': 1891, 'n_tokens_neox': 1815, 'n_words': 456}