def test_save_images_exception(self): app = self.application app.frames = [ (VTKMesh('mesh'), VTKParticles("flow_particles"), VTKParticles("wall_particles")), (VTKMesh('mesh'), VTKParticles("flow_particles"), VTKParticles("wall_particles")), (VTKMesh('mesh'), VTKParticles("flow_particles"), VTKParticles("wall_particles")), ] temp_dir = tempfile.mkdtemp() with cleanup_garbage(temp_dir), \ mock.patch("simphony_ui.ui.DirectoryDialog") as dialog_cls, \ mock.patch('simphony_ui.ui.error') as mock_message, \ mock.patch("simphony_ui.ui.mlab") as mlab: def mock_msg(*args, **kwargs): return mock_message.side_effect = mock_msg dialog = mock.Mock() dialog_cls.return_value = dialog dialog.open.return_value = OK dialog.path = temp_dir savefig = mock.Mock(side_effect=Exception()) mlab.savefig = savefig app._save_images() self.assertTrue(app.interactive) self.assertTrue(mock_message.called)
def test_save_images(self): app = self.application app.frames = [ (VTKMesh('mesh'), VTKParticles("flow_particles"), VTKParticles("wall_particles")), (VTKMesh('mesh'), VTKParticles("flow_particles"), VTKParticles("wall_particles")), (VTKMesh('mesh'), VTKParticles("flow_particles"), VTKParticles("wall_particles")), ] temp_dir = tempfile.mkdtemp() with cleanup_garbage(temp_dir), \ mock.patch("simphony_ui.ui.DirectoryDialog") as dialog_cls, \ mock.patch("simphony_ui.ui.mlab") as mlab: dialog = mock.Mock() dialog_cls.return_value = dialog dialog.open.return_value = CANCEL dialog.path = temp_dir mlab.savefig = mock.Mock() app._save_images() self.assertFalse(mlab.savefig.called) mlab.savefig.reset_mock() dialog.open.return_value = OK app._save_images() self.assertEqual(mlab.savefig.call_count, 3) for i in xrange(3): self.assertEqual( mlab.savefig.call_args_list[i][0][0], os.path.join(temp_dir, "frame-{}.png".format(i)))
def setUp(self): self.temp_dir = tempfile.mkdtemp() with cleanup_garbage(self.temp_dir): self.openfoam_model = CustomOpenfoamModel() self.openfoam_model.output_path = self.temp_dir self.openfoam_model.input_file = os.path.join( os.path.join(os.path.dirname(os.path.abspath(__file__)), 'fixtures'), 'openfoam_input.txt')
def test_ui_timeout(self): openfoam_settings = OpenfoamModel() openfoam_settings.input_file = os.path.join( os.path.join(os.path.dirname(os.path.abspath(__file__)), 'fixtures'), 'openfoam_input.txt') liggghts_settings = LiggghtsModel() liggghts_settings.input_file = os.path.join( os.path.join(os.path.dirname(os.path.abspath(__file__)), 'fixtures'), 'liggghts_input.dat') global_settings = GlobalParametersModel() def progress_callback(*args, **kwargs): pass event_lock = mock.Mock() event_lock.wait.return_value = False temp_dir = tempfile.mkdtemp() with cleanup_garbage(temp_dir): self.assertIsNone( run_calc(global_settings, openfoam_settings, liggghts_settings, progress_callback, event_lock))
def setUpClass(cls): cls.global_settings = GlobalParametersModel() cls.openfoam_settings = OpenfoamModel() cls.liggghts_settings = LiggghtsModel() cls.event_lock = Mock() cls.event_lock.wait = Mock() cls.event_lock.clear = Mock() cls.openfoam_settings.input_file = os.path.join( os.path.join( os.path.dirname(os.path.abspath(__file__)), 'fixtures' ), 'openfoam_input.txt' ) cls.liggghts_settings.input_file = os.path.join( os.path.join( os.path.dirname(os.path.abspath(__file__)), 'fixtures' ), 'liggghts_input.dat' ) temp_dir = tempfile.mkdtemp() with cleanup_garbage(temp_dir): cls.openfoam_settings.output_path = temp_dir def callback(*args): pass cls.datasets = run_calc( cls.global_settings, cls.openfoam_settings, cls.liggghts_settings, callback, event_lock=cls.event_lock ) super(TestCalculation, cls).setUpClass()
def test_multi_thread(self): app = self.application app.openfoam_settings.input_file = os.path.join( os.path.join(os.path.dirname(os.path.abspath(__file__)), 'fixtures'), 'openfoam_input.txt') app.liggghts_settings.input_file = os.path.join( os.path.join(os.path.dirname(os.path.abspath(__file__)), 'fixtures'), 'liggghts_input.dat') app.global_settings.num_iterations = 2 temp_dir = tempfile.mkdtemp() with cleanup_garbage(temp_dir): app.openfoam_settings.output_path = temp_dir self.assertEqual(len(app.frames), 0) app.run_calc() with self.event_loop_until_condition(lambda: (len(app.frames) != 0), timeout=30): pass with self.event_loop_until_condition(lambda: app.interactive, timeout=30): pass self.assertNotEqual(len(app.frames), 0) self.assertEqual(len(app.frames[0]), 3) # Last added module was the arrow_module self.assertEqual( app.sources[1].children[0].children[0].glyph.scale_mode, 'scale_by_scalar') self.assertEqual( app.sources[1].children[0].children[1].glyph.scale_mode, 'scale_by_vector') self.assertEqual( app.sources[1].children[0].children[1].glyph.color_mode, 'color_by_vector') app.reset() app.run_calc() with self.event_loop_until_condition(lambda: (len(app.frames) != 0), timeout=30): pass with self.event_loop_until_condition(lambda: app.interactive, timeout=30): pass self.assertEqual( app.sources[1].children[0].children[0].glyph.scale_mode, 'scale_by_scalar') self.assertEqual( app.sources[1].children[0].children[1].glyph.scale_mode, 'scale_by_vector') self.assertEqual( app.sources[1].children[0].children[1].glyph.color_mode, 'color_by_vector')