def test_get_matrix_variables(self): given = ["_A=a1", "_A=a2", "_B=b1", "_B=b2", "_B=b3", "_C=c1"] expected = { "A": ["a1", "a2"], "B": ["b1", "b2", "b3"], "C": ["c1"], } self.assertEqual(expected, WorkflowExporter._get_matrix_variables(given)) self.assertEqual({}, WorkflowExporter._get_matrix_variables([]))
def test_gitlab(self): subs = ["_A=a1", "_A=a2", "_B=b1", "_B=b2", "_B=b3", "_C=c1"] repo = self.mk_repo() pwd = os.getcwd() os.chdir(repo.working_dir) e = WorkflowExporter.get_exporter("gitlab") e.export("wf.yml", subs) self.assertTrue(os.path.isfile(".gitlab-ci.yml")) dictionary = { "A": ["a1", "a2"], "B": ["b1", "b2", "b3"], "C": ["c1"], } expected_dict = str(dictionary) with open(".gitlab-ci.yml", "r") as f: content = f.read() if expected_dict in content: self.assertTrue(expected_dict in content) self.assertTrue("-s _A=$A -s _B=$B -s _C=$C" in content) self.assertTrue(f"getpopper/popper:v{__version__}" in content) os.chdir(pwd)
def test_travis(self): subs = ["_A=a1", "_A=a2", "_B=b1", "_B=b2", "_B=b3", "_C=c1"] repo = self.mk_repo() pwd = os.getcwd() os.chdir(repo.working_dir) e = WorkflowExporter.get_exporter("travis") e.export("wf.yml", subs) self.assertTrue(os.path.isfile(".travis.yml")) expected_env_items = [ "A=a1 B=b1 C=c1", "A=a1 B=b2 C=c1", "A=a1 B=b3 C=c1", "A=a2 B=b1 C=c1", "A=a2 B=b2 C=c1", "A=a2 B=b3 C=c1", ] with open(".travis.yml", "r") as f: content = f.read() for e in expected_env_items: self.assertTrue(e in content) self.assertTrue("-s _A=$A -s _B=$B -s _C=$C" in content) self.assertTrue(f"getpopper/popper:v{__version__}" in content) os.chdir(pwd)
def cli(ctx, service, file, substitution): """Generates configuration files for distinct CI services. This command needs to be executed on the root of your Git repository folder. """ if not os.path.exists(".git"): log.fail("This command needs to be executed on the root of your " "Git project folder (where the .git/ folder is located).") exporter = WorkflowExporter.get_exporter(service) exporter.export(file, substitution) log.info(f"Wrote {service} configuration successfully.")
def test_get_matrix(self): given = { "A": ["a1", "a2"], "B": ["b1", "b2", "b3"], "C": ["c1"], } expected = [ {"A": "a1", "B": "b1", "C": "c1"}, {"A": "a1", "B": "b2", "C": "c1"}, {"A": "a1", "B": "b3", "C": "c1"}, {"A": "a2", "B": "b1", "C": "c1"}, {"A": "a2", "B": "b2", "C": "c1"}, {"A": "a2", "B": "b3", "C": "c1"}, ] self.assertEqual(expected, list(WorkflowExporter._get_matrix(given)))