Skip to content
This repository has been archived by the owner on Nov 17, 2022. It is now read-only.

Refactor resources tests - integrate versions and improve test coverage #297

Merged
merged 64 commits into from
Mar 22, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
8c1004d
Test that test data for various versions are being detected
hayfield Nov 28, 2017
9c7999b
Merge branch 'improve-version-parameter' into 218ify-resource-version…
hayfield Nov 29, 2017
86e2332
Add a fixture for specifying all standard versions, or independent
hayfield Dec 19, 2017
9af9dea
Test the creation of Codelist resource paths
hayfield Dec 19, 2017
351a74d
Rename a function
hayfield Dec 19, 2017
e9a4d71
Add a fixture to actually provide all versions of the IATI Standard
hayfield Dec 19, 2017
c3d8be0
Remove an 'X' from a class name
hayfield Dec 19, 2017
fb4f9b1
Move a create_x_path function to new class
hayfield Dec 19, 2017
8b03b82
Merge branch 'minor-versions-constant' into 218ify-resource-create-x-…
hayfield Dec 19, 2017
3c72578
Test the creation of Codelist Mapping file resource paths
hayfield Dec 19, 2017
ceef8a5
Fuzz the finding of a Codelist Mapping File path
hayfield Dec 19, 2017
71110b5
Test that creation of Codelist paths raises relevant errors
hayfield Dec 19, 2017
85499b8
Merge branch '218ify-resource-create-x-path' into 'improve-resource-v…
hayfield Feb 28, 2018
7cad2b5
Make resources tests pass
hayfield Feb 28, 2018
a4b219b
Update documentation for permitted version arg values
hayfield Feb 28, 2018
82d3491
Merge branch 'improve-version-parameter' into 'improve-resource-versi…
hayfield Mar 7, 2018
db320ed
Merge branch 'prevent-decimal-attr-error' into 'improve-resource-vers…
hayfield Mar 7, 2018
bea658c
Merge branch 'prevent-decimal-attr-error' into improve-resource-versi…
hayfield Mar 8, 2018
1cf576b
Merge branch 'improve-version-parameter' into improve-resource-versio…
hayfield Mar 8, 2018
2a28686
Improve testing of requesting Codelist Mapping resources
hayfield Mar 8, 2018
01b403d
Fix decimalisation of invalid major versions
hayfield Mar 8, 2018
be2965a
Merge branch 'improve-version-parameter' into 'improve-resource-versi…
hayfield Mar 9, 2018
a3f8112
Actually save a file between resolving a merge conflict and committing
hayfield Mar 9, 2018
f12a6c0
Merge branch 'improve-version-parameter' into refactor-resources-tests
hayfield Mar 9, 2018
263ff3a
Start full redesign of the resource module tests
hayfield Mar 9, 2018
c0292a3
Fix a docstring to refer to the correct variable name.
hayfield Mar 13, 2018
dd15e9f
Test the resources folder_name_for_version function
hayfield Mar 13, 2018
032af8e
Test resource function folder_path_for_version
hayfield Mar 13, 2018
cfd1c48
Test the resource path_for_version function
hayfield Mar 13, 2018
c1e4e13
Merge branch 'improve-version-parameter' into refactor-resources-tests
hayfield Mar 13, 2018
dc51880
Provide improved checks on input paths
hayfield Mar 13, 2018
2069da2
Re-order tests in test_resources
hayfield Mar 13, 2018
e5312c2
Test creation of paths to Ruleset resources
hayfield Mar 14, 2018
bada482
Remove a now-incorrect docstring statement.
hayfield Mar 14, 2018
ca6d35c
Test creation of paths for Schema resources
hayfield Mar 14, 2018
21f12b8
Make use of a named tuple to increase test clarity
hayfield Mar 14, 2018
d15f7dd
More thoroughly test iati.resources.get_ruleset_paths()
hayfield Mar 14, 2018
b46c51c
Merge branch 'improve-version-parameter' into refactor-resources-tests
hayfield Mar 14, 2018
96d9223
Remove a now-redundant test function
hayfield Mar 14, 2018
4019cd7
Test that get_x_path() functions raise errors when given junk values
hayfield Mar 14, 2018
89adb58
Test getting Schema resource paths
hayfield Mar 14, 2018
1442cb5
Integrate the checks from old get_x_schema_paths checks
hayfield Mar 14, 2018
3ab0d49
Migrate create_codelist_mapping tests to new format
hayfield Mar 14, 2018
fd2fb7b
Test get_codelist_mapping_paths in resources
hayfield Mar 14, 2018
33b9eff
Remove default value for version arg on resources.get_x_paths functions
hayfield Mar 14, 2018
8446fec
Update some out-of-date docstrings
hayfield Mar 14, 2018
c15554b
Update changelog with resources changes
hayfield Mar 14, 2018
c34c531
Fix linting errors
hayfield Mar 15, 2018
df07224
Perform some basic docstring improvements
hayfield Mar 15, 2018
244203b
More thoroughly test resources.create_codelist_path()
hayfield Mar 15, 2018
45c52b9
Test that appropraite errors are raised when decorating incorrect fun…
hayfield Mar 15, 2018
9f9f728
standardise -> normalise
hayfield Mar 15, 2018
df13e9f
Test resources get_codelist_paths()
hayfield Mar 15, 2018
c114412
Tidy up some development placeholders
hayfield Mar 15, 2018
b26c2c6
Update documentation for iati.resources.get_codelist_paths()
hayfield Mar 20, 2018
28aece8
Add PR numbers for resource test changelog items
hayfield Mar 20, 2018
7ec75b1
Make test function names match what they are testing
hayfield Mar 20, 2018
37cca6d
Remove default values for resource version args
hayfield Mar 21, 2018
f89e7f8
Remove now False statements from docstrings
hayfield Mar 21, 2018
3782fd2
Add a pylint disable for missing parameter
hayfield Mar 21, 2018
02d1433
Make review changes
hayfield Mar 21, 2018
c880a6e
Add a clarity comment based on review
hayfield Mar 21, 2018
d19a6df
Extract some common version functionality into a function
hayfield Mar 21, 2018
2f62bf9
Test that create_codelist_mapping_path() TypeError-s correctly
hayfield Mar 21, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,23 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a
- [Tests] Separate testing of `bytes` and `str` type values for Python 3+. [#286]
- [Tests] Mark tests requiring updates when adding a new version. [#288]
- [Tests] Add another build stage to check that docs build when merging to dev or master. [#292]
- [Tests] Significantly improve test coverage of the `resources` module. [#297]

### Changed

- [Resources] Change the folder containing version-independent data from `version-independent` to `version_independent` for consistency. [#297]
- [Resources] `create_*_path()` functions will raise errors when given an unknown version. [#297]
- [Resources] `get_*_paths()` functions now verify that paths point to actual files before returning them. [#297]
- [Resources] `get_*_paths()` functions raise errors when given values that cannot represent a version. [#297]

- [Utilities] Raise a TypeError rather than a ValueError when `convert_xml_to_tree()` is given a value of incorrect type. [#286]

### Deprecated

### Removed

- [Resources] Functions in the `resources` module no longer have default values for the `version` argument. [#297]

### Fixed

- [Validation] The `_check_codes()` implementation is no longer fixed to version 2.02. [#291]
Expand Down
2 changes: 1 addition & 1 deletion iati/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ def ruleset_schema():
Determine whether a version should be provided. This is worth considering if the content of the IATI Ruleset Schema varies between versions.

"""
path = iati.resources.create_ruleset_path(iati.resources.FILE_RULESET_SCHEMA_NAME)
path = iati.resources.create_ruleset_path(iati.resources.FILE_RULESET_SCHEMA_NAME, iati.version.STANDARD_VERSION_ANY)
schema_str = iati.utilities.load_as_string(path)

return json.loads(schema_str)
Expand Down
346 changes: 249 additions & 97 deletions iati/resources.py

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion iati/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

pytest_plugins = [ # name required by pytest # pylint: disable=invalid-name
'iati.tests.fixtures.comparison',
'iati.tests.fixtures.filepaths',
'iati.tests.fixtures.versions'
]

Expand All @@ -30,7 +31,9 @@ def pytest_runtest_call(item):
('2.02', 62), # There are 38 embedded codelists at v2.02, plus 24 non-embedded codelists (which are valid for any version)
('2.01', 61), # There are 37 embedded codelists at v2.01, plus 24 non-embedded codelists (which are valid for any version)
('1.05', 59), # There are 35 embedded codelists at v1.05, plus 24 non-embedded codelists (which are valid for any version)
('1.04', 59) # There are 35 embedded codelists at v1.04, plus 24 non-embedded codelists (which are valid for any version)
('1.04', 59), # There are 35 embedded codelists at v1.04, plus 24 non-embedded codelists (which are valid for any version)
('2', 62), # the same as the latest minor within the major
('1', 59) # the same as the latest minor within the major
])
def codelist_lengths_by_version(request): # latest_version fixture used to perform checks when adding new versions # pylint: disable=unused-argument
"""Return a tuple containing versions of the Standard, and the number of Codelists for that version.
Expand Down
57 changes: 57 additions & 0 deletions iati/tests/fixtures/filepaths.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
"""Pytest fixtures for obtaining filepaths."""
import os
import pytest
import iati.tests.utilities


@pytest.fixture(params=[
'filename-no-extension',
'filename-with-extension.ext',
'FilenameMixedCase'
])
def filename_no_meaning(request):
"""Return a filename with no particular meaning."""
return request.param


@pytest.fixture(params=[
'a-single-filename'
])
def filename_no_meaning_single(request):
"""Return a single filename with no particular meaning."""
return request.param


@pytest.fixture(params=iati.tests.utilities.generate_test_types(['str'], True))
def filepath_invalid_type(request):
"""Return a value that is of a type that cannot represent a filepath.

Python2/3 compatibility: Look at using the concept of PathLike that was introduced at 3.4.
"""
return request.param


@pytest.fixture
def filepath_empty():
"""Return a value that is an empty filepath."""
return ''


@pytest.fixture(params=[
' ', # whitespace only
'\ntext-with-newline\n', # newline
os.path.sep * 3 # multiple separators, each with nothing between them
])
def filepath_invalid_value(request):
"""Return a value that is a string that cannot represent a filepath."""
return request.param


@pytest.fixture(params=[
'foldername' + os.path.sep,
'foldername-with-hyphen' + os.path.sep,
'folder' + os.path.sep + 'sub-folder' + os.path.sep
])
def folderpath_no_meaning(request):
"""Return a folder path with no particular meaning. Differs from a filepath in that it contains separators."""
return request.param
78 changes: 75 additions & 3 deletions iati/tests/fixtures/versions.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
* `major` - major / integer versions
* `minor` - minor / decimal versions
* `all` - both major and minor versions
* `any` - both major and minor versions, plus the value that represents every single version
* `independent` - a value that represents every single version
* Instantiation Status
* `inst` - an iati.Version instance
Expand Down Expand Up @@ -237,12 +238,18 @@ def std_ver_minor_uninst_typeerr(request):
return request.param


@pytest.fixture(params=iati.tests.utilities.generate_test_types([], True))
@pytest.fixture(params=MINOR_MIXED_VER_INVALID + MAJOR_INVALID + MAJOR_VALID + iati.tests.utilities.generate_test_types([], True))
def std_ver_minor_uninst_mixederr(request):
"""Return a value that does not represent a minor version number."""
return request.param


@pytest.fixture(params=MINOR_MIXED_VER_INVALID + MAJOR_INVALID)
def std_ver_all_uninst_valueerr(request):
"""Return a value of the correct type to represent a version number, but has an invalid value."""
return request.param


@pytest.fixture(params=iati.tests.utilities.generate_test_types(['str', 'int'], True))
def std_ver_all_uninst_typeerr(request):
"""Return a value of the wrong type to represent a version number.
Expand All @@ -255,6 +262,56 @@ def std_ver_all_uninst_typeerr(request):
return request.param


@pytest.fixture(params=MINOR_MIXED_VER_INVALID + MAJOR_INVALID + iati.tests.utilities.generate_test_types(['int'], True))
def std_ver_all_uninst_mixederr(request):
"""Return a value that does not represent a version number."""
return request.param


@pytest.fixture(params=[
ver.iativer_str for ver in iati.version.STANDARD_VERSIONS_MINOR
] + [
ver.semver_str for ver in iati.version.STANDARD_VERSIONS_MINOR
] + iati.version.STANDARD_VERSIONS_MINOR + [
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This sort of ugly list expansion definitely needs rectifying through use of a function that does it nicely!

iati.version.STANDARD_VERSION_ANY
])
def std_ver_minor_independent_mixedinst_valid_known(request):
"""Return an IATI version number that pyIATI knows to exist, or independent.

Todo:
Add decimal representations where possible.

"""
return request.param


@pytest.fixture(params=[
ver.iativer_str for ver in iati.version.STANDARD_VERSIONS_MINOR
] + [
ver.semver_str for ver in iati.version.STANDARD_VERSIONS_MINOR
] + [
iati.version.STANDARD_VERSION_ANY
] + iati.version.STANDARD_VERSIONS_MINOR + MAJOR_KNOWN)
def std_ver_any_mixedinst_valid_known(request):
"""Return a value that can represent some known version number at any level of granularity.

Todo:
Add decimal representations where possible.

"""
return request.param


@pytest.fixture(params=[
iati.Version(version) for version in MINOR_IATIVER_VALID if not iati.Version(version) in iati.version.STANDARD_VERSIONS_MINOR
] + [
major_version for major_version in MAJOR_VALID if major_version not in MAJOR_KNOWN
])
def std_ver_all_mixedinst_valid_unknown(request):
"""Return a major or minor version of the IATI Standard that is not known by pyIATI to exist."""
return request.param


@pytest.fixture(params=MINOR_DECIMAL_VALID)
def std_ver_minor_uninst_valid_decimal_possible(request):
"""Return a decimal value that is a valid representation of a minor version number."""
Expand Down Expand Up @@ -293,7 +350,7 @@ def std_ver_minor_uninst_valid_possible(request):

@pytest.fixture(params=MINOR_MIXED_VER_INVALID)
def std_ver_minor_uninst_valueerr_str_decimal(request):
"""Return a valid version number in a valid format."""
"""Return an invalid version number in a valid format."""
return request.param


Expand All @@ -312,6 +369,21 @@ def std_ver_minor_uninst_valid_known(request):
return request.param


@pytest.fixture(params=[
ver.iativer_str for ver in iati.version.STANDARD_VERSIONS_MINOR
] + [
ver.semver_str for ver in iati.version.STANDARD_VERSIONS_MINOR
] + iati.version.STANDARD_VERSIONS_MINOR)
def std_ver_minor_mixedinst_valid_known(request):
"""Return an IATI version number that pyIATI knows to exist.

Todo:
Add decimal representations where possible.

"""
return request.param


@pytest.fixture(params=[
ver.iativer_str for ver in iati.version.STANDARD_VERSIONS_SUPPORTED
] + [
Expand Down Expand Up @@ -370,7 +442,7 @@ def std_ver_minor_inst_valid_known(request):
version for version in MINOR_IATIVER_VALID if not iati.Version(version) in iati.version.STANDARD_VERSIONS_MINOR
])
def std_ver_minor_inst_valid_unknown(request):
"""Return a version of the IATI Standard that is not known by pyIATI to exist."""
"""Return a minor version of the IATI Standard that is not known by pyIATI to exist."""
return iati.Version(request.param)


Expand Down
Loading