def testOutput(self): """ Test that the python output is working. """ self.plot() # Write the python script output = self._widget.OutputPlugin name = '{}_test_script.py'.format(self.__class__.__name__) output.write.emit(name) self.assertTrue(os.path.exists(name)) # Compare with gold with open(name, 'r') as fid: script = fid.read() with open(os.path.join('gold', name), 'r') as fid: gold_script = fid.read() self.assertEqual(script.strip('\n'), gold_script.strip('\n')) # Remove the show from the script and make it output a png script = script.replace('plt.show()', '') script = script.replace('output.pdf', 'output.png') with open(name, 'w') as fid: fid.write(script) subprocess.call(['python', name], stdout=open(os.devnull, 'wb'), stderr=subprocess.STDOUT) self.assertTrue(os.path.exists('output.png')) differ = mooseutils.ImageDiffer(os.path.join('gold', 'output.png'), 'output.png', allowed=0.99) print differ.message() self.assertFalse(differ.fail(), "{} does not match the gold file.".format(name)) # Test pdf output name = '{}_test_output.pdf'.format(self.__class__.__name__) output.write.emit(name) self.assertTrue(os.path.exists(name)) # Test png output name = '{}_test_output.png'.format(self.__class__.__name__) output.write.emit(name) self.assertTrue(os.path.exists(name)) goldname = os.path.join('gold', name) differ = mooseutils.ImageDiffer(goldname, name, allowed=0.99) self.assertFalse(differ.fail(), "{} does not match the gold file.".format(name))
def testPython(self): """ Test script writer. """ # Test that the script is created imagename = self._repr_script.replace('.py', '.png') self._window.onResultOptionsChanged({'variable': 'diffused'}) self._window.onWindowRequiresUpdate() self._window._window.setOptions(test=True) self._widget.OutputPlugin.write.emit(self._repr_script) self.assertTrue(os.path.exists(self._repr_script)) # Inject write command with open(self._repr_script, 'a') as fid: fid.write('\nwindow.write({})'.format(repr(imagename))) # Execute the script subprocess.call(['python', self._repr_script], stdout=open(os.devnull, 'wb'), stderr=subprocess.STDOUT) self.assertTrue(os.path.exists(imagename)) # Diff the image from the script if self._window.devicePixelRatio() == 1: differ = mooseutils.ImageDiffer(os.path.join('gold', imagename), imagename) print(differ.message()) self.assertFalse(differ.fail())
def python(self, imagename): """ Test script writer. """ # Test that the script is created self._window._window.setOptions(test=True, size=[600, 600]) self._widget.OutputPlugin.write.emit(self._repr_script) self.assertTrue(os.path.exists(self._repr_script)) # Inject write command with open(self._repr_script, 'a') as fid: fid.write('\nwindow.write({})'.format(repr(imagename))) # Execute the script subprocess.call(['python', self._repr_script], stdout=open(os.devnull, 'wb'), stderr=subprocess.STDOUT) self.assertTrue(os.path.exists(imagename)) # Diff the image from the script differ = mooseutils.ImageDiffer(os.path.join('gold', imagename), imagename) print differ.message() self.assertFalse(differ.fail())
def testPNG(self): """ Tests the PNG button is working. """ imagename = self._repr_script.replace('.py', '.png') self._widget.OutputPlugin.write.emit(imagename) differ = mooseutils.ImageDiffer(os.path.join('gold', imagename), imagename) print differ.message() self.assertFalse(differ.fail())
def testPNG(self): """ Tests the PNG button is working. """ imagename = self._repr_script.replace('.py', '.png') self._window.onResultOptionsChanged({'variable': 'diffused'}) self._widget.OutputPlugin.write.emit(imagename) differ = mooseutils.ImageDiffer(os.path.join('gold', imagename), imagename) print(differ.message()) self.assertFalse(differ.fail())