Skip to content

Improve coverage checks #466

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

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
[report]
fail_under = 91
fail_under = 93
exclude_lines =
if TYPE_CHECKING:


[run]
source = pystac
branch = true
source =
pystac
tests
2 changes: 1 addition & 1 deletion pystac/extensions/sar.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ def ext(cls, obj: T, add_if_missing: bool = False) -> "SarExtension[T]":
return cast(SarExtension[T], AssetSarExtension(obj))
else:
raise pystac.ExtensionTypeError(
f"SAR extension does not apply to type {type(obj)}"
f"SAR extension does not apply to type '{type(obj).__name__}'"
Copy link
Contributor

@duckontheweb duckontheweb Jun 27, 2021

Choose a reason for hiding this comment

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

It looks like this change could be made for a number of other extensions as well. Is there a reason to only change this for the sar and view extensions, or should we update the ext method for all extensions in this PR?

Copy link
Contributor Author

@l0b0 l0b0 Jun 29, 2021

Choose a reason for hiding this comment

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

I can do that, but I'd need to be sure that you're OK with changing all of them so it's not wasted effort. What do you think?

I could also pull these changes into a separate PR if that helps.

)


Expand Down
2 changes: 1 addition & 1 deletion pystac/extensions/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ def ext(cls, obj: T, add_if_missing: bool = False) -> "ViewExtension[T]":
return cast(ViewExtension[T], AssetViewExtension(obj))
else:
raise pystac.ExtensionTypeError(
f"View extension does not apply to type {type(obj)}"
f"View extension does not apply to type '{type(obj).__name__}'"
)

@staticmethod
Expand Down
2 changes: 1 addition & 1 deletion scripts/test
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ echo " -- RUNNING UNIT TESTS --"
echo

# Test suite with coverage enabled
coverage run --source=pystac/ -m unittest discover tests/
coverage run -m unittest discover tests
coverage xml
24 changes: 24 additions & 0 deletions tests/extensions/test_sar.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
"""Tests for pystac.extensions.sar."""

import datetime
from random import choice
from typing import List
import unittest

from string import ascii_letters

import pystac
from pystac import ExtensionTypeError
from pystac.extensions import sar
from pystac.extensions.sar import SarExtension
from tests.utils import TestCases
Expand Down Expand Up @@ -180,6 +184,26 @@ def test_asset_ext_add_to(self) -> None:

self.assertIn(SarExtension.get_schema_uri(), item.stac_extensions)

def test_should_return_none_when_observation_direction_is_not_set(self) -> None:
extension = SarExtension.ext(self.item)
extension.apply(
choice(ascii_letters),
choice(list(sar.FrequencyBand)),
[],
choice(ascii_letters),
)
self.assertIsNone(extension.observation_direction)

def test_should_raise_exception_when_passing_invalid_extension_object(
self,
) -> None:
self.assertRaisesRegex(
ExtensionTypeError,
r"^SAR extension does not apply to type 'object'$",
SarExtension.ext,
object(),
)


if __name__ == "__main__":
unittest.main()
14 changes: 13 additions & 1 deletion tests/extensions/test_view.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import json

from pystac import ExtensionTypeError
from pystac.collection import Collection
import unittest

Expand Down Expand Up @@ -257,8 +259,18 @@ def test_asset_ext_add_to(self) -> None:

self.assertIn(ViewExtension.get_schema_uri(), item.stac_extensions)

def test_should_raise_exception_when_passing_invalid_extension_object(
self,
) -> None:
self.assertRaisesRegex(
ExtensionTypeError,
r"^View extension does not apply to type 'object'$",
ViewExtension.ext,
object(),
)


class ViewSummariestest(unittest.TestCase):
class ViewSummariesTest(unittest.TestCase):
def setUp(self) -> None:
self.maxDiff = None
example_uri = TestCases.get_path(
Expand Down
2 changes: 1 addition & 1 deletion tests/test_catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -939,7 +939,7 @@ def test_collections_cache_correctly(self) -> None:

def test_reading_iterating_and_writing_works_as_expected(self) -> None:
"""Test case to cover issue #88"""
stac_uri = "tests/data-files/catalogs/test-case-6/catalog.json"
stac_uri = TestCases.get_path("data-files/catalogs/test-case-6/catalog.json")
cat = Catalog.from_file(stac_uri)

# Iterate over the items. This was causing failure in
Expand Down
8 changes: 7 additions & 1 deletion tests/test_item_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
import json
from pystac.item_collection import ItemCollection
import unittest
from os.path import relpath

import pystac

from tests.utils import TestCases
Expand Down Expand Up @@ -101,7 +103,11 @@ def test_raise_error_for_invalid_object(self) -> None:

def test_from_relative_path(self) -> None:
_ = pystac.ItemCollection.from_file(
"./tests/data-files/item-collection/sample-item-collection.json"
relpath(
TestCases.get_path(
"data-files/item-collection/sample-item-collection.json"
)
)
)

def test_from_list_of_dicts(self) -> None:
Expand Down
5 changes: 4 additions & 1 deletion tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from pystac import utils

from pystac.utils import make_relative_href, make_absolute_href, is_absolute_href
from tests.utils import TestCases


class UtilsTest(unittest.TestCase):
Expand Down Expand Up @@ -273,7 +274,9 @@ def test_datetime_to_str(self) -> None:

def test_geojson_bbox(self) -> None:
# Use sample Geojson from https://en.wikipedia.org/wiki/GeoJSON
with open("tests/data-files/geojson/sample.geojson") as sample_geojson:
with open(
TestCases.get_path("data-files/geojson/sample.geojson")
) as sample_geojson:
all_features = json.load(sample_geojson)
geom_dicts = [f["geometry"] for f in all_features["features"]]
for geom in geom_dicts:
Expand Down