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

Image comparison #162

Draft
wants to merge 1 commit into
base: dev
Choose a base branch
from
Draft
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
104 changes: 92 additions & 12 deletions tests/test_examples.py
Original file line number Diff line number Diff line change
@@ -1,39 +1,119 @@
import unittest
from pathlib import Path

from matplotlib.testing import compare

import numpy as np
from eomaps import Maps

basepath = Path(__file__).parent
img_folder = basepath / "test_images" / "examples"


def compareit(tol=1, **save_kwargs):
def decorator(f):
def wrapper(*args, **kwargs):
test_img = img_folder / (f.__name__ + ".png")
compare_img = test_img.parent / (
test_img.stem + "_compare" + test_img.suffix
)

m = f(*args, **kwargs)

# if not test_img.exists():
# m.savefig(test_img, **save_kwargs)
# print("Image did not yet exist!!")
# return

m.savefig(compare_img, **save_kwargs)
ret = compare.compare_images(test_img, compare_img, tol, False)

if ret is not None:
raise compare.ImageComparisonFailure(ret)

return ret

return wrapper

return decorator


class TestExamples(unittest.TestCase):
@compareit()
def test_example1(self):
import example1
np.random.seed(1)

from example1 import m

return m

@compareit()
def test_example2(self):
import example2
np.random.seed(1)

from example2 import m

return m

@compareit()
def test_example3(self):
import example3
np.random.seed(1)

from example3 import m

return m

@compareit()
def test_example4(self):
import example4
from example4 import m

return m

@compareit()
def test_example5(self):
import example5
from example5 import m

return m

@compareit(tol=10)
def test_example6(self):
import example6
# increase tolerance here since we deal with webmaps!
from example6 import m

return m

@compareit()
def test_example7(self):
import example7
from example7 import m

return m

@compareit()
def test_example8(self):
import example8
from example8 import m

return m

@compareit()
def test_example9(self):
import example9
from example9 import m

return m

@compareit()
def test_example_inset_maps(self):
import example_inset_maps
from example_inset_maps import m

return m

@compareit()
def test_example_row_col_selector(self):
import example_row_col_selector
from example_row_col_selector import m

return m

@compareit()
def test_example_lines(self):
import example_lines
from example_lines import m

return m
Binary file added tests/test_images/examples/test_example1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/test_images/examples/test_example2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/test_images/examples/test_example3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/test_images/examples/test_example4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/test_images/examples/test_example5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/test_images/examples/test_example6.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/test_images/examples/test_example7.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/test_images/examples/test_example8.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/test_images/examples/test_example9.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.