Skip to content

Commit

Permalink
Merge pull request #11174 from brianmoose/fix-peacock
Browse files Browse the repository at this point in the history
Do a better job of cleaning up the FileCache
  • Loading branch information
permcody committed Apr 3, 2018
2 parents 4ce2672 + a7ee7a9 commit 424301c
Show file tree
Hide file tree
Showing 10 changed files with 58 additions and 38 deletions.
3 changes: 0 additions & 3 deletions python/peacock/Input/InputFile.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,17 +54,14 @@ def openInputFile(self, filename):
# parser doesn't do any checks.
if not os.path.exists(filename):
msg = "Input file %s does not exist" % filename
mooseutils.mooseError(msg)
raise PeacockException(msg)

if not os.path.isfile(filename):
msg = "Input file %s is not a file" % filename
mooseutils.mooseError(msg)
raise PeacockException(msg)

if not filename.endswith(".i"):
msg = "Input file %s does not have the proper extension" % filename
mooseutils.mooseError(msg)
raise PeacockException(msg)

with open(filename, 'r') as f:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def setUp(self):
self.input_file = os.path.abspath("../../common/transient.i")

def tearDown(self):
super(Tests, self).tearDown()
Testing.remove_file("delete_me.i")
Testing.remove_file("delete_me2.i")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class Tests(Testing.PeacockTester):
def tearDown(self):
if self.input:
self.input.MeshViewerPlugin.reset()
super(Tests, self).tearDown()

def create_app(self, args):
self.createPeacockApp(args)
Expand Down Expand Up @@ -149,7 +150,7 @@ def testWrongExe(self):
self.assertEqual(tab.MeshPlugin.isEnabled(), False)

def testBadInput(self):
self.create_app(["-i", "../../common/out_transient.e", Testing.find_moose_test_exe()])
self.create_app(["-i", "gold/out_transient.e", Testing.find_moose_test_exe()])
tabs = self.app.main_widget.tab_plugin
self.check_current_tab(tabs, self.input.tabName())

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def setUp(self):
"""
Creates the peacock application.
"""

Testing.setupTestCache(self.__class__)
args = ["-size", "1024", "768", "-i", "../../common/transient_big.i", "-e", Testing.find_moose_test_exe()]
working_dir = os.getcwd()
self._app = PeacockApp.PeacockApp(args, self.qapp)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def setUp(self):
"""
Creates the peacock application.
"""

Testing.setupTestCache(self.__class__)
args = ["-size", "1024", "768", "-i", "../../common/time_data.i", "-e", Testing.find_moose_test_exe(), "-w", os.getcwd()]
self._app = PeacockApp.PeacockApp(args, self.qapp)
self._window = self._app.main_widget.tab_plugin.VectorPostprocessorViewer.currentWidget().FigurePlugin
Expand Down
3 changes: 0 additions & 3 deletions python/peacock/tests/utils/test_RecentlyUsedMenu.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,13 @@

from peacock.utils.RecentlyUsedMenu import RecentlyUsedMenu
from peacock.utils import Testing
from PyQt5.QtCore import QSettings
from PyQt5 import QtWidgets

class Tests(Testing.PeacockTester):
qapp = QtWidgets.QApplication([])

def setUp(self):
super(Tests, self).setUp()
settings = QSettings()
settings.clear()
self.main_win = QtWidgets.QMainWindow()
self.menubar = self.main_win.menuBar()
self.test_menu = self.menubar.addMenu("Test recently used")
Expand Down
4 changes: 3 additions & 1 deletion python/peacock/utils/FileCache.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ def _setDirty(self):
or self.path_data.get("data_version") != self.data_version
or self.stat.st_ctime != self.path_data.get("ctime")
or self.stat.st_size != self.path_data.get("size")
or not os.path.exists(self.path_data.get("pickle_path"))
):
self.dirty = True
return
Expand All @@ -81,7 +82,7 @@ def read(self):
return None

@staticmethod
def removeCacheFile( path):
def removeCacheFile(path):
try:
os.remove(path)
except:
Expand Down Expand Up @@ -141,3 +142,4 @@ def clearAll(settings_key):
for key, val in val.items():
FileCache.removeCacheFile(val["pickle_path"])
settings.remove(settings_key)
settings.sync()
68 changes: 43 additions & 25 deletions python/peacock/utils/Testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import qtutils
import time
import unittest
import glob
import glob, shutil
from PyQt5 import QtCore, QtWidgets
from peacock import PeacockApp
import inspect
Expand Down Expand Up @@ -92,17 +92,12 @@ def remove_file(filename):
pass

