def _n2_cmd(options): """ Process command line args and call n2 on the specified file. Parameters ---------- options : argparse Namespace Command line options. """ filename = options.file[0] if filename.endswith('.py'): # the file is a python script, run as a post_setup hook def _viewmod(prob): n2(prob, outfile=options.outfile, show_browser=not options.no_browser, title=options.title, embeddable=options.embeddable, use_declare_partial_info=options.use_declare_partial_info) exit() # could make this command line selectable later options.func = lambda options: _viewmod _post_setup_exec(options) else: # assume the file is a recording, run standalone n2(filename, outfile=options.outfile, title=options.title, show_browser=not options.no_browser, embeddable=options.embeddable, use_declare_partial_info=options.use_declare_partial_info)
def _viewmod(prob): n2(prob, outfile=options.outfile, show_browser=not options.no_browser, title=options.title, embeddable=options.embeddable, use_declare_partial_info=options.use_declare_partial_info) exit() # could make this command line selectable later
def test_n2_from_problem(self): """ Test that an n2 html file is generated from a Problem. """ p = Problem() p.model = SellarStateConnection() p.setup() n2(p, outfile=self.problem_html_filename, show_browser=DEBUG) # Check that the html file has been created and has something in it. self.assertTrue(os.path.isfile(self.problem_html_filename), (self.problem_html_filename + " is not a valid file.")) self.assertGreater(os.path.getsize(self.problem_html_filename), 100)
def test_n2_set_title(self): """ Test that an n2 html file is generated from a Problem. """ p = Problem() p.model = SellarStateConnection() p.setup() n2(p, outfile=self.problem_html_filename, show_browser=DEBUG, title="Sellar State Connection") # Check that the html file has been created and has something in it. self.assertTrue(os.path.isfile(self.problem_html_filename), (self.problem_html_filename + " is not a valid file.")) self.assertTrue( 'OpenMDAO Model Hierarchy and N2 diagram: Sellar State Connection' \ in open(self.problem_html_filename).read() )
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(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 n2 --no_browser %s' % self.sqlite_db_filename2)