-
Notifications
You must be signed in to change notification settings - Fork 5
Refactor resources tests - integrate versions and improve test coverage #297
Refactor resources tests - integrate versions and improve test coverage #297
Conversation
This is required for the completion of some things in #255
A fixture is removed following a mis-remembering of how 'version-independent' works.
The name was longer than needed following previous iterations of the name
This includes: - decimal - integer - version-independent
This makes it clearer that the class works with creating paths, rather than XPaths (which are something completely different...)
This brings it in line with #255
This is the minimal amount of change required to make the tests pass. This should very much not be deemed a final implementation - there is a lot of messy type checking. Refactoring of code in this commit should definitely be undertaken.
Strings consisting of whitespace and numbers were being decimalised. This is not desired since the value does not represent an integer. This improves the testing so that these values are not decimalised.
This is a process starting with the lowest level components, and building up to the larger components. Since the resources module was originally created, it has been redesigned multiple times. Across this period, the tests have not been rearchitectured. This process will turn the resource tests into a state that works for the current module state, rather than that from a year ago.
This provides better bounds on what permitted values are, in turn enabling some simplification of the matching algorithm. The name of the version_independent folder has been changed so that it matches the regex that has been set for resource folder names.
This tests valid and invalid inputs, while also adding an extra check over the previous implementation.
The includes both valid and invalid paths and versions. A couple of changes and tests have needed adding to improve correctness of functions that return components of this path.
The general functionality is as-per Rulesets and Schemas. The one difference is around major versions, where they remain as majors rather than being converted to minors.
…ctions The version decorators require that the decorated function has a version argument. When the input function takes no parameters, an IndexError was being raised. This makes it more appropraite, a TypeError.
The improving of wrapper names did not account for this change
This adds more thorough testing for obtaining lists of Codelist paths. The current situation doesn't allow differentiation between types of Codelist - at the moment Embedded and Non-Embedded. This should be investigated fully once a decision in this area has been made.
Now that the entire file has been refactored, the marks that differentiate new and old tests can be removed.
"""Find the paths for all Codelists at the specified version of the Standard. | ||
|
||
Args: | ||
version (str): The version of the Standard to return the Codelists for. Defaults to iati.version.STANDARD_VERSION_ANY. | ||
version (str / int / Decimal / iati.Version): The version of the Standard to return the Codelists for. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we need to be clear that this returns paths to embedded and non-embedded codelists. I had to run it to be sure!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding comments as a I go...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
More comments
iati/resources.py
Outdated
version (str / int / Decimal / iati.Version): The version of the Standard to return the Codelists for. | ||
Decimal: Return paths for the specified version of the Standard. | ||
Integer: Return paths for the latest Decimal version within the given integer. | ||
Version-independent: Return paths for Non-Embedded Codelists. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wrt to version independent info, is this expected?
>>> iati.resources.get_codelist_paths(iati.version.STANDARD_VERSION_ANY)
[]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is... not the documented behaviour!
There are a couple of issues around the naming of the folder containing NE Codelists (being codelists_non_embedded/
rather than version_independent/codelists/
) and the default
module currently expecting an empty array.
I'd suggest that management and handling of NE Codelists should be looked at as standalone Issue (with this particular docstring being updated to reflect the current behaviour).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
...the problem with default
is due to STANDARD_VERSION_ANY
being added as a thing after it was tested, so there not being any tests against this value (so it's deem to not be a permitted value at all!)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
iati/resources.py
Outdated
|
||
Returns: | ||
list(str): A list of paths to all of the Codelists at the specified version of the Standard. | ||
|
||
Todo: | ||
Further exploration needs to be undertaken in how to handle pre-1.04 versions of the Standard. | ||
Look to provide an argument that allows the returned list to be restricted to only Embedded or only Non-Embedded Codelists. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
parameter that is embedded=True
or non_embedded=True
???
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding functionality along these lines is out of scope for this PR so will need to be designed and undertaken separately.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is desired that there is a way to return only NE-Codelist paths. This is yet to be implemented and should be undertaken as a slightly wider task of looking into keeping track of how different Codelists are managed.
#308 turns the TODOs about improving the distinction between Embedded and Non-Embedded Codelists (as noted in review comments) into an Issue. |
A PR now exists, so the number can be added
The previous names were inconsistent with others in the same class, and did not match the name of the function they were testing. The new names are consistent and match.
A number of functions in the resources module still had default values for the version argument. Explicit is better than implicit. As such, the default values have been removed and tests added to ensure TypeErrors are raised as appropriate. It was documented in the changelog that this was already the case, though the removal of defaults had only been undertaken for some functions.
37cca6d updated code without updating the docstrings. This updates the docstrings.
There are tests checking that there is no default value. As such, there being no parameter shouldn't be a linting error.
return 'version-independent' | ||
elif isinstance(version, str): | ||
return PATH_VERSION_INDEPENDENT | ||
elif isinstance(version, (str, int)) and not isinstance(version, bool): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggest add todo docstring to note that this logic is necessary given lack of functionality such as Version.is_major
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
iati/version.py
Outdated
@@ -355,7 +364,12 @@ def decimalise_integer(input_func): | |||
""" | |||
def wrap_decimalise_integer(*args, **kwargs): | |||
"""Act as a wrapper to convert input Integer Version numbers to a normalised format Decimal Version.""" | |||
version = _decimalise_integer(args[0]) | |||
try: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extract to version = _extract_argument(args, arg_idx=0)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A number of small changes made while reviewing the resources code from top to bottom.
Change as requested in: #297 (review)
Some code was repeated many times. That was bad. It is now in a function. This is less bad.
There were previously no tests for this. There are now tests for this.
iati/tests/test_resources.py
Outdated
@pytest.mark.parametrize('path_component', [ | ||
'resources', | ||
'standard' | ||
class TestResourcePathCreationCodelistMapping(object): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ensure that there are typeerror and junnk value tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comments from the code review addressed, so approving...
Make sweeping and wide-ranging improvements to tests of the
resources
module.The two key purposes of these changes are:
resources
functions handle versions as expected