def exec_pom_macro(line, poms_tree, want_tree=None, filename='pom.xml'): """ Parameters: line:: A line of spec code injected to %prep poms_tree:: dictionary that maps subpackage directory paths to input poms want_tree:: dictionary that maps subpackage directory paths to wanted poms (in want directory) It creates a directory structure corresponding to keys in poms_tree and copies pom files into it. Then it executes prep and compares altered poms to wanted ones from want_tree (if not specified in want_tree it is assumed to remain unchanged and is compared with the original pom). Returns tuple of rpmbuild's return value, stderr and report of differences in xml files. """ DATADIR = path.join(DIRPATH, 'data', 'pom_editor') pack = Package('test') pack.append_to_prep(line) for destpath, sourcepath in poms_tree.items(): pack.add_source(path.join(DATADIR, sourcepath), path.join(destpath, filename)) _, stderr, return_value = pack.run_prep() reports = [] if return_value == 0: for filepath, pom in poms_tree.items(): if want_tree and filepath in want_tree: expected_pom = path.join('want', want_tree[filepath]) else: expected_pom = pom expected_pom = path.join(DATADIR, expected_pom) actual_pom = path.join(pack.buildpath, filepath, filename) reports.append(compare_xml_files(actual_pom, expected_pom)) return return_value, stderr, '\n'.join(reports).strip()
def test_wildcard(self, stdout, stderr, return_value): self.assertEqual(return_value, 0, stderr) filelist = get_config_file_list() self.assertEqual(len(filelist), 1) for filename in filelist: report = compare_xml_files(get_actual_config(filename), get_expected_config(filename, 'mvn_file', 'wildcard'), ['artifactGlob']) self.assertFalse(report, '\n' + report)
def test_odd(self, stdout, stderr, return_value): self.assertEqual(return_value, 0, stderr) filelist = get_config_file_list() self.assertEqual(len(filelist), 1) for filename in filelist: report = compare_xml_files( get_actual_config(filename), get_expected_config(filename, 'mvn_alias', 'odd'), unordered) self.assertFalse(report, '\n' + report)
def test_comb2(self, stdout, stderr, return_value): self.assertEqual(return_value, 0, stderr) filelist = get_config_file_list() self.assertEqual(len(filelist), 1) for filename in filelist: report = compare_xml_files(get_actual_config(filename), get_expected_config(filename, 'mvn_alias', 'comb2'), unordered) self.assertFalse(report, '\n' + report)
def test_xml3(self, stdout, stderr, return_value): self.assertEqual(return_value, 0, stderr) filelist = get_config_file_list() self.assertEqual(len(filelist), 1) for filename in filelist: report = compare_xml_files(get_actual_config(filename), get_expected_config(filename, 'mvn_config', 'xml3'), ['artifactGlob']) self.assertFalse(report, '\n' + report)
def test_mvn_config_path(self, pack): pack.append_to_prep('%mvn_config a/b/c xxx') _, stderr, return_value = pack.run_prep() self.assertEqual(return_value, 0, stderr) confpath = os.path.join(pack.buildpath, '.xmvn', 'config.d') filelist = os.listdir(confpath) self.assertEqual(len(filelist), 1) actfile = os.path.join(confpath, filelist[0]) expfile = os.path.join(DIRPATH, 'data', 'mvn_config', 'path_00001.xml') report = compare_xml_files(actfile, expfile, unordered) self.assertEqual(report, '', report)
def test_mvn_file_simple(self, pack): pack.append_to_prep('%mvn_file :x file') _, stderr, return_value = pack.run_prep() self.assertEqual(return_value, 0, stderr) confpath = os.path.join(pack.buildpath, '.xmvn', 'config.d') filelist = os.listdir(confpath) self.assertEqual(len(filelist), 1) actfile = os.path.join(confpath, filelist[0]) expfile = os.path.join(DIRPATH, 'data', 'mvn_file', 'simple_00001.xml') report = compare_xml_files(actfile, expfile, unordered) self.assertEqual(report, '', report)
def test_mvn_alias_backref(self, pack): pack.append_to_prep("""%mvn_alias '*:{aaa,bbb}*' ':@1'""") _, stderr, return_value = pack.run_prep() self.assertEqual(return_value, 0, stderr) confpath = os.path.join(pack.buildpath, '.xmvn', 'config.d') filelist = os.listdir(confpath) self.assertEqual(len(filelist), 1) actfile = os.path.join(confpath, filelist[0]) expfile = os.path.join(DIRPATH, 'data', 'mvn_alias', 'backref_00001.xml') report = compare_xml_files(actfile, expfile, unordered) self.assertEqual(report, '', report)
def test_mvn_config_multiline(self, pack): pack.append_to_prep("""%mvn_config a/b/c " <bla> bla </bla> " """) _, stderr, return_value = pack.run_prep() self.assertEqual(return_value, 0, stderr) confpath = os.path.join(pack.buildpath, '.xmvn', 'config.d') filelist = os.listdir(confpath) self.assertEqual(len(filelist), 1) actfile = os.path.join(confpath, filelist[0]) expfile = os.path.join(DIRPATH, 'data', 'mvn_config', 'multiline_00001.xml') report = compare_xml_files(actfile, expfile, unordered) self.assertEqual(report, '', report)
def test_mvn_build_singleton(self, pack): pack.append_to_build('%mvn_build -s') _, stderr, return_value = pack.run_build() self.assertEqual(return_value, 0, stderr) confpath = os.path.join(pack.buildpath, '.xmvn', 'config.d') filelist = sorted(os.listdir(confpath)) self.assertEqual(len(filelist), 2) for i in range(2): actfile = os.path.join(confpath, filelist[i]) filename = 'singleton_0000{i}.xml'.format(i=i + 1) expfile = os.path.join(DIRPATH, 'data', 'mvn_build', filename) report = compare_xml_files(actfile, expfile, unordered) self.assertEqual(report, '', report) expfile = os.path.join(pack.buildpath, '.xmvn', 'out') actfile = os.path.join(DIRPATH, 'data', 'mvn_build', 'singleton_out') with open(actfile, 'r') as act: with open(expfile, 'r') as exp: self.assertEqual(act.read(), exp.read())
def check_result(pom_path): wantpath = '{pom}-want'.format(pom=os.path.basename(pom_path)) report = compare_xml_files(pom_path, wantpath) res = not report return report, res