def create(self): """ Creates the widgets for testing. This is done here rather than in setUp to allow for testing of delayed loading. """ self._reader = mooseutils.VectorPostprocessorReader(self._pattern) self._data = PostprocessorDataWidget(self._reader) # Build the widgets self._control, self._widget, self._window = main(self._data) self._widget.currentWidget().FigurePlugin.setFixedSize(QtCore.QSize(625, 625))
def setUp(self): """ Creates the GUI containing the ArtistGroupWidget and the matplotlib figure axes. """ data = [PostprocessorDataWidget(mooseutils.PostprocessorReader('../input/white_elephant_jan_2016.csv'))] self._widget, self._window = main() self._widget.FigurePlugin.setFixedSize(QtCore.QSize(500, 500)) self._widget.initialize(data)
def setUp(self): """ Creates the GUI containing the ArtistGroupWidget and the matplotlib figure axes. """ import matplotlib matplotlib.rcParams["figure.figsize"] = (5., 5.) matplotlib.rcParams["figure.dpi"] = (100) data = [PostprocessorDataWidget(mooseutils.PostprocessorReader('../input/white_elephant_jan_2016.csv'))] self._widget, self._window = main() self._widget.FigurePlugin.setFixedSize(QtCore.QSize(500, 500)) self._widget.call('onSetData', data)
def create(self, timer=False): """ Creates the widgets for testing. This is done here rather than in setUp to allow for testing of delayed loading. """ self._reader = mooseutils.PostprocessorReader(self._filename) self._data = PostprocessorDataWidget(self._reader, timer=timer) # Build the widgets self._control, self._widget, self._window = main(self._data) self._widget.currentWidget().FigurePlugin.setFixedSize(QtCore.QSize(625, 625))
class TestLineGroupWidgetPostprocessor(Testing.PeacockImageTestCase): """ Test class for the ArtistToggleWidget which toggles postprocessor lines. """ #: QApplication: The main App for QT, this must be static to work correctly. qapp = QtWidgets.QApplication(sys.argv) def copyfiles(self): """ Copy the data file to a local temporary. """ src = os.path.abspath(os.path.join(__file__, '../../input/white_elephant_jan_2016.csv')) shutil.copyfile(src, self._filename) def create(self, timer=False): """ Creates the widgets for testing. This is done here rather than in setUp to allow for testing of delayed loading. """ self._reader = mooseutils.PostprocessorReader(self._filename) self._data = PostprocessorDataWidget(self._reader, timer=timer) # Build the widgets self._control, self._widget, self._window = main(self._data) self._widget.currentWidget().FigurePlugin.setFixedSize(QtCore.QSize(625, 625)) def setUp(self): """ Creates the GUI containing the ArtistGroupWidget and the matplotlib figure axes. """ self._filename = '{}_{}'.format(self.__class__.__name__, 'test.csv') def tearDown(self): """ Clean up. """ if os.path.exists(self._filename): os.remove(self._filename) def testEmpty(self): """ Test that an empty plot is possible. """ self.copyfiles() self.create() self.assertImage('testEmpty.png') # Test that controls are initialized and disabled correctly self.assertEqual(self._control.AxisVariable.currentText(), "time") self.assertFalse(self._control._toggles['time'].isEnabled(), "Time toggle should be disabled.") def testSelect(self): """ Test that selecting variables works. """ self.copyfiles() self.create() vars = ['air_temp_set_1', 'precip_accum_set_1'] for var in vars: self._control._toggles[var].CheckBox.setCheckState(QtCore.Qt.Checked) self._control._toggles[var].clicked.emit() self.assertImage('testSelect.png') self.assertEqual('; '.join(vars), self._window.axes()[0].get_yaxis().get_label().get_text()) self.assertEqual('time', self._window.axes()[0].get_xaxis().get_label().get_text()) # Switch axis self._control._toggles[vars[0]].PlotAxis.setCurrentIndex(1) self._control._toggles[vars[0]].clicked.emit() self.assertImage('testSelect2.png') self.assertEqual(vars[0], self._window.axes()[1].get_yaxis().get_label().get_text()) self.assertEqual(vars[1], self._window.axes()[0].get_yaxis().get_label().get_text()) self.assertEqual('time', self._window.axes()[0].get_xaxis().get_label().get_text()) def testChangePrimaryVariable(self): """ Test that the primary variable may be modified. """ self.copyfiles() self.create() # Plot something x_var = 'snow_water_equiv_set_1' y_var = 'precip_accum_set_1' self._control._toggles[y_var].CheckBox.setCheckState(QtCore.Qt.Checked) self._control._toggles[y_var].clicked.emit() self.assertImage('testChangePrimaryVariable0.png') # Change the primary variable self._control.AxisVariable.setCurrentIndex(5) self._control.AxisVariable.currentIndexChanged.emit(5) self.assertEqual(self._control.AxisVariable.currentText(), x_var) self.assertFalse(self._control._toggles[x_var].isEnabled(), "Toggle should be disabled.") self.assertTrue(self._control._toggles['time'].isEnabled(), "Toggle should be enabled.") self.assertImage('testChangePrimaryVariable1.png') def testDelayLoadAndUnload(self): """ Test that delayed loading and removal of files works. """ self.create() # Plot should be empty and the message should be visible. self.assertImage('testEmpty.png') self.assertTrue(self._control.NoDataMessage.isVisible()) # Load data self.copyfiles() self._data.load() self.assertFalse(self._control.NoDataMessage.isVisible()) # Plot something var = 'air_temp_set_1' self._control._toggles[var].CheckBox.setCheckState(QtCore.Qt.Checked) self._control._toggles[var].clicked.emit() self.assertImage('testDelayLoadPlot.png') # Remove data os.remove(self._filename) self._data.load() self.assertTrue(self._control.NoDataMessage.isVisible()) self.assertImage('testEmpty.png') # Re-load data self.copyfiles() self._data.load() self.assertFalse(self._control.NoDataMessage.isVisible()) self._control._toggles[var].CheckBox.setCheckState(QtCore.Qt.Checked) self._control._toggles[var].clicked.emit() self.assertImage('testDelayLoadPlot2.png') # The line color/style is different because the cycle keeps going def testRepr(self): """ Test script creation. """ self.copyfiles() self.create() var = 'air_temp_set_1' self._control._toggles[var].CheckBox.setCheckState(QtCore.Qt.Checked) self._control._toggles[var].clicked.emit() output, imports = self._control.repr() self.assertIn("x = data('time')", output) self.assertIn("y = data('air_temp_set_1')", output)
class TestLineGroupWidgetPostprocessor(Testing.PeacockImageTestCase): """ Test class for the ArtistToggleWidget which toggles postprocessor lines. """ #: QApplication: The main App for QT, this must be static to work correctly. qapp = QtWidgets.QApplication(sys.argv) def copyfiles(self): """ Copy the data file to a local temporary. """ src = os.path.abspath( os.path.join(__file__, '../../input/white_elephant_jan_2016.csv')) shutil.copyfile(src, self._filename) def create(self, timer=False): """ Creates the widgets for testing. This is done here rather than in setUp to allow for testing of delayed loading. """ self._reader = mooseutils.PostprocessorReader(self._filename) self._data = PostprocessorDataWidget(self._reader, timer=timer) # Build the widgets self._control, self._widget, self._window = main(self._data) self._widget.currentWidget().FigurePlugin.setFixedSize( QtCore.QSize(625, 625)) def setUp(self): """ Creates the GUI containing the ArtistGroupWidget and the matplotlib figure axes. """ self._filename = '{}_{}'.format(self.__class__.__name__, 'test.csv') def tearDown(self): """ Clean up. """ if os.path.exists(self._filename): os.remove(self._filename) def testEmpty(self): """ Test that an empty plot is possible. """ self.copyfiles() self.create() self.assertImage('testEmpty.png') # Test that controls are initialized and disabled correctly self.assertEqual(self._control.AxisVariable.currentText(), "time") self.assertFalse(self._control._toggles['time'].isEnabled(), "Time toggle should be disabled.") def testSelect(self): """ Test that selecting variables works. """ self.copyfiles() self.create() vars = ['air_temp_set_1', 'precip_accum_set_1'] for var in vars: self._control._toggles[var].CheckBox.setCheckState( QtCore.Qt.Checked) self._control._toggles[var].clicked.emit() self.assertImage('testSelect.png') self.assertEqual( '; '.join(vars), self._window.axes()[0].get_yaxis().get_label().get_text()) self.assertEqual( 'time', self._window.axes()[0].get_xaxis().get_label().get_text()) # Switch axis self._control._toggles[vars[0]].PlotAxis.setCurrentIndex(1) self._control._toggles[vars[0]].clicked.emit() self.assertImage('testSelect2.png') self.assertEqual( vars[0], self._window.axes()[1].get_yaxis().get_label().get_text()) self.assertEqual( vars[1], self._window.axes()[0].get_yaxis().get_label().get_text()) self.assertEqual( 'time', self._window.axes()[0].get_xaxis().get_label().get_text()) def testChangePrimaryVariable(self): """ Test that the primary variable may be modified. """ self.copyfiles() self.create() # Plot something x_var = 'snow_water_equiv_set_1' y_var = 'precip_accum_set_1' self._control._toggles[y_var].CheckBox.setCheckState(QtCore.Qt.Checked) self._control._toggles[y_var].clicked.emit() self.assertImage('testChangePrimaryVariable0.png') # Change the primary variable self._control.AxisVariable.setCurrentIndex(5) self._control.AxisVariable.currentIndexChanged.emit(5) self.assertEqual(self._control.AxisVariable.currentText(), x_var) self.assertFalse(self._control._toggles[x_var].isEnabled(), "Toggle should be disabled.") self.assertTrue(self._control._toggles['time'].isEnabled(), "Toggle should be enabled.") self.assertImage('testChangePrimaryVariable1.png') def testDelayLoadAndUnload(self): """ Test that delayed loading and removal of files works. """ self.create() # Plot should be empty and the message should be visible. self.assertImage('testEmpty.png') self.assertTrue(self._control.NoDataMessage.isVisible()) # Load data self.copyfiles() self._data.load() self.assertFalse(self._control.NoDataMessage.isVisible()) # Plot something var = 'air_temp_set_1' self._control._toggles[var].CheckBox.setCheckState(QtCore.Qt.Checked) self._control._toggles[var].clicked.emit() self.assertImage('testDelayLoadPlot.png') # Remove data os.remove(self._filename) self._data.load() self.assertTrue(self._control.NoDataMessage.isVisible()) self.assertImage('testEmpty.png') # Re-load data self.copyfiles() self._data.load() self.assertFalse(self._control.NoDataMessage.isVisible()) self._control._toggles[var].CheckBox.setCheckState(QtCore.Qt.Checked) self._control._toggles[var].clicked.emit() self.assertImage( 'testDelayLoadPlot2.png', allowed=0.98 ) # The line color/style is different because the cycle keeps going def testRepr(self): """ Test script creation. """ self.copyfiles() self.create() var = 'air_temp_set_1' self._control._toggles[var].CheckBox.setCheckState(QtCore.Qt.Checked) self._control._toggles[var].clicked.emit() output, imports = self._control.repr() self.assertIn("x = data('time')", output) self.assertIn("y = data('air_temp_set_1')", output)
class TestLineGroupWidgetVectorPostprocessor(Testing.PeacockImageTestCase): """ Test class for the ArtistToggleWidget which toggles postprocessor lines. """ #: QApplication: The main App for QT, this must be static to work correctly. qapp = QtWidgets.QApplication(sys.argv) def copyfiles(self): """ Copy the data file to a local temporary. """ prefix = os.path.abspath(os.path.join(__file__, '../../input/vpp2_')) t = [0, 1, 3, 5, 7, 9] for i in range(len(t)): src = '{}000{}.csv'.format(prefix, t[i]) shutil.copyfile(src, self._filenames[i]) def create(self): """ Creates the widgets for testing. This is done here rather than in setUp to allow for testing of delayed loading. """ self._reader = mooseutils.VectorPostprocessorReader(self._pattern) self._data = PostprocessorDataWidget(self._reader) # Build the widgets self._control, self._widget, self._window = main(self._data) self._widget.currentWidget().FigurePlugin.setFixedSize(QtCore.QSize(625, 625)) def setUp(self): """ Creates the GUI containing the ArtistGroupWidget and the matplotlib figure axes. """ prefix = self.__class__.__name__ self._pattern = '{}_test_*.csv'.format(prefix) self._filenames = [] for t in [0, 1, 3, 5, 7, 9]: self._filenames.append('{}_test_000{}.csv'.format(prefix, t)) def tearDown(self): """ Clean up. """ for filename in self._filenames: if os.path.exists(filename): os.remove(filename) def testEmpty(self): """ Test that an empty plot is possible. """ self.copyfiles() self.create() self.assertImage('testEmpty.png') # Test that controls are initialized and disabled correctly self.assertEqual(self._control.AxisVariable.currentText(), "index (Peacock)") self.assertFalse(self._control._toggles['index (Peacock)'].isEnabled(), "id toggle should be disabled.") def testSelect(self): """ Test that selecting variables works. """ self.copyfiles() self.create() vars = ['t**2*x', 't*x**2'] for var in vars: self._control._toggles[var].CheckBox.setCheckState(QtCore.Qt.Checked) self._control._toggles[var].clicked.emit() self.assertImage('testSelect.png') self.assertEqual('; '.join(vars), self._window.axes()[0].get_yaxis().get_label().get_text()) self.assertEqual('index (Peacock)', self._window.axes()[0].get_xaxis().get_label().get_text()) # Switch axis self._control._toggles[vars[0]].PlotAxis.setCurrentIndex(1) self._control._toggles[vars[0]].clicked.emit() self.assertImage('testSelect2.png') self.assertEqual(vars[0], self._window.axes()[1].get_yaxis().get_label().get_text()) self.assertEqual(vars[1], self._window.axes()[0].get_yaxis().get_label().get_text()) self.assertEqual('index (Peacock)', self._window.axes()[0].get_xaxis().get_label().get_text()) def testChangePrimaryVariable(self): """ Test that the primary variable may be modified. """ self.copyfiles() self.create() # Plot something x_var = 't*x' y_var = 't*x**2' self._control._toggles[y_var].CheckBox.setCheckState(QtCore.Qt.Checked) self._control._toggles[y_var].clicked.emit() self.assertImage('testChangePrimaryVariable0.png') # Change the primary variable self._control.AxisVariable.setCurrentIndex(2) self._control.AxisVariable.currentIndexChanged.emit(2) self.assertEqual(self._control.AxisVariable.currentText(), x_var) self.assertFalse(self._control._toggles[x_var].isEnabled(), "Toggle should be disabled.") self.assertTrue(self._control._toggles['index (Peacock)'].isEnabled(), "Toggle should be enabled.") self.assertImage('testChangePrimaryVariable1.png') def testDelayLoadAndUnload(self): """ Test that delayed loading and removal of files works. """ self.create() # Plot should be empty and the message should be visible. self.assertImage('testEmpty.png') self.assertTrue(self._control.NoDataMessage.isVisible()) # Load data self.copyfiles() self._data.load() self.assertFalse(self._control.NoDataMessage.isVisible()) # Plot something var = 't*x**2' self._control._toggles[var].CheckBox.setCheckState(QtCore.Qt.Checked) self._control._toggles[var].clicked.emit() self.assertImage('testDelayLoadPlot.png') # Remove data self.tearDown() self._data.load() self.assertTrue(self._control.NoDataMessage.isVisible()) self.assertImage('testEmpty.png') # Re-load data self.copyfiles() self._data.load() self.assertFalse(self._control.NoDataMessage.isVisible()) self._control._toggles[var].CheckBox.setCheckState(QtCore.Qt.Checked) self._control._toggles[var].clicked.emit() self.assertImage('testDelayLoadPlot2.png') # The line color/style is different because the cycle keeps going def testTime(self): """ Test that the time of VPP data can be specified. """ self.copyfiles() self.create() var = 't*x**2' self._control._toggles[var].CheckBox.setCheckState(QtCore.Qt.Checked) self._control._toggles[var].clicked.emit() self.assertEqual(self._window.axes()[0].get_ylim(), (-45.0, 945.0)) self.assertImage('testTime0.png') # Change the time self._control.plot(time=1) self.assertEqual(self._window.axes()[0].get_ylim(), (-5.0, 105.0)) self.assertImage('testTime1.png') # Change to an invalid time, the control should be disabled and plot removed self._control.plot(time=2.5) self.assertFalse(self._control.isEnabled()) self.assertImage('testEmpty.png') def testRepr(self): """ Test script function. """ self.copyfiles() self.create() var = 't*x**2' self._control._toggles[var].CheckBox.setCheckState(QtCore.Qt.Checked) self._control._toggles[var].clicked.emit() self._control.plot(time=9.0) output, imports = self._control.repr() self.assertIn("x = data('index (Peacock)', time=9.0)", output) self.assertIn("y = data('t*x**2', time=9.0)", output)
class TestLineGroupWidgetVectorPostprocessor(Testing.PeacockImageTestCase): """ Test class for the ArtistToggleWidget which toggles postprocessor lines. """ #: QApplication: The main App for QT, this must be static to work correctly. qapp = QtWidgets.QApplication(sys.argv) def copyfiles(self): """ Copy the data file to a local temporary. """ prefix = os.path.abspath(os.path.join(__file__, '../../input/vpp2_')) t = [0, 1, 3, 5, 7, 9] for i in range(len(t)): src = '{}000{}.csv'.format(prefix, t[i]) shutil.copyfile(src, self._filenames[i]) def create(self): """ Creates the widgets for testing. This is done here rather than in setUp to allow for testing of delayed loading. """ self._reader = mooseutils.VectorPostprocessorReader(self._pattern) self._data = PostprocessorDataWidget(self._reader) # Build the widgets self._control, self._widget, self._window = main(self._data) self._widget.currentWidget().FigurePlugin.setFixedSize( QtCore.QSize(625, 625)) def setUp(self): """ Creates the GUI containing the ArtistGroupWidget and the matplotlib figure axes. """ prefix = self.__class__.__name__ self._pattern = '{}_test_*.csv'.format(prefix) self._filenames = [] for t in [0, 1, 3, 5, 7, 9]: self._filenames.append('{}_test_000{}.csv'.format(prefix, t)) def tearDown(self): """ Clean up. """ for filename in self._filenames: if os.path.exists(filename): os.remove(filename) def testEmpty(self): """ Test that an empty plot is possible. """ self.copyfiles() self.create() self.assertImage('testEmpty.png') # Test that controls are initialized and disabled correctly self.assertEqual(self._control.AxisVariable.currentText(), "index (Peacock)") self.assertFalse(self._control._toggles['index (Peacock)'].isEnabled(), "id toggle should be disabled.") def testSelect(self): """ Test that selecting variables works. """ self.copyfiles() self.create() vars = ['t**2*x', 't*x**2'] for var in vars: self._control._toggles[var].CheckBox.setCheckState( QtCore.Qt.Checked) self._control._toggles[var].clicked.emit() self.assertImage('testSelect.png') self.assertEqual( '; '.join(vars), self._window.axes()[0].get_yaxis().get_label().get_text()) self.assertEqual( 'index (Peacock)', self._window.axes()[0].get_xaxis().get_label().get_text()) # Switch axis self._control._toggles[vars[0]].PlotAxis.setCurrentIndex(1) self._control._toggles[vars[0]].clicked.emit() self.assertImage('testSelect2.png') self.assertEqual( vars[0], self._window.axes()[1].get_yaxis().get_label().get_text()) self.assertEqual( vars[1], self._window.axes()[0].get_yaxis().get_label().get_text()) self.assertEqual( 'index (Peacock)', self._window.axes()[0].get_xaxis().get_label().get_text()) def testChangePrimaryVariable(self): """ Test that the primary variable may be modified. """ self.copyfiles() self.create() # Plot something x_var = 't*x' y_var = 't*x**2' self._control._toggles[y_var].CheckBox.setCheckState(QtCore.Qt.Checked) self._control._toggles[y_var].clicked.emit() self.assertImage('testChangePrimaryVariable0.png') # Change the primary variable self._control.AxisVariable.setCurrentIndex(2) self._control.AxisVariable.currentIndexChanged.emit(2) self.assertEqual(self._control.AxisVariable.currentText(), x_var) self.assertFalse(self._control._toggles[x_var].isEnabled(), "Toggle should be disabled.") self.assertTrue(self._control._toggles['index (Peacock)'].isEnabled(), "Toggle should be enabled.") self.assertImage('testChangePrimaryVariable1.png') def testDelayLoadAndUnload(self): """ Test that delayed loading and removal of files works. """ self.create() # Plot should be empty and the message should be visible. self.assertImage('testEmpty.png') self.assertTrue(self._control.NoDataMessage.isVisible()) # Load data self.copyfiles() self._data.load() self.assertFalse(self._control.NoDataMessage.isVisible()) # Plot something var = 't*x**2' self._control._toggles[var].CheckBox.setCheckState(QtCore.Qt.Checked) self._control._toggles[var].clicked.emit() self.assertImage('testDelayLoadPlot.png') # Remove data self.tearDown() self._data.load() self.assertTrue(self._control.NoDataMessage.isVisible()) self.assertImage('testEmpty.png') # Re-load data self.copyfiles() self._data.load() self.assertFalse(self._control.NoDataMessage.isVisible()) self._control._toggles[var].CheckBox.setCheckState(QtCore.Qt.Checked) self._control._toggles[var].clicked.emit() self.assertImage( 'testDelayLoadPlot2.png' ) # The line color/style is different because the cycle keeps going def testTime(self): """ Test that the time of VPP data can be specified. """ self.copyfiles() self.create() var = 't*x**2' self._control._toggles[var].CheckBox.setCheckState(QtCore.Qt.Checked) self._control._toggles[var].clicked.emit() self.assertEqual(self._window.axes()[0].get_ylim(), (-45.0, 945.0)) self.assertImage('testTime0.png') # Change the time self._control.plot(time=1) self.assertEqual(self._window.axes()[0].get_ylim(), (-5.0, 105.0)) self.assertImage('testTime1.png') # Change to an invalid time, the control should be disabled and plot removed self._control.plot(time=2.5) self.assertFalse(self._control.isEnabled()) self.assertImage('testEmpty.png') def testRepr(self): """ Test script function. """ self.copyfiles() self.create() var = 't*x**2' self._control._toggles[var].CheckBox.setCheckState(QtCore.Qt.Checked) self._control._toggles[var].clicked.emit() self._control.plot(time=9.0) output, imports = self._control.repr() self.assertIn("x = data('index (Peacock)', time=9.0)", output) self.assertIn("y = data('t*x**2', time=9.0)", output)
layout.addWidget(control) control.axesModified.connect(window.onAxesModified) def axis_label(): """ A labeling function for setting axis labels. """ x, y, y2 = control.getAxisLabels() control._axes[0].set_xlabel(x) control._axes[0].set_ylabel('; '.join(y)) control._axes[1].set_ylabel('; '.join(y2)) control.variablesChanged.connect(axis_label) widget.show() return control, widget, window if __name__ == '__main__': import sys import mooseutils from peacock.PostprocessorViewer.PostprocessorDataWidget import PostprocessorDataWidget app = QtWidgets.QApplication(sys.argv) filename = '../../../tests/input/white_elephant_jan_2016.csv' reader = mooseutils.PostprocessorReader(filename) data = PostprocessorDataWidget(reader) control, widget, window = main(data) sys.exit(app.exec_())