def test_n2_from_sqlite(self): """ Test that an n2 html file is generated from a sqlite file. """ p = Problem() p.model = SellarStateConnection() r = SqliteRecorder(self.sqlite_db_filename2) p.driver.add_recorder(r) p.setup() p.final_setup() r.shutdown() n2(p, outfile=self.compare_html_filename, show_browser=DEBUG_BROWSER) n2(self.sqlite_db_filename2, outfile=self.sqlite_html_filename, show_browser=DEBUG_BROWSER) # Check that the html file has been created and has something in it. self.assertTrue(os.path.isfile(self.sqlite_html_filename), (self.sqlite_html_filename + " is not a valid file.")) self.assertGreater(os.path.getsize(self.sqlite_html_filename), 100) # Check that there are no errors when running from the command line with a recording. check_call('openmdao n2 --no_browser %s' % self.sqlite_db_filename2) # Compare the sizes of the files generated from the Problem and the recording size1 = os.path.getsize(self.sqlite_html_filename) size2 = os.path.getsize(self.compare_html_filename) self.assertTrue( size1 == size2, 'File size of ' + self.sqlite_html_filename + ' is ' + str(size1) + ', but size of ' + self.compare_html_filename + ' is ' + str(size2))
def test_view_model_command(self): """ Check that there are no errors when running from the command line with a script. """ from openmdao.test_suite.scripts import sellar filename = os.path.abspath(sellar.__file__).replace('.pyc', '.py') # PY2 check_call('openmdao view_model --no_browser %s' % filename)
def test_n2_from_sqlite(self): """ Test that an n2 html file is generated from a sqlite file. """ p = om.Problem() p.model = SellarStateConnection() r = SqliteRecorder(self.sqlite_db_filename2) p.driver.add_recorder(r) p.setup() p.final_setup() r.shutdown() n2(p, outfile=self.compare_html_filename, show_browser=DEBUG_BROWSER) n2(self.sqlite_db_filename2, outfile=self.sqlite_html_filename, show_browser=DEBUG_BROWSER) # Check that the html file has been created and has something in it. self.assertTrue(os.path.isfile(self.sqlite_html_filename), (self.sqlite_html_filename + " is not a valid file.")) self.assertGreater(os.path.getsize(self.sqlite_html_filename), 100) # Check that there are no errors when running from the command line with a recording. check_call('openmdao n2 --no_browser %s' % self.sqlite_db_filename2) # Compare models from the files generated from the Problem and the recording sqlite_model_data = self._extract_compressed_model( self.sqlite_html_filename) compare_model_data = self._extract_compressed_model( self.compare_html_filename) self.assertTrue( sqlite_model_data == compare_model_data, 'Model data from sqlite does not match data from Problem.')
def test_n2_command(self): """ Check that there are no errors when running from the command line with a script. """ from openmdao.test_suite.scripts import sellar filename = os.path.abspath(sellar.__file__).replace('.pyc', '.py') # PY2 check_call('openmdao n2 --no_browser %s' % filename)
def test_pyxdsm_case_reading(self): """ Writes a recorder file, and the XDSM writer makes the diagram based on the SQL file and not the Problem instance. """ from openmdao.recorders.sqlite_recorder import SqliteRecorder filename = 'xdsm_from_sql' case_recording_filename = filename + '.sql' prob = Problem() prob.model = model = SellarNoDerivatives() model.add_design_var('z', lower=np.array([-10.0, 0.0]), upper=np.array([10.0, 10.0]), indices=np.arange(2, dtype=int)) model.add_design_var('x', lower=0.0, upper=10.0) model.add_objective('obj') model.add_constraint('con1', equals=np.zeros(1)) model.add_constraint('con2', upper=0.0) recorder = SqliteRecorder(case_recording_filename) prob.driver.add_recorder(recorder) prob.setup(check=False) prob.final_setup() # Write output write_xdsm(case_recording_filename, filename=filename, out_format='tex', show_browser=False, quiet=QUIET) # Check if file was created self.assertTrue(os.path.isfile(case_recording_filename)) self.assertTrue(os.path.isfile('.'.join([filename, 'tex']))) # Check that there are no errors when running from the command line with a recording. check_call('openmdao xdsm --no_browser %s' % case_recording_filename)
def test_check_call(self): logging.debug('') logging.debug('test_check_call') cmd = 'dir' if sys.platform == 'win32' else 'ls' try: check_call(cmd, stdout='stdout', stderr='stderr') self.assertEqual(os.path.exists('stdout'), True) self.assertEqual(os.path.exists('stderr'), True) finally: if os.path.exists('stdout'): os.remove('stdout') if os.path.exists('stderr'): os.remove('stderr') try: check_call('no-such-command', stdout='stdout', stderr='stderr') self.assertEqual(os.path.exists('stdout'), True) self.assertEqual(os.path.exists('stderr'), True) except CalledProcessError as exc: msg = "Command 'no-such-command' returned non-zero exit status" self.assertEqual(str(exc)[:len(msg)], msg) else: self.fail('Expected CalledProcessError') finally: if os.path.exists('stdout'): os.remove('stdout') if os.path.exists('stderr'): os.remove('stderr')
def test_command(self): """ Check that there are no errors when running from the command line with a script. """ from openmdao.test_suite.scripts import sellar filename = os.path.abspath(sellar.__file__) check_call('openmdao xdsm --no_browser {}'.format(filename))
def test_view_model_from_sqlite(self): """ Test that an n2 html file is generated from a sqlite file. """ p = Problem() p.model = SellarStateConnection() r = SqliteRecorder(self.sqlite_db_filename2) p.driver.add_recorder(r) p.setup(check=False) p.final_setup() r.shutdown() view_model(self.sqlite_db_filename2, outfile=self.sqlite_html_filename, show_browser=DEBUG) # Check that the html file has been created and has something in it. self.assertTrue(os.path.isfile(self.sqlite_html_filename), (self.problem_html_filename + " is not a valid file.")) self.assertGreater(os.path.getsize(self.sqlite_html_filename), 100) # Check that there are no errors when running from the command line with a recording. check_call('openmdao view_model --no_browser %s' % self.sqlite_db_filename2)
def test_view_model_from_sqlite(self): """ Test that an n2 html file is generated from a sqlite file. """ p = Problem() p.model = SellarStateConnection() r = SqliteRecorder(self.sqlite_db_filename2) p.driver.add_recorder(r) p.setup() p.final_setup() r.shutdown() view_model(self.sqlite_db_filename2, outfile=self.sqlite_html_filename, show_browser=DEBUG) # Check that the html file has been created and has something in it. self.assertTrue(os.path.isfile(self.sqlite_html_filename), (self.problem_html_filename + " is not a valid file.")) self.assertGreater(os.path.getsize(self.sqlite_html_filename), 100) # Check that there are no errors when running from the command line with a recording. check_call('openmdao view_model --no_browser %s' % self.sqlite_db_filename2)