def clean_files():
remove_file("out_transient.csv")
remove_file("oversample_oversample2.e")
remove_file("out_transient.e")
remove_file("peacock_run_exe_tmp.i")
remove_file("peacock_run_tmp.i")
remove_file("peacock_run_tmp_mesh.e")
remove_file("peacock_run_tmp_mesh.i")
for i in range(21):
remove_file("peacock_run_tmp_out_line_sample_{0:04d}.csv".format(i))
remove_file("time_data_line_sample_{0:04d}.csv".format(i))
remove_file("time_data_line_sample_time.csv")
for fname in glob.glob('*.csv'):
remove_file(fname)
for fname in glob.glob('*.e'):
remove_file(fname)
for fname in glob.glob('peacock_*.[ie]'):
remove_file(fname)

def run_tests():
unittest.main(verbosity=2)
Expand Down Expand Up @@ -132,29 +127,45 @@ def findQObjectsByType(top_qobject, type_name):
addQObjectByType(top_qobject, type_name, matched)
return matched

def setupTestCache(cls):
"""
This should be called by most/all of the peacock tests. It
sets QCoreApplication.applicationName based on the currently
running test so that when running in parallel different tests don't
clobber the --json dump cache or overwrite settings.
It also clears out any existing --json dumps cached and clears the
settings.
"""
message.MOOSE_TESTING_MODE = True
test_app_name = os.path.splitext(os.path.basename(inspect.getfile(cls)))[0]
qtutils.setAppInformation(app_name=test_app_name, force=True)
settings = QtCore.QSettings()
settings.clear()
settings.sync()
ds = QtCore.QStandardPaths.standardLocations(QtCore.QStandardPaths.CacheLocation)
for d in ds:
if os.path.isdir(d):
try:
shutil.rmtree(d)
except:
pass

class PeacockTester(unittest.TestCase):
def setUp(self):
self.finished = False
self.app = None
message.MOOSE_TESTING_MODE = True
qtutils.setAppInformation(app_name=self._appPrefix())
self.starting_directory = os.getcwd()
self.clearSettings()

def _appPrefix(self):
return os.path.splitext(os.path.basename(inspect.getfile(self.__class__)))[0]

def clearSettings(self):
settings = QtCore.QSettings()
settings.clear()
settings.sync()
setupTestCache(self.__class__)
clean_files()

def tearDown(self):
if self.app:
self.app.main_widget.close()
del self.app
os.chdir(self.starting_directory)
self.clearSettings()
# cleanup after ourselves
setupTestCache(self.__class__)
clean_files()

def run_finished(self, current, total):
if current == total:
Expand Down Expand Up @@ -192,10 +203,17 @@ def setUpClass(cls):
"""
super(PeacockImageTestCase, cls).setUpClass()

setupTestCache(cls)

filenames = glob.glob(cls.filename('_*.png'))
for fname in filenames:
os.remove(fname)

@classmethod
def tearDownClass(cls):
super(PeacockImageTestCase, cls).tearDownClass()
setupTestCache(cls) # cleanup after ourselves

@classmethod
def filename(cls, basename):
"""
Expand Down Expand Up @@ -244,7 +262,7 @@ def setUp(self):
self._app = PeacockApp.PeacockApp(args)
self._window = self._app.main_widget.tab_plugin.ExodusViewer.currentWidget().VTKWindowPlugin
set_window_size(self._window)
remove_file('peacock_run_exe_tmp_out.e')
clean_files()

def selectTab(self, tab):
"""
Expand Down
8 changes: 6 additions & 2 deletions python/peacock/utils/qtutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,17 @@
from mooseutils import message
from PyQt5 import QtCore

def setAppInformation(app_name="peacock"):
def setAppInformation(app_name="peacock", force=False):
"""
Set the application depending on whether we are testing
"""
QtCore.QCoreApplication.setOrganizationName("IdahoLab")
QtCore.QCoreApplication.setOrganizationDomain("inl.gov")
if message.MOOSE_TESTING_MODE:
QtCore.QCoreApplication.setApplicationName("test_%s" % app_name)
if force or not QtCore.QCoreApplication.applicationName():
# We don't want to override the application name if it is already
# set since PeacockApp will set it to "peacock_peacockapp" and
# we want the names to be more unique.
QtCore.QCoreApplication.setApplicationName("test_%s" % app_name)
else:
QtCore.QCoreApplication.setApplicationName(app_name)
2 changes: 1 addition & 1 deletion scripts/separate_unittests.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,6 @@
cmd.append("-b")
ret = subprocess.call(cmd)
if ret != 0:
print("%s exited %s" % (t, ret))
print("%s exited %s" % (name, ret))
final_code = 1
sys.exit(final_code)

0 comments on commit 424301c

Please sign in to comment.