worldbank / GOSTnets

Convenience wrapper for networkx analysis using geospatial information, focusing on OSM
https://worldbank.github.io/GOSTnets/
MIT License
21 stars 15 forks source link

Setup testing #67

Closed elbeejay closed 1 day ago

elbeejay commented 4 months ago

Tests for the GOSTnets package

This PR provides both unit and integrative tests for the GOSTnets package.

In total, this PR includes 91 tests, covering 72% of the codebase (2072 lines of code).

Running the test suite

A new CI workflow (test.yml) was added to automatically run the tests on pushes and pull requests. If desired, we can work to add a "coverage badge" that displays the percentage of code covered by the test suite on the README or something along those lines.

To run the test suite locally, you can follow the instructions in the CI workflow, which are to clone the repository, and then install the [dev] version of the package: pip install .[dev]. Then you can run the test suite with the command pytest. If you are interested in the code coverage, you should use the coverage tool to run pytest: coverage run -m pytest, after the tests run, you can view coverage in the terminal with coverage report, or generate a nice HTML view with coverage html which enables you to look at the specific lines of code covered and not covered by the tests.

Unit Tests

There are 79 "unit" tests that aim to atomically test and validate the performance of individual functions. These tests sometimes involve "mocking" of functions, objects, or data to isolate the functionality of each individual function (in normal use, functions may call each other, or rely on outputs from other functions as their input).

Integrative Tests

There are 12 "integrative" tests that are more similar to example workflows and test the functions on test data. As opposed to the "unit" tests that aim to test each function in isolation, the integrative tests allow functions to call nested functions and so-on, just as they would when the package is being used normally.

Missing Tests

This PR implements tests that call 72% of the lines of code in the GOSTnets package. Lines of code that are untested include:



However given the fact that we've achieved coverage of the majority of code and functionlity, I believe it is reasonable to merge this PR in now. Some of the tests to write in the future will require detailed updates of the functions themselves, which may be best done on a single case-by-case basis to make the review of the PR easier.

This PR already does some minor editing to functions as needed due to deprecation of parameters and other changes in upstream dependencies.

elbeejay commented 1 week ago

It's a pretty big PR so let me know if you'd like me to break it up into smaller PRs or something different to make it more digestible @g4brielvs

g4brielvs commented 6 days ago

@elbeejay Many thanks! I have prioritized and will review it shortly.