Skip to content

Commit

Permalink
Test metrics module (r-earthengine#31) and make tests a module
Browse files Browse the repository at this point in the history
  • Loading branch information
aazuspan committed Jan 18, 2022
1 parent 8147089 commit 137722f
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
Empty file added tests/__init__.py
Empty file.
36 changes: 36 additions & 0 deletions tests/test_QA.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import ee
import unittest

from ee_extra.QA.metrics import *

ee.Initialize()


class Test(unittest.TestCase):
"""Tests for QA module."""

def test_list_metrics(self):
"""Test that listMetrics returns a valid dictionary"""
metrics = listMetrics()

self.assertIn("MSE", metrics.keys())
self.assertEqual(MSE, metrics["MSE"])

def test_get_metrics(self):
"""Test that getMetrics returns matches"""
mse = getMetrics(["MSE"])[0]
self.assertIs(mse, MSE)

def test_all_metrics(self):
"""Test that all metrics run"""
metrics = listMetrics().values()

img = ee.Image("LANDSAT/LC08/C01/T1_TOA/LC08_047027_20160819")
modified = ee.Image("LANDSAT/LC08/C01/T1_TOA/LC08_047027_20160819")

for metric in metrics:
if metric is ERGAS:
value = metric(img, modified, h=30, l=30)
else:
value = metric(img, modified)
self.assertIsInstance(value, (ee.Number, ee.Dictionary))

0 comments on commit 137722f

Please sign in to comment.