Skip to content
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: add pytest missing plugins #639

Merged
merged 3 commits into from
Dec 11, 2022
Merged
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
12 changes: 7 additions & 5 deletions .github/workflows/unit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,17 +72,19 @@ jobs:
assert len(unexpected) == 0

- name: test with pytest
run: coverage run -m pytest --color=yes --instafail tests
run: pytest --color=yes --cov --cov-report=xml --instafail tests

- name: assess dead fixtures
if: matrix.python-version == '3.8'
run: pytest --dead-fixtures

- name: build the template panel application
if: matrix.python-version == '3.8'
run: |
pytest --nbmake sepal_ui/templates/panel_app/ui.ipynb
run: pytest --nbmake sepal_ui/templates/panel_app/ui.ipynb

- name: build the template map application
if: matrix.python-version == '3.8'
run: |
pytest --nbmake sepal_ui/templates/map_app/ui.ipynb
run: pytest --nbmake sepal_ui/templates/map_app/ui.ipynb

- name: coverage
run: coverage xml
Expand Down
2 changes: 2 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ def get_templates():
"pytest-sugar",
"pytest-icdiff",
"pytest-instafail",
"pytest-deadfixtures",
"pytest-cov",
"nbmake ",
],
"doc": [
Expand Down
35 changes: 21 additions & 14 deletions tests/test_PlanetModel.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,17 @@

@pytest.mark.skipif("PLANET_API_KEY" not in os.environ, reason="requires Planet")
class TestPlanetModel:
@pytest.mark.parametrize("credentials", ["planet_key", "cred"])
def test_init(self, credentials, request):
def test_init(self, planet_key, cred, request):

# Test with a valid api key
planet_model = PlanetModel(planet_key)

assert isinstance(planet_model, PlanetModel)
assert isinstance(planet_model.session, planet.http.Session)
assert planet_model.active is True

# Test with a valid api key and login credentials
planet_model = PlanetModel(request.getfixturevalue(credentials))
# Test with a valid login credentials
planet_model = PlanetModel(cred)

assert isinstance(planet_model, PlanetModel)
assert isinstance(planet_model.session, planet.http.Session)
Expand Down Expand Up @@ -56,10 +62,7 @@ def test_init_session_from_event(self):

return

def test_is_active(self, planet_key):

# We only need to test with a key.
planet_model = PlanetModel(planet_key)
def test_is_active(self, planet_model):

planet_model._is_active()
assert planet_model.active is True
Expand All @@ -69,9 +72,8 @@ def test_is_active(self, planet_key):

return

def test_get_subscriptions(self, planet_key):
def test_get_subscriptions(self, planet_model):

planet_model = PlanetModel(planet_key)
subs = planet_model.get_subscriptions()

# Check object has length, because there is no way to check a value
Expand All @@ -80,10 +82,7 @@ def test_get_subscriptions(self, planet_key):

return

def test_get_planet_items(self, planet_key):

# Arrange
planet_model = PlanetModel(planet_key)
def test_get_planet_items(self, planet_model):

aoi = { # Yasuni national park in Ecuador
"type": "Polygon",
Expand Down Expand Up @@ -119,3 +118,11 @@ def cred(self):
credentials = json.loads(os.getenv("PLANET_API_CREDENTIALS"))

return list(credentials.values())

@pytest.fixture
def planet_model(self):
"""Start a planet model using the API key"""

key = os.getenv("PLANET_API_KEY")

return PlanetModel(key)