-
Notifications
You must be signed in to change notification settings - Fork 123
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
test_link.py: Add more tests and cleanup #211
Conversation
- Drop RANDOM_BBOX and RANDOM_GEOM as they are not important to the methods under test - Just import datetime. Try to stick to importing just modules. - Create an item in setUp - Add test_minimal first the simplest instance creation call - Add a limited test_relative
Codecov Report
@@ Coverage Diff @@
## develop #211 +/- ##
===========================================
+ Coverage 92.32% 92.62% +0.29%
===========================================
Files 28 28
Lines 3349 3375 +26
===========================================
+ Hits 3092 3126 +34
+ Misses 257 249 -8
Continue to review full report at Codecov.
|
Looking at the coverage this way: coverage run --source=pystac/ -m unittest discover tests/ -v -k test_link
coverage report -m | grep link.py I was able to get the missing coverage down to:
With all tests and these changes, these are the only missing lines:
Should I add these tests to this pr? # TODO: Test get_href when href is absolute and there is an owner
# TODO: Test get_absolute_href when there is an owner
# TODO: Test when resolve_stac_object on link when target is a str.
def test_resolve_stac_object_no_root_and_target_is_item(self):
link = pystac.Link('my rel', target=self.item)
link.resolve_stac_object()
class StaticLinkTest(unittest.TestCase):
def test_from_dict_round_trip(self):
test_cases = [
{'rel': '', 'href': ''}, # Not valid, but works.
{'rel': 'r', 'href': 't'},
{'rel': 'r', 'href': '/t'},
{'rel': 'r', 'href': 't', 'type': 'a/b', 'title': 't', 'c': 'd', 1: 2},
{'rel': 'self', 'href': 't'}, # Special case.
]
for d in test_cases:
d2 = pystac.Link.from_dict(d).to_dict()
self.assertEqual(d, d2)
def test_from_dict_link_type(self):
test_cases = [
({'rel': '', 'href': 'https://a'}, pystac.LinkType.ABSOLUTE),
({'rel': '', 'href': '/a'}, pystac.LinkType.ABSOLUTE),
({'rel': '', 'href': 'a'}, pystac.LinkType.RELATIVE),
({'rel': '', 'href': './a'}, pystac.LinkType.RELATIVE),
# 'self' is a special case.
({'rel': 'self', 'href': 'does not matter'}, pystac.LinkType.ABSOLUTE),
]
for case in test_cases:
item = pystac.Link.from_dict(case[0])
self.assertEqual(case[1], item.link_type)
def test_from_dict_failures(self):
for d in [{}, {'href': 't'}, {'rel': 'r'}]:
with self.assertRaises(KeyError):
pystac.Link.from_dict(d)
for d in [{'rel': '', 'href': 1}, {'rel': '', 'href': None},]:
with self.assertRaises(AttributeError):
pystac.Link.from_dict(d)
def test_collection(self):
c = pystac.Collection('collection id', 'desc', extent=None)
link = pystac.Link.collection(c)
expected = {'rel': 'collection', 'href': None, 'type': 'application/json'}
self.assertEqual(expected, link.to_dict())
def test_child(self):
c = pystac.Collection('collection id', 'desc', extent=None)
link = pystac.Link.child(c)
expected = {'rel': 'child', 'href': None, 'type': 'application/json'}
self.assertEqual(expected, link.to_dict()) This boils now to how important it is to have unittests for the module cover the module. I appreciate tests that get right to the heart of trouble when things break, but it is a bit more testing code to have around. Head is currently showing:
|
- Add TODO for lines not covered by test_link.py - Add StaticLinkTest class without setUp
Went ahead with cleaning up and adding the rest of the tests that I wrote. |
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 are a few TODOs in the code; based on your last comment it seems like these might be left over?
In general I think we should prefer Issues to code TODOs.
Also, if there's TODO's left for the PR, it's best to put the PR in the "Draft" state. Sometimes I'll put a checklist of TODOs in the PR description that I can check off as I accomplish tasks, and after I'm ready to move the PR out of Draft phase, remove the TODO list from the description.
Made stac-utils#218 to track them.
Make #218. Sorry about all the confusion. I appreciate the github pointers. I think this PR is now ready. |
RANDOM_BBOX
andRANDOM_GEOM
as they are not important to themethods under test
datetime
. Try to stick to importing just modules.setUp
test_minimal
with the simplest instance creation calltest_relative
#155