def test_getReferences_hasTwoReferences_returnsThem(self): sut = ProjectFile(None, None) sut.add_reference('A') sut.add_reference('B') self.assertEquals({'A', 'B'}, set( map(lambda x: x.get_variable_name(), sut.get_references())))
def find_playbooks(self, path, config): for f in os.listdir(path): file_name, file_extension = os.path.splitext(f) full_path = os.path.join(path, f) if os.path.isfile(full_path) and file_extension == ".yml": b = basename(file_name) self.playbooks[b] = ProjectFile(full_path, config)
def test_getReferences_twoProjectFiles_mergesThem(self): p1 = ProjectFile(None, None) p1.add_reference('A') p1.add_reference('B') p2 = ProjectFile(None, None) p2.add_reference('A') p2.add_reference('C') sut = Role("", None, None) sut.add_file(p1) sut.add_file(p2) names = set(map(lambda x: x.get_variable_name(), sut.get_references())) self.assertEquals(set(['A', 'B', 'C']), names)
def read_children(self, path, config): self.trace("read_children %s" % path) for f in os.listdir(path): file_name, file_extension = os.path.splitext(f) full_path = os.path.join(path, f) if os.path.isfile(full_path) and file_extension == ".yml": child_file = ProjectFile(full_path, config) self.add_file(child_file) child_file.parse_from_yaml() elif os.path.isfile(full_path) and (file_extension == ".j2" or "templates" in path): child_file = ProjectFile(full_path, config) self.add_file(child_file) child_file.parse_from_text() elif os.path.isdir(full_path): self.read_children(full_path, config) else: self.trace("IGNORING: %s" % path)
def test_getDefaults_twoProjectFiles_mergesThem(self): p1 = ProjectFile(None, None) p1.add_default('A', '1') p1.add_default('B', '2') p2 = ProjectFile(None, None) p2.add_default('A', '3') p2.add_default('C', '4') sut = Role("", None, None) sut.add_file(p1) sut.add_file(p2) r1 = VariableDefault('A', '1', None) r2 = VariableDefault('B', '2', None) r3 = VariableDefault('A', '3', None) r4 = VariableDefault('C', '4', None) self.assertEquals(set([r1, r2, r3, r4]), sut.get_defaults())
def test_getReferences_referenceInJ2_findsIt(self): path = os.getcwd() + "/test/artifacts/template2.xml.j2" sut = ProjectFile(path, None) sut.parse_from_yaml() self.assertTrue('tree1' in map(lambda x: x.get_variable_name(), sut.get_references()))
def test_getReferences_referenceInYaml_findsIt(self): path = os.getcwd() + "/test/artifacts/playbook1.yml" sut = ProjectFile(path, None) sut.parse_from_yaml() self.assertTrue('test_var_1' in map(lambda x: x.get_variable_name(), sut.get_references()))
def test_getDefaults_hasOneDefault_returnsIt(self): sut = ProjectFile(None, None) sut.add_default('A', '1') self.assertEqual(set([VariableDefault('A', '1', None)]), sut.get_defaults())
def test_getFile_constructedWithFile_returnsIt(self): sut = ProjectFile(self.temp_file.name, None) self.assertEqual(self.temp_file.name, sut.get_file())