def test_global_abort_on_failure(self): with utils.RecipeDir() as recipes_dir: fname = self.create_recipe_in_repo(recipes_dir, "pr.cfg", "recipe.cfg") reader = RecipeReader(recipes_dir, fname) reader.config.remove_option('Step 1', 'abort_on_failure') reader.config['Global Environment']['abort_on_failure'] = 'true' reader.read() self.assertEqual(reader.recipe['steps'][0]['abort_on_failure'], True)
def test_read_private(self): with utils.RecipeDir() as recipes_dir: fname = self.create_recipe_in_repo(recipes_dir, "recipe_private.cfg", "private.cfg") reader = RecipeReader(recipes_dir, fname) r = reader.read() self.assertEqual(reader.check(), True) self.assertEqual(r["private"], True) self.assertEqual(r["viewable_by_teams"], ["idaholab/MOOSE TEAM", "idaholab/OTHER TEAM"])
def read_recipes(self): """ Converts all the recipes found by get_recipe_files() and converts them into dicts Return: list of recipe dicts """ all_recipes = [] for recipe_file in self.get_recipe_files(): reader = RecipeReader(self.recipe_dir, recipe_file) recipe = reader.read() if recipe: all_recipes.append(recipe) else: raise InvalidRecipe(recipe_file) if not self.check_dependencies(all_recipes): raise InvalidDependency("Invalid dependencies!") return all_recipes
def test_misc(self): with utils.RecipeDir() as recipes_dir: fname = self.create_recipe_in_repo(recipes_dir, "recipe_private.cfg", "private.cfg") reader = RecipeReader(recipes_dir, fname) self.assertEqual(reader.get_option("does not exist", "foo", 1), 1) self.assertEqual(reader.get_option("Main", "automatic", 2), 2) self.assertTrue(reader.set_steps()) reader.config.add_section("BadSection") self.assertFalse(reader.set_steps()) self.assertEqual(reader.read(), {}) reader.config.set("BadSection", "script", "scripts/2.sh") self.assertTrue(reader.set_steps()) self.assertNotEqual(reader.read(), {}) reader.config.set("Main", "name", "") self.assertEqual(reader.read(), {})
def test_parse_repo(self): with utils.RecipeDir() as recipes_dir: fname = self.create_recipe_in_repo(recipes_dir, "recipe_private.cfg", "private.cfg") reader = RecipeReader(recipes_dir, fname) r = reader.read() self.assertEqual(reader.check(), True) self.assertEqual(r["repository_server"], "dummy_git_server") self.assertEqual(r["repository_owner"], "idaholab") self.assertEqual(r["repository_name"], "civet") d = reader.parse_repo("[email protected]:idaholab/civet") self.check_repo(d) d = reader.parse_repo("[email protected]:idaholab/civet.git") self.check_repo(d) d = reader.parse_repo("https://github.com/idaholab/civet.git") self.check_repo(d) d = reader.parse_repo("https://github.com/idaholab/civet") self.check_repo(d) d = reader.parse_repo("https://github.com:idaholab/civet") self.assertEqual(d, None)
def test_write(self): with utils.RecipeDir() as recipe_dir: fname = self.create_recipe_in_repo(recipe_dir, "recipe_all.cfg", "recipe.cfg") self.create_recipe_in_repo(recipe_dir, "recipe_push.cfg", "push_dep.cfg") self.create_recipe_in_repo(recipe_dir, "recipe_pr.cfg", "pr_dep.cfg") self.write_script_to_repo(recipe_dir, "contents", "1.sh") self.write_script_to_repo(recipe_dir, "contents", "2.sh") reader = RecipeReader(recipe_dir, fname) r = reader.read() self.assertEqual(r.get("repository"), "git@dummy_git_server:idaholab/civet.git") r["repository"] = "new_repo" global_env = r.get("global_env") self.assertEqual(len(global_env), 2) r["global_env"]["APPLICATION_NAME"] = "new_app" global_sources = r.get("global_sources") self.assertEqual(len(global_sources), 2) r["global_sources"][0] = "new_source" deps = r.get("pullrequest_dependencies") self.assertEqual(len(deps), 1) r["pullrequest_dependencies"][0] = "new_dep" steps = r.get("steps") self.assertEqual(len(steps), 2) r["steps"][0]["name"] = "new_step" self.assertTrue( RecipeWriter.write_recipe_to_repo(recipe_dir, r, "new_file.cfg")) reader = RecipeReader(recipe_dir, "new_file.cfg") r = reader.read() # we changed the source and the dep so now the recipe doesn't pass the check. self.assertEqual(r, {}) r = reader.read(do_check=False) self.assertEqual(r["repository"], "new_repo") self.assertEqual(r["global_env"]["APPLICATION_NAME"], "new_app") self.assertEqual(r["global_sources"][0], "new_source") self.assertEqual(r["pullrequest_dependencies"][0], "new_dep") self.assertEqual(r["steps"][0]["name"], "new_step") self.assertFalse( RecipeWriter.write_recipe_to_repo('/foo', r, '../bar'))
def test_check(self): with utils.RecipeDir() as recipes_dir: fname = self.create_recipe_in_repo(recipes_dir, "recipe_all.cfg", "recipe.cfg") self.create_recipe_in_repo(recipes_dir, "pr_dep.cfg", "pr_dep.cfg") reader = RecipeReader(recipes_dir, fname) r = reader.read() # should fail since dependency is not there self.assertEqual(reader.check(), False) self.assertEqual(r, {}) self.create_recipe_in_repo(recipes_dir, "push_dep.cfg", "push_dep.cfg") r = reader.read() self.assertEqual(reader.check(), True) self.assertNotEqual(r, {}) good_recipe = reader.recipe.copy() reader.recipe["display_name"] = "" self.assertEqual(reader.check(), True) self.assertEqual(reader.recipe["display_name"], reader.recipe["name"]) reader.recipe["automatic"] = "foo" self.assertEqual(reader.check(), False) reader.recipe = good_recipe.copy() reader.recipe["trigger_pull_request"] = False reader.recipe["trigger_push"] = False reader.recipe["trigger_manual"] = False reader.recipe["allow_on_pr"] = False reader.recipe["trigger_release"] = False self.assertEqual(reader.check(), False) reader.recipe = good_recipe.copy() reader.recipe["trigger_pull_request"] = True reader.recipe["allow_on_pr"] = True self.assertEqual(reader.check(), False) reader.recipe = good_recipe.copy() reader.recipe["trigger_push"] = True reader.recipe["trigger_push_branch"] = "" self.assertEqual(reader.check(), False) reader.recipe = good_recipe.copy() reader.recipe["trigger_manual"] = True reader.recipe["trigger_manual_branch"] = "" self.assertEqual(reader.check(), False) reader.recipe = good_recipe.copy() reader.recipe["sha"] = "" self.assertEqual(reader.check(), False) reader.recipe = good_recipe.copy() reader.recipe["repo_sha"] = "" self.assertEqual(reader.check(), False) reader.recipe = good_recipe.copy() reader.recipe["build_configs"] = [] self.assertEqual(reader.check(), False) reader.recipe = good_recipe.copy() reader.recipe["repository_owner"] = "" self.assertEqual(reader.check(), False) reader.recipe = good_recipe.copy() reader.recipe["global_sources"] = ["not a file"] self.assertEqual(reader.check(), False) reader.recipe = good_recipe.copy() reader.recipe["pullrequest_dependencies"] = ["not a file"] self.assertEqual(reader.check(), False) reader.recipe["pullrequest_dependencies"] = [fname] self.assertEqual(reader.check(), False) reader.recipe = good_recipe.copy() reader.recipe["push_dependencies"] = ["not a file"] self.assertEqual(reader.check(), False) reader.recipe["push_dependencies"] = [fname] self.assertEqual(reader.check(), False) reader.recipe = good_recipe.copy() reader.recipe["manual_dependencies"] = ["not a file"] self.assertEqual(reader.check(), False) reader.recipe["manual_dependencies"] = [fname] self.assertEqual(reader.check(), False) reader.recipe = good_recipe.copy() reader.recipe["release_dependencies"] = ["not a file"] self.assertEqual(reader.check(), False) reader.recipe["release_dependencies"] = [fname] self.assertEqual(reader.check(), False) reader.recipe = good_recipe.copy() reader.recipe["steps"] = [] self.assertEqual(reader.check(), False) reader.recipe = good_recipe.copy() reader.recipe["steps"][0]["script"] = "not a file" self.assertEqual(reader.check(), False)
def test_no_file(self): with utils.RecipeDir() as recipes_dir: with self.assertRaises(Exception): RecipeReader(recipes_dir, "no_exist")
def test_read(self): with utils.RecipeDir() as recipes_dir: fname = self.create_recipe_in_repo(recipes_dir, "recipe_all.cfg", "recipe.cfg") self.create_recipe_in_repo(recipes_dir, "push_dep.cfg", "push_dep.cfg") self.create_recipe_in_repo(recipes_dir, "recipe_extra.cfg", "extra.cfg") reader = RecipeReader(recipes_dir, fname) # should fail since dependency is not there r = reader.read() self.assertEqual(reader.check(), False) self.assertEqual(r, {}) self.create_recipe_in_repo(recipes_dir, "pr_dep.cfg", "pr_dep.cfg") r = reader.read() self.assertEqual(reader.check(), True) self.assertEqual(r.get("name"), "Recipe with everything") self.assertEqual(r.get("display_name"), "Recipe with everything") self.assertEqual(len(r.get("sha")), 40) self.assertEqual(len(r.get("repo_sha")), 40) self.assertEqual(r.get("repository"), "git@dummy_git_server:idaholab/civet.git") self.assertEqual(r.get("private"), False) self.assertEqual(r.get("active"), True) self.assertEqual(r.get("automatic"), "authorized") self.assertEqual(r.get("build_user"), "moosebuild") self.assertEqual(r.get("build_configs"), ["linux-gnu"]) self.assertEqual(r.get("trigger_push"), True) self.assertEqual(r.get("trigger_push_branch"), "devel") self.assertEqual(r.get("priority_push"), 1) self.assertEqual(r.get("trigger_pull_request"), True) self.assertEqual(r.get("priority_pull_request"), 2) self.assertEqual(r.get("trigger_manual"), True) self.assertEqual(r.get("trigger_manual_branch"), "devel") self.assertEqual(r.get("priority_manual"), 3) self.assertEqual(r.get("allow_on_pr"), False) global_env = r.get("global_env") self.assertEqual(len(global_env), 2) self.assertEqual(global_env.get("APPLICATION_NAME"), "civet") self.assertEqual(global_env.get("MOOSE_DIR"), "BUILD_ROOT/moose") global_sources = r.get("global_sources") self.assertEqual(len(global_sources), 2) self.assertEqual(global_sources, ["scripts/1.sh", "scripts/2.sh"]) pr_deps = r.get("pullrequest_dependencies") self.assertEqual(len(pr_deps), 1) self.assertEqual(pr_deps, ["recipes/pr_dep.cfg"]) push_deps = r.get("push_dependencies") self.assertEqual(len(push_deps), 1) self.assertEqual(push_deps, ["recipes/push_dep.cfg"]) manual_deps = r.get("manual_dependencies") self.assertEqual(len(manual_deps), 0) steps = r.get("steps") self.assertEqual(len(steps), 2) self.assertEqual(steps[0].get("name"), "Pre Test") self.assertEqual(steps[0].get("script"), "scripts/1.sh") self.assertEqual(steps[0].get("abort_on_failure"), True) self.assertEqual(steps[0].get("allowed_to_fail"), True) self.assertEqual(len(steps[0].get("environment")), 4) self.assertEqual(steps[0].get("environment").get("FOO"), "bar") self.assertEqual(steps[1].get("name"), "Next Step") self.assertEqual(steps[1].get("script"), "scripts/2.sh") self.assertEqual(steps[1].get("abort_on_failure"), False) self.assertEqual(steps[1].get("allowed_to_fail"), False) self.assertEqual(len(steps[1].get("environment")), 4) self.assertEqual(steps[1].get("environment").get("ENV"), "some string")