Skip to content

Commit

Permalink
Do a better job of cleaning up the FileCache
Browse files Browse the repository at this point in the history
closes #11156
  • Loading branch information
Brian Alger committed Apr 2, 2018
1 parent ed66139 commit 74fe3aa
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 33 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 @@ -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.removeCacheDir(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.removeCacheDir(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
4 changes: 1 addition & 3 deletions python/peacock/tests/utils/test_RecentlyUsedMenu.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,14 @@

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.clearSettings()
self.main_win = QtWidgets.QMainWindow()
self.menubar = self.main_win.menuBar()
self.test_menu = self.menubar.addMenu("Test recently used")
Expand Down
3 changes: 2 additions & 1 deletion python/peacock/utils/FileCache.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def read(self):
return None

@staticmethod
def removeCacheFile( path):
def removeCacheFile(path):
try:
os.remove(path)
except:
Expand Down Expand Up @@ -141,3 +141,4 @@ def clearAll(settings_key):
for key, val in val.items():
FileCache.removeCacheFile(val["pickle_path"])
settings.remove(settings_key)
settings.sync()
60 changes: 40 additions & 20 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,17 +127,35 @@ def findQObjectsByType(top_qobject, type_name):
addQObjectByType(top_qobject, type_name, matched)
return matched

def removeCacheDir(cls):
# We need to call setAppInfo so that we remove the correct cache directory
setAppInfo(cls)
ds = QtCore.QStandardPaths.standardLocations(QtCore.QStandardPaths.CacheLocation)
for d in ds:
if os.path.isdir(d):
try:
shutil.rmtree(d)
except:
pass

def appSettingsPrefix(cls):
return os.path.splitext(os.path.basename(inspect.getfile(cls)))[0]

def setAppInfo(cls):
message.MOOSE_TESTING_MODE = True
qtutils.setAppInformation(app_name=appSettingsPrefix(cls), force=True)

class PeacockTester(unittest.TestCase):
@classmethod
def setUpClass(cls):
super(PeacockTester, cls).setUpClass()
removeCacheDir(cls)

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]
clean_files()

def clearSettings(self):
settings = QtCore.QSettings()
Expand All @@ -154,7 +167,7 @@ def tearDown(self):
self.app.main_widget.close()
del self.app
os.chdir(self.starting_directory)
self.clearSettings()
clean_files()

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

removeCacheDir(cls)

filenames = glob.glob(cls.filename('_*.png'))
for fname in filenames:
os.remove(fname)
Expand Down Expand Up @@ -236,6 +251,11 @@ class PeacockAppImageTestCase(PeacockImageTestCase):
"""
Base class for testing complete Peacock gui.
"""
@classmethod
def setUpClass(cls):
super(PeacockAppImageTestCase, cls).setUpClass()
removeCacheDir(cls)

def setUp(self):
"""
Creates the peacock application.cd
Expand All @@ -244,7 +264,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 74fe3aa

Please sign in to comment.