Exemplo n.º 1
0
 def test_spec_file(self):
     ''' Test the SpecFile class'''
     ReviewDirs.reset()
     ReviewDirs.workdir_setup('.', True)
     dest = Mock.get_builddir('SOURCES')
     if not os.path.exists(dest):
         os.makedirs(dest)
     self.helpers._get_file(TEST_SPEC, Mock.get_builddir('SOURCES'))
     spec = SpecFile(self.spec_file)
     # Test misc rpm values (Macro resolved)
     self.assertEqual(spec.name, 'python-test')
     self.assertEqual(spec.version, '1.0')
     # resolve the dist-tag
     dist = self.helpers._run_cmd('rpm --eval %dist')[:-1]
     self.assertEqual(spec.release, '1' + dist)
     # test misc rpm values (without macro resolve)
     self.assertEqual(spec.find_tag('Release'), ['1%{?dist}'])
     self.assertEqual(spec.find_tag('License'), ['GPLv2+'])
     self.assertEqual(spec.find_tag('Group'), ['Development/Languages'])
     # Test rpm value not there
     self.assertEqual(spec.find_tag('PreReq'), [])
     # Test get sections
     expected = {'%clean': ['rm -rf $RPM_BUILD_ROOT']}
     self.assertEqual(spec.get_section('%clean'), expected)
     expected = {'%build': ['%{__python} setup.py build']}
     self.assertEqual(spec.get_section('%build'), expected)
     expected = {
         '%install': [
             'rm -rf $RPM_BUILD_ROOT',
             '%{__python} setup.py install -O1 --skip-build'
             ' --root $RPM_BUILD_ROOT'
         ]
     }
     self.assertEqual(spec.get_section('%install'), expected)
     expected = {
         '%files':
         ['%defattr(-,root,root,-)', '%doc COPYING', '%{python_sitelib}/*']
     }
     self.assertEqual(spec.get_section('%files'), 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.get_sources(), expected)
     # Test find
     regex = re.compile(r'^Release\s*:\s*(.*)')
     res = spec.find(regex)
     if res:
         self.assertEqual(res.groups(), ('1%{?dist}', ))
     else:
         self.assertTrue(False)
     os.chdir(self.startdir)
Exemplo n.º 2
0
 def test_spec_file(self):
     ''' Test the SpecFile class'''
     ReviewDirs.reset()
     ReviewDirs.workdir_setup('.', True)
     dest = Mock.get_builddir('SOURCES')
     if not os.path.exists(dest):
         os.makedirs(dest)
     self.helpers._get_file(TEST_SPEC, Mock.get_builddir('SOURCES'))
     spec = SpecFile(self.spec_file)
     # Test misc rpm values (Macro resolved)
     self.assertEqual(spec.name,'python-test')
     self.assertEqual(spec.version,'1.0')
     # resolve the dist-tag
     dist = self.helpers._run_cmd('rpm --eval %dist')[:-1]
     self.assertEqual(spec.release,'1'+dist)
     # test misc rpm values (without macro resolve)
     self.assertEqual(spec.find_tag('Release'), ['1%{?dist}'])
     self.assertEqual(spec.find_tag('License'), ['GPLv2+'])
     self.assertEqual(spec.find_tag('Group'), ['Development/Languages'])
     # Test rpm value not there
     self.assertEqual(spec.find_tag('PreReq'), [])
     # Test get sections
     expected = {'%clean': ['rm -rf $RPM_BUILD_ROOT']}
     self.assertEqual(spec.get_section('%clean'), expected)
     expected = {'%build': ['%{__python} setup.py build']}
     self.assertEqual(spec.get_section('%build'), expected)
     expected = {'%install': ['rm -rf $RPM_BUILD_ROOT', 
                 '%{__python} setup.py install -O1 --skip-build'
                 ' --root $RPM_BUILD_ROOT']}
     self.assertEqual(spec.get_section('%install'),expected)
     expected = {'%files': ['%defattr(-,root,root,-)', 
                 '%doc COPYING', '%{python_sitelib}/*']}
     self.assertEqual(spec.get_section('%files'),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.get_sources(), expected)
     # Test find
     regex = re.compile(r'^Release\s*:\s*(.*)')
     res = spec.find(regex)
     if res:
         self.assertEqual(res.groups(), ('1%{?dist}',))
     else:
         self.assertTrue(False)
     os.chdir(self.startdir)
Exemplo n.º 3
0
 def test_mock_clear(self):
     ''' test mock.clear_builddir(). '''
     self.init_test('test_misc',
                    argv=['-n', 'python-test', '--cache',
                          '--no-build'])
     wdir = Mock.get_builddir('BUILD')
     len1 = len(glob.glob(os.path.join(wdir, "*")))
     s = "cd {0}; ln -sf foo bar || :".format(wdir)
     check_output(s, shell=True)
     Mock.builddir_cleanup()
     len2 = len(glob.glob(os.path.join(wdir, "*")))
     self.assertEqual(len2, len1)
