Skip to content

Core test#59

Merged
vgro merged 12 commits intodevelopfrom
core-test
Aug 22, 2022
Merged

Core test#59
vgro merged 12 commits intodevelopfrom
core-test

Conversation

@vgro
Copy link
Copy Markdown
Collaborator

@vgro vgro commented Aug 12, 2022

Description

Added tests for CoreGrid constructor, make_square_grid, and make_hex_grid functions in core.py.

Fixes #31 (partly)

Type of change

  • New feature (non-breaking change which adds functionality)
  • Optimization (back-end change that speeds up the code)
  • Bug fix (non-breaking change which fixes an issue)

Key checklist

  • Make sure you've run the pre-commit checks: $ pre-commit run -a
  • All tests pass: $ poetry run pytest

Further checks

  • Code is commented, particularly in hard-to-understand areas
  • Tests added that prove fix is effective or that feature works

Comment thread tests/test_grid.py Outdated
@jacobcook1995
Copy link
Copy Markdown
Collaborator

jacobcook1995 commented Aug 12, 2022

It seems like you are falling foul of flake8's doctoring checks, so it isn't passing CI. Me and David turned off doc string checks for tests in safedata_validator, with the logic that tests are not public functions. I don't know if this is good/best practice though?

Comment thread tests/test_grid.py Outdated
@alexdewar
Copy link
Copy Markdown
Collaborator

@jacobcook1995 I think there are two problems here: one is that of missing docstrings, the other is of malformed docstrings. You might want to disable the former for tests (though personally I wouldn't -- you really should have a comments saying what each of your tests do anyway, so why not just make them docstrings?) but I think malformed docstrings are a code style problem like any other and should just be fixed.

Most of the "public" functions you have won't really be used by end users anyway, but it's still worth having docstrings for them as internal documentation. Same applies to tests.

Comment thread tests/test_grid.py Outdated
Comment thread tests/test_grid.py Outdated
Comment thread tests/test_grid.py Outdated
@alexdewar
Copy link
Copy Markdown
Collaborator

alexdewar commented Aug 12, 2022

It looks like the tests are failing on the CI system because scipy is not being installed (though presumably it is installed on your local machine) because it's missing from your project dependencies.

You need to run poetry add scipy and commit the result.

Comment thread tests/test_grid.py Outdated
assert distance == pytest.approx(distance2)

# check angle between corner points is the same
from math import atan2, degrees, pi
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

A simpler approach would be to calculate the inner product of the two segments and check if it is zero. So, if AB and AC are numpy arrays that go from point A to B and point A to C respectively, then they will form a ±90 deg angle if:

assert np.inner(AB, AC) == pytest.approx(0)

If you need specifically the angle (which you do for the hexagonal one), you can follow an approach like this: https://www.atqed.com/numpy-vector-angle

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I replaced the initial checks for angles with this approach, thanks for the suggestion

Comment thread tests/test_grid.py
@codecov-commenter
Copy link
Copy Markdown

Codecov Report

Merging #59 (86088fb) into develop (f29248b) will increase coverage by 75.86%.
The diff coverage is n/a.

@@             Coverage Diff              @@
##           develop      #59       +/-   ##
============================================
+ Coverage     0.00%   75.86%   +75.86%     
============================================
  Files            3        3               
  Lines           58       58               
============================================
+ Hits             0       44       +44     
+ Misses          58       14       -44     
Impacted Files Coverage Δ
virtual_rainforest/core/grid.py 75.92% <0.00%> (+75.92%) ⬆️
virtual_rainforest/__init__.py 100.00% <0.00%> (+100.00%) ⬆️

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@vgro vgro merged commit 6666069 into develop Aug 22, 2022
@vgro vgro deleted the core-test branch August 22, 2022 08:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add tests for functions/methods in grid.py

5 participants