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

taup: added a time plot -- analogue to the existing ray path plot #1877

Merged
merged 49 commits into from Oct 9, 2017
Commits
Jump to file or symbol
Failed to load files and symbols.
+18 −10
Diff settings

Always

Just for now

Viewing a subset of changes. View all

ImageComparison decorator: add option to deactivate imgur upload

this can be used in tests that should fail and then might attempt to
upload images which takes several seconds and is totally unwanted in
this case
  • Loading branch information...
megies committed Oct 7, 2017
commit 0d82278b4b5e366da50863657de2c9031025ec42
@@ -80,12 +80,10 @@ def test_image_comparison(self):
# image comparison that should raise
# avoid uploading the staged test fail image
# (after an estimate of 10000 uploads of it.. ;-))
with mock.patch.object(ImageComparison, '_upload_images',
new=mock.MagicMock(return_value='')):
with self.assertRaises(ImageComparisonException):
with ImageComparison(path, img_basename,
adjust_tolerance=False) as ic:
shutil.copy(img_fail, ic.name)
with self.assertRaises(ImageComparisonException):
with ImageComparison(path, img_basename, adjust_tolerance=False,
no_uploads=True) as ic:
shutil.copy(img_fail, ic.name)
# check that temp file is deleted
self.assertFalse(os.path.exists(ic.name))
View
@@ -272,6 +272,11 @@ class ImageComparison(NamedTemporaryFile):
default will leave the style as is. You may wish to set it to
``'default'`` to enable the new style from Matplotlib 2.0, or some
alternate style, which will work back to Matplotlib 1.4.0.
:type no_uploads: bool
:param no_uploads: If set to ``True`` no uploads to imgur are attempted, no
matter what (e.g. any options to ``obspy-runtests`` that would normally
cause an upload attempt). This can be used to forcibly deactivate
upload attempts in image tests that are expected to fail.
The class should be used with Python's "with" statement. When setting up,
the matplotlib rcdefaults are set to ensure consistent image testing.
@@ -305,7 +310,8 @@ class ImageComparison(NamedTemporaryFile):
"""
def __init__(self, image_path, image_name, reltol=1,
adjust_tolerance=True, plt_close_all_enter=True,
plt_close_all_exit=True, style=None, *args, **kwargs):
plt_close_all_exit=True, style=None, no_uploads=False, *args,
**kwargs):
self.suffix = "." + image_name.split(".")[-1]
super(ImageComparison, self).__init__(suffix=self.suffix, *args,
**kwargs)
@@ -318,6 +324,7 @@ def __init__(self, image_path, image_name, reltol=1,
self.tol = reltol * 3.0
self.plt_close_all_enter = plt_close_all_enter
self.plt_close_all_exit = plt_close_all_exit
self.no_uploads = no_uploads
if (MATPLOTLIB_VERSION < [1, 4, 0] or
(MATPLOTLIB_VERSION[:2] == [1, 4] and style is None)):
@@ -561,11 +568,14 @@ def _copy_tempfiles(self):
def _upload_images(self):
"""
Uploads images to imgur.
Uploads images to imgur unless explicitly deactivated with option
`no_uploads` (to speed up tests that are expected to fail).
:returns: ``dict`` with links to uploaded images or ``str`` with
message if upload failed
"""
if self.no_uploads:
return "Upload to imgur deactivated with option 'no_uploads'."
try:
import pyimgur
# try to get imgur client id from environment
@@ -189,8 +189,8 @@ def _test_plot_all(plot_all):
# same test should fail if plot_all=True
with self.assertRaises(ImageComparisonException):
with ImageComparison(
self.image_dir,
"traveltimes_plot_all_False.png") as ic:
self.image_dir, "traveltimes_plot_all_False.png",
no_uploads=True) as ic:
_test_plot_all(plot_all=True)
plt.savefig(ic.name)
ProTip! Use n and p to navigate between commits in a pull request.