elifesciences / elife-tools

Python library for parsing eLife article XML data.
MIT License
15 stars 7 forks source link

Refactor tests folder, and tests that compare .json fixture files #311

Closed gnott closed 3 years ago

gnott commented 5 years ago

There are JSON file test fixtures in the project, currently in the elifetools/tests/JSON/ folder. There's a script elifetools/tests/generate_expected_json.py which can be used to help re-generate the fixtures.

Running the generate script (after some modifications) does still generate .json file output, except since the contents of the JSON files are mostly simple dict data, the inconsistent order of the dict keys causes the git diff of the files to vary more than they should to be useful test fixtures. At the very least, the keys of the dict can be sorted alphabetically before saving them as .json files. Alternatively, output as an OrderedDict may help with comparisons.

Comparisons with the file fixtures can compare sorted dicts, or use the assert equal dict-style assertions.

Another couple potential improvements are to move the generate_test_fixtures.py to the root folder of the project, and move the elifetools/tests directory to tests instead.

In summary, some proposed tests refactoring:

gnott commented 5 years ago

May also consider to use OrderedDict as a replacement for all remaining plain old {} dict in the parser. We use OrderedDict regularly when generating some output, and it will probably have little negative speed or usability impacts. @giorgiosironi maybe you have some comments about switching to OrderedDict for older function calls?

gnott commented 3 years ago

In PR https://github.com/elifesciences/elife-tools/pull/356, new test scenarios no longer use the old JSON files, and generate_test_fixtures.py is now removed completely. Test cases and test fixtures are managed in the newer style. This issue can be closed now.