Skip to content

Commit

Permalink
Add timestamp to figure save directory
Browse files Browse the repository at this point in the history
  • Loading branch information
dstansby committed May 6, 2018
1 parent bd7d4b0 commit 589723d
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Expand Up @@ -76,5 +76,5 @@ $RECYCLE.BIN/
.pytest_cache/
sunpydata.sqlite

result_images
result_images*
.pytest_cache
4 changes: 2 additions & 2 deletions sunpy/conftest.py
Expand Up @@ -14,7 +14,7 @@
matplotlib.use('Agg')

from sunpy.tests.hash import HASH_LIBRARY_NAME
from sunpy.tests.helpers import new_hash_library
from sunpy.tests.helpers import new_hash_library, test_fig_dir
from sunpy.extern import six

import pytest
Expand Down Expand Up @@ -49,7 +49,7 @@ def pytest_runtest_setup(item):
def pytest_unconfigure(config):
if len(new_hash_library) > 0:
# Write the new hash library in JSON
hashfile = os.path.join('result_images', HASH_LIBRARY_NAME)
hashfile = os.path.join(test_fig_dir, HASH_LIBRARY_NAME)
with open(hashfile, 'w') as outfile:
json.dump(new_hash_library, outfile, sort_keys=True, indent=4, separators=(',', ': '))

Expand Down
8 changes: 5 additions & 3 deletions sunpy/tests/helpers.py
Expand Up @@ -7,6 +7,7 @@
import tempfile
import platform
import os
import datetime

import pytest
import numpy as np
Expand Down Expand Up @@ -52,6 +53,7 @@ def warnings_as_errors(request):

hash_library = hash.hash_library
new_hash_library = {}
test_fig_dir = 'result_images_{:%H%M%S}'.format(datetime.datetime.now())


def figure_test(test_function):
Expand Down Expand Up @@ -85,9 +87,9 @@ def wrapper(*args, **kwargs):
fig = plt.gcf()

# Save the image that was generated
if not os.path.exists('result_images'):
os.mkdir('result_images')
result_image_loc = os.path.join('result_images', '{}.png'.format(name))
if not os.path.exists(test_fig_dir):
os.mkdir(test_fig_dir)
result_image_loc = os.path.join(test_fig_dir, '{}.png'.format(name))
plt.savefig(result_image_loc)
plt.close()

Expand Down

0 comments on commit 589723d

Please sign in to comment.