solver_io, ('nightly','expensive')) for solver_name, solver_io in [('ipopt','nl')]: networkx_examples_dir = join(pysp_examples_dir, "networkx_scenariotree") networkx_model_dir = join(networkx_examples_dir, "ReferenceModel.py") networkx_data_dir = join(networkx_examples_dir, "ScenarioTree.py") class_names = create_test_classes('networkx', networkx_model_dir, networkx_data_dir, solver_name, solver_io, ('nightly','expensive')) for name in class_names: globals()[name] = unittest.skipIf(not networkx_available, "networkx module is not available")(globals()[name]) # this example is big for solver_name, solver_io in [('cplex','lp')]: baa99_examples_dir = join(pysp_examples_dir, "baa99") baa99_model_dir = join(baa99_examples_dir, "ReferenceModel.py") baa99_data_dir = None create_test_classes('baa99', baa99_model_dir, baa99_data_dir, solver_name, solver_io, ('nightly','expensive')) if __name__ == "__main__":
hydro_examples_dir = join(pysp_examples_dir, "hydro") hydro_model_dir = join(hydro_examples_dir, "models") hydro_data_dir = join(hydro_examples_dir, "scenariodata") create_test_classes('hydro', hydro_model_dir, hydro_data_dir, solver_name, solver_io, ('nightly', 'expensive')) for solver_name, solver_io in [('ipopt', 'nl')]: networkx_examples_dir = join(pysp_examples_dir, "networkx_scenariotree") networkx_model_dir = join(networkx_examples_dir, "ReferenceModel.py") networkx_data_dir = None class_names = create_test_classes('networkx', networkx_model_dir, networkx_data_dir, solver_name, solver_io, ('nightly', 'expensive')) for name in class_names: globals()[name] = unittest.skipIf(not networkx_available, "networkx module is not available")( globals()[name]) # this example is big for solver_name, solver_io in [('cplex', 'lp')]: baa99_examples_dir = join(pysp_examples_dir, "baa99") baa99_model_dir = join(baa99_examples_dir, "ReferenceModel.py") baa99_data_dir = None create_test_classes('baa99', baa99_model_dir, baa99_data_dir, solver_name, solver_io, ('nightly', 'expensive')) if __name__ == "__main__": unittest.main()
def test_egg1(self): """Load an egg for the 'project1' project. Eggs are loaded in the 'eggs1' directory, but only the Project1 stuff is actually imported.""" pyutilib.subprocess.run( [sys.executable, currdir + os.sep + "egg1.py", currdir, "json"]) self.assertMatchesJsonBaseline(currdir + "egg1.out", currdir + "egg1.jsn") if yaml_available: pyutilib.subprocess.run( [sys.executable, currdir + os.sep + "egg1.py", currdir, "yaml"]) self.assertMatchesYamlBaseline(currdir + "egg1.out", currdir + "egg1.yml") def test_egg2(self): """Load an egg for the 'project1' project. Eggs are loaded in the 'eggs1' and 'eggs2' directories, but only the Project1 and Project 3 stuff is actually imported.""" pyutilib.subprocess.run( [sys.executable, currdir + os.sep + "egg2.py", currdir, "json"]) self.assertMatchesJsonBaseline(currdir + "egg2.out", currdir + "egg2.jsn") if yaml_available: pyutilib.subprocess.run( [sys.executable, currdir + os.sep + "egg2.py", currdir, "yaml"]) self.assertMatchesYamlBaseline(currdir + "egg2.out", currdir + "egg2.yml") # Apply class decorator explicitly, which works in Python 2.5 Test = unittest.skipIf(not pkg_resources_avail, "Cannot import 'pkg_resources'")(Test) if __name__ == "__main__": unittest.main()
def test13(self): dirname = currdir + 'import_data' + os.sep context = {} m = pyutilib.misc.import_file(dirname + 'tfile1.0', context=context) self.assertEqual(id(m), id(context['tfile1.0'])) self.assertEqual(m.f(), 'tfile1.0') def test13a(self): dirname = currdir + 'import_data' + os.sep context = {} m = pyutilib.misc.import_file(dirname + 'tfile1.0', context=context, name='junk') self.assertEqual(id(m), id(context['junk'])) self.assertEqual(m.f(), 'tfile1.0') def test14(self): context = {} m = pyutilib.misc.import_file( 'pyutilib.misc.tests.import_data.a.tfile', context=context) self.assertEqual( id(m), id(context['pyutilib.misc.tests.import_data.a.tfile'])) self.assertEqual(m.f(), 'a') # Apply decorator explicitly TestRunFile = unittest.skipIf(not _runpy, "Cannot import 'runpy'")(TestRunFile) if __name__ == "__main__": unittest.main()
[sys.executable, currdir + os.sep + "egg1.py", currdir, "json"]) self.assertMatchesJsonBaseline(currdir + "egg1.out", currdir + "egg1.jsn") if yaml_available: pyutilib.subprocess.run([ sys.executable, currdir + os.sep + "egg1.py", currdir, "yaml" ]) self.assertMatchesYamlBaseline(currdir + "egg1.out", currdir + "egg1.yml") def test_egg2(self): """Load an egg for the 'project1' project. Eggs are loaded in the 'eggs1' and 'eggs2' directories, but only the Project1 and Project 3 stuff is actually imported.""" pyutilib.subprocess.run( [sys.executable, currdir + os.sep + "egg2.py", currdir, "json"]) self.assertMatchesJsonBaseline(currdir + "egg2.out", currdir + "egg2.jsn") if yaml_available: pyutilib.subprocess.run([ sys.executable, currdir + os.sep + "egg2.py", currdir, "yaml" ]) self.assertMatchesYamlBaseline(currdir + "egg2.out", currdir + "egg2.yml") # Apply class decorator explicitly, which works in Python 2.5 Test = unittest.skipIf(not pkg_resources_avail, "Cannot import 'pkg_resources'")(Test) if __name__ == "__main__": unittest.main()
sys.path.remove(dirname) def test13(self): dirname = currdir + 'import_data' + os.sep context = {} m = pyutilib.misc.import_file(dirname + 'tfile1.0', context=context) self.assertEqual(id(m), id(context['tfile1.0'])) self.assertEqual(m.f(), 'tfile1.0') def test13a(self): dirname = currdir + 'import_data' + os.sep context = {} m = pyutilib.misc.import_file( dirname + 'tfile1.0', context=context, name='junk') self.assertEqual(id(m), id(context['junk'])) self.assertEqual(m.f(), 'tfile1.0') def test14(self): context = {} m = pyutilib.misc.import_file( 'pyutilib.misc.tests.import_data.a.tfile', context=context) self.assertEqual( id(m), id(context['pyutilib.misc.tests.import_data.a.tfile'])) self.assertEqual(m.f(), 'a') # Apply decorator explicitly TestRunFile = unittest.skipIf(not _runpy, "Cannot import 'runpy'")(TestRunFile) if __name__ == "__main__": unittest.main()