def test_107_changelog_skipping(self): """ Test the case when sourceX is name and we use f-r -n so that file gets mixed up with a directory """ self.init_test('test_regressions', argv=['-rn', self.srpm_file]) spec = SpecFile(self.spec_file) regex = re.compile('initial fedora') self.assertEqual(len(spec.find_all_re(regex)), 2) self.assertEqual(len(spec.find_all_re(regex, True)), 1)
def test_spec_file(self): ''' Test the SpecFile class''' def fix_usr_link(path): ''' Convert absolute paths to /usr/path. ''' if not '/' in path: return path lead = path.split('/')[1] if lead in ['bin', 'sbin', 'lib', 'lib64']: return '/usr' + path return path self.init_test('test_misc', argv=['-n', 'python-test', '--no-build']) spec = SpecFile(os.path.join(os.getcwd(), 'python-test.spec')) self.assertEqual(spec.name, 'python-test') self.assertEqual(spec.version, '1.0') dist = Mock.get_macro('%dist', None, {}) self.assertEqual(spec.release, '1' + dist) self.assertEqual(spec.expand_tag('Release'), '1' + dist) self.assertEqual(spec.expand_tag('License'), 'GPLv2+') self.assertEqual(spec.expand_tag('Group'), 'Development/Languages') # Test rpm value not there self.assertEqual(spec.expand_tag('PreReq'), None) # Test get sections expected = ['rm -rf $RPM_BUILD_ROOT'] self.assertEqual(spec.get_section('%clean'), expected) expected = '%{__python} setup.py build' expected = ['LANG=C', 'export LANG', 'unset DISPLAY', '/usr/bin/python setup.py build'] build = spec.get_section('%build') build = map(fix_usr_link, build) self.assertIn(''.join(build), ''.join(expected)) install = spec.get_section('%install') install = map(fix_usr_link, install) expected = ['LANG=C', 'export LANG', 'unset DISPLAY', 'rm -rf $RPM_BUILD_ROOT', '/usr/bin/python setup.py install -O1 --skip-build' ' --root $RPM_BUILD_ROOT'] self.assertIn(''.join(install), ''.join(expected)) # Test get_sources (return the Source/Patch lines with macros resolved) expected = {'Source0': 'http://timlau.fedorapeople.org/' 'files/test/review-test/python-test-1.0.tar.gz'} self.assertEqual(spec.sources_by_tag, expected) expected = ['%defattr(-,root,root,-)', '%doc COPYING', rpm.expandMacro('%{python_sitelib}') + '/*'] self.assertEqual(spec.get_files(), expected) # Test find regex = re.compile(r'^Release\s*:\s*(.*)') res = spec.find_re(regex) if res: self.assertEqual(res.split(':')[1].strip(), '1%{?dist}') else: self.assertTrue(False)