Exemplo n.º 4
0
 def setUp(self):
     sys.argv = ['fedora-review','-n','python-test','--prebuilt']
     Settings.init(True)
     ReviewDirs.reset()
     ReviewDirs.workdir_setup('.', True)
     self.log = Settings.get_logger()
     self.helpers = Helpers()
     self.srpm_file = os.path.join(os.path.abspath('.'),
                                   os.path.basename(TEST_SRPM))
     self.spec_file = os.path.join(Mock.get_builddir('SOURCES'),
                                     os.path.basename(TEST_SPEC))
     self.source_file = os.path.join(Mock.get_builddir('SOURCES'),
                                     os.path.basename(TEST_SRC))
     if not os.path.exists(TEST_WORK_DIR):
         os.makedirs(TEST_WORK_DIR)
     self.helpers._get_file(TEST_SRPM, TEST_WORK_DIR)
     self.startdir = os.getcwd()
     for tree in ['python-test', 'results']:
         if os.path.exists(tree):
             shutil.rmtree(tree)
     Mock.reset()
Exemplo n.º 5
0
 def setUp(self):
     sys.argv = ['fedora-review', '-n', 'python-test', '--prebuilt']
     Settings.init(True)
     ReviewDirs.reset()
     ReviewDirs.workdir_setup('.', True)
     self.log = Settings.get_logger()
     self.helpers = Helpers()
     self.srpm_file = os.path.join(os.path.abspath('.'),
                                   os.path.basename(TEST_SRPM))
     self.spec_file = os.path.join(Mock.get_builddir('SOURCES'),
                                   os.path.basename(TEST_SPEC))
     self.source_file = os.path.join(Mock.get_builddir('SOURCES'),
                                     os.path.basename(TEST_SRC))
     if not os.path.exists(TEST_WORK_DIR):
         os.makedirs(TEST_WORK_DIR)
     self.helpers._get_file(TEST_SRPM, TEST_WORK_DIR)
     self.startdir = os.getcwd()
     for tree in ['python-test', 'results']:
         if os.path.exists(tree):
             shutil.rmtree(tree)
     Mock.reset()
Exemplo n.º 6
0
 def setUp(self):
     sys.argv = ['fedora-review', '-b', '1']
     Settings.init(True)
     self.log = Settings.get_logger()
     self.helpers = HelpersMixin()
     self.srpm_file = os.path.join(os.path.abspath('.'),
                                   'test_misc',
                                   'python-test-1.0-1.fc16.src.rpm')
     self.spec_file = os.path.join(Mock.get_builddir('SOURCES'),
                                   'python-test.spec')
     self.startdir = os.getcwd()
     Mock.reset()
Exemplo n.º 7
0
 def __run_checks(self, spec, srpm):
     self.checks = Checks(spec, srpm)
     if Settings.no_report:
         self.outfile = '/dev/null'
     else:
         self.outfile = ReviewDirs.report_path(self.checks.spec.name)
     with open(self.outfile, "w") as output:
         if Settings.nobuild:
             self.checks.srpm.is_build = True
         self.log.info('Running checks and generate report\n')
         self.checks.run_checks(output=output,
                                writedown=not Settings.no_report)
         output.close()
     if not os.path.exists('BUILD'):
         os.symlink(Mock.get_builddir('BUILD'), 'BUILD')
     if not Settings.no_report:
         print "Review in: " + self.outfile
Exemplo n.º 8
0
 def __run_checks(self, spec, srpm):
     self.checks = Checks(spec, srpm )
     if Settings.no_report:
         self.outfile = '/dev/null'
     else:
         self.outfile = ReviewDirs.report_path(self.checks.spec.name)
     with open(self.outfile,"w") as output:
         if Settings.nobuild:
             self.checks.srpm.is_build = True
         self.log.info('Running checks and generate report\n')
         self.checks.run_checks(output=output,
                                writedown=not Settings.no_report)
         output.close()
     if not os.path.exists('BUILD'):
         os.symlink(Mock.get_builddir('BUILD'), 'BUILD')
     if not Settings.no_report:
         print "Review in: " + self.outfile
Exemplo n.º 9
0
 def run(self):
     if not Mock.is_available():
         self.set_passed(self.NA)
         return
     Mock.clear_builddir()
     errmsg = Mock.rpmbuild_bp(self.srpm)
     if errmsg:
         self.log.debug(
             "Cannot do rpmbuild -bp, trying with builddeps")
         Mock.install(self.spec.build_requires)
         Mock.rpmbuild_bp(self.srpm)
     if os.path.lexists('BUILD'):
         if os.path.islink('BUILD'):
             os.unlink('BUILD')
         else:
             shutil.rmtree('BUILD')
     os.symlink(Mock.get_builddir('BUILD'), 'BUILD')
     self.log.info('Active plugins: ' +
                       ', '.join(self.checks.get_plugins(True)))
     self.set_passed(self.NA, None, [self.setup_attachment()])
Exemplo n.º 10
0
 def run(self):
     if not Mock.is_available():
         self.log.info(
             "Mock unavailable, build and installation not checked.")
         self.set_passed(self.NA)
         return
     Mock.clear_builddir()
     errmsg = Mock.rpmbuild_bp(self.srpm)
     if errmsg:
         self.log.debug("Cannot do rpmbuild -bp, trying with builddeps")
         Mock.install(self.spec.build_requires)
         Mock.rpmbuild_bp(self.srpm)
     if os.path.lexists('BUILD'):
         if os.path.islink('BUILD'):
             os.unlink('BUILD')
         else:
             shutil.rmtree('BUILD')
     os.symlink(Mock.get_builddir('BUILD'), 'BUILD')
     self.log.info('Active plugins: ' +
                   ', '.join(self.checks.get_plugins(True)))
     self.set_passed(self.NA, None, [self.setup_attachment()])
Exemplo n.º 11
0
    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'])
        dest = Mock.get_builddir('SOURCES')
        if not os.path.exists(dest):
            os.makedirs(dest)
        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)