def test_commandline_generate_model_run_report_with_targetdir(self): # test the -t option for a smaller selection of yaml file d = defaults() sp = d['paths']['tested_records'] here = Path('.') rec_list = [rec for rec in sp.glob('*.yaml')] #test_list= rec_list test_list = sorted(rec_list)[2:3] targetDirName = 'output' targetPath = here.joinpath(targetDirName) targetPath.mkdir(parents=True, exist_ok=True) test_list = sorted(rec_list)[0:1] result_list = [ runProtected(rec, ['generate_model_run_report', "-t", targetDirName], targetPath) for rec in test_list ] failure_list = [ r for r in result_list if r['returnValue'] != 0 or r['fileExists'] == False ] self.assertEqual(len(failure_list), 0, msg="The following files caused problems %s" % str(failure_list))
def test_create_old_overview_report(self): # fixme: # The tested method is deprecated and should be replaced by templates as soon as possible. # we create a target directory populated with only a few files and create a overview html from it d = defaults() #sp=d['paths']['tested_records'] sp = d['paths']['tested_records'].parent.joinpath('VerosTestModels') src_dir_name = 'localDataBase' src_dir_path = Path(src_dir_name) src_dir_path.mkdir() rec_list = [rec for rec in sp.glob('*.yaml')] #[0:2] for rec in rec_list: src = str(sp.joinpath(rec)) target = (src_dir_name) shutil.copy(src, src_dir_name) ml = ModelList.from_dir_path(src_dir_path) target_dir_path = Path('.').joinpath('html') targetFileName = 'overview.html' create_overview_report(ml, target_dir_path, targetFileName) targetPath = target_dir_path.joinpath(targetFileName) self.assertTrue(targetPath.exists())
def test_commandline_generate_model_run_report_single_file(self): # This function is more of a tool to test a # specific selectable yaml file # than an active automatic test. # Usually the specific file will be tested by one of the # more comprehensive tests that iterate over all our model files. d = defaults() sp = d['paths']['tested_records'] here = Path('.') rec_list = [rec for rec in sp.glob('*.yaml')] test_list = rec_list #test_list=['Allison2010NatureGeoscience.yaml'] targetDirName = 'output' targetPath = here.joinpath(targetDirName) targetPath.mkdir(parents=True, exist_ok=True) result_list = [ runProtected(rec, ['generate_model_run_report', "-t", targetDirName], targetPath) for rec in test_list ] failure_list = [ r for r in result_list if r['returnValue'] != 0 or r['fileExists'] == False ] self.assertEqual(len(failure_list), 0, msg="The following files caused problems %s" % str(failure_list))
def f(rec): #command_list=['generate_model_run_report'] d = defaults() tp = d['paths']['report_templates'].joinpath( "CompleteSingleModelReport.py") print("1 ###################") print(tp.absolute()) command_list = ['render'] result = runProtected(rec, command_list) return result
def table(request): from bgc_md.ModelList import ModelList from bgc_md.reports import defaults d=defaults() source_dir_path=d['paths']['tested_records'] ml=ModelList.from_dir_path(src_dir_path) target_dir_path=Path('.').joinpath('html') targetFileName='table.html' rel=ml.create_overview_table(target_dir_path,targetFileName) return HttpResponse('Test')
def test_flagstaff_templates_commandline(self): d = defaults() sp = d['paths']['data'].joinpath('FlagstaffTemplates') tp = d['paths']['report_templates'].joinpath( 'single_model', 'FlagstaffVegetationTemplate.py') rec_list = [rec for rec in sp.glob('*.yaml')] #[0:2] for rec in rec_list: #print(rec) run([ "render", str(tp.absolute()), "-y", str(rec.absolute()), "-t", "." ])
def test_website_from_template(self): d = defaults() sp = d['paths']['tested_records'].parent.joinpath('TestModels_1') model_list = ModelList.from_dir_path(sp) list_tp = d['paths']['report_templates'].joinpath( 'multiple_model', 'Website.py') #rel=render(list_tp,model_list=model_list) rel = render(list_tp, model_list) target_dir_path = Path('.') target_dir_path.mkdir(parents=True, exist_ok=True) targetFileName = 'overview.html' rel.write_pandoc_html(target_dir_path.joinpath(targetFileName))
def test_report_template_single_model(self): d = defaults() sp = d['paths']['tested_records'].parent.joinpath( 'TestModels_1').joinpath('Williams2005GCB.yaml') tp = d['paths']['report_templates'].joinpath('single_model', 'MinimalSingleReport.py') model = Model.from_path(sp) rel = render(tp, model) target_dir_path = Path('.').joinpath('html') target_dir_path.mkdir(parents=True, exist_ok=True) targetFileName = 'Report.html' rel.write_pandoc_html(target_dir_path.joinpath(targetFileName))
def test_commandline_gnerate_website(self): # we create a target directory populated with only a few files and create a website from it d = defaults() sp = d['paths']['tested_records'] src_dir_name = 'localDataBase' src_dir_path = Path(src_dir_name) src_dir_path.mkdir() rec_list = sorted([rec for rec in sp.glob('*.yaml')])[2:3] for rec in rec_list: print(rec) src = (sp.joinpath(rec)).as_posix() target = (src_dir_name) shutil.copy(src, src_dir_name) res = run(['generate_website', '-s', src_dir_name], check=True)
def test_commandline_generate_model_run_report(self): d = defaults() sp = d['paths']['tested_records'] rec_list = [rec for rec in sp.glob('*.yaml')] test_list = rec_list #test_list= sorted(rec_list)[2:3] pool = Pool(processes=1) result_list = pool.map(f, test_list) # failure_list = [ r for r in result_list if r['returnValue'] != 0 or r['fileExists'] == False ] self.assertEqual(len(failure_list), 0, msg="The following files caused problems %s" % str(failure_list))
def test_create_overview_table(self): # we create a target directory populated with only a few files and create a overview html from it d = defaults() sp = d['paths']['tested_records'] src_dir_name = 'localDataBase' src_dir_path = Path(src_dir_name) src_dir_path.mkdir() rec_list = [rec for rec in sp.glob('*.yaml')][0:1] for rec in rec_list: print(rec) src = (sp.joinpath(rec)).as_posix() target = (src_dir_name) shutil.copy(src, src_dir_name) ml = ModelList.from_dir_path(src_dir_path) target_dir_path = Path('.').joinpath('html') rel = ml.create_overview_table(target_dir_path) targetFileName = 'table.html' targetPath = target_dir_path.joinpath(targetFileName) rel.write_pandoc_html(targetPath) print(targetPath) self.assertTrue(targetPath.exists())
def setUp(self): this = Path(__file__).parents[1] #the package dir vegModelPath = defaults()['paths'][ 'veg'] ### Fix me!!! Temporarily changed Vegetation for Test self.ml = ModelList.from_dir_path(vegModelPath)