def init_test(self, cd, argv=None, wd=None, buildroot=None, options=None): ''' Initiate a test which runs in directory cd kwargs: argv: fed to sys.argv and eventually to Settings fedora-review is prepended and mock_root appended. wd: review directory, cleared. options: mock-options''' cd = os.path.abspath(cd) os.chdir(cd) if not wd: wd = os.getcwd() ReviewDirs.workdir_setup(wd, 'testing') if not argv: argv = [] args = argv args.insert(0, 'fedora-review') br = buildroot if buildroot else self.BUILDROOT args.append("--mock-config=" + br) opts = [] if NO_NET: opts.append('--offline') if options: opts.append(options) if opts: argv.append('--mock-options=' + ' '.join(opts)) sys.argv = argv Settings.init(True) Mock.clear_builddir() Mock.reset()
def test_mockbuild(self): """ Test the SRPMFile class """ self.init_test('mockbuild', argv=['-rn', 'python-test']) srpm = SRPMFile(self.srpm_file) # install the srpm srpm.unpack() self.assertTrue(srpm._unpacked_src is not None) src_dir = srpm._unpacked_src src_files = glob.glob(os.path.expanduser(src_dir) + '/*') src_files = [os.path.basename(f) for f in src_files] self.assertTrue('python-test-1.0.tar.gz' in src_files) self.log.info("Starting mock build (patience...)") Mock.clear_builddir() Mock.build(srpm.filename) rpms = glob.glob(os.path.join(Mock.resultdir, 'python-test-1.0-1*noarch.rpm')) self.assertEqual(1, len(rpms))
def run_spec(self, spec): ''' Run all tests for a test spec.... ''' # pylint: disable=C0111,W0212 class Null(object): def write(self, msg): pass argv = ['-rn', spec.testcase, '-x', 'generic-large-docs', '--no-build'] argv.extend(spec.args) self.init_test(spec.testcase, wd=spec.workdir, argv=argv) helper = ReviewHelper() Mock.clear_builddir() if os.path.exists('BUILD'): if os.path.islink('BUILD'): os.unlink('BUILD') else: shutil.rmtree('BUILD') stdout = sys.stdout sys.stdout = Null() rc = helper.run('review.txt') self.assertEqual(rc, 0) sys.stdout = stdout checkdict = helper.checks.get_checks() for check in checkdict.itervalues(): self.assertTrue(check.is_run) if check.is_passed or check.is_pending or check.is_failed: self.assertIn(check.group, spec.groups_ok, check.name + ': group is ' + check.group) for (what, check) in spec.expected: state = checkdict[check].state if what in ['pass', 'fail', 'pending']: self.assertEqual(state, what, check + ': state is ' + str(state)) elif what == 'na': self.assertEqual(state, None, check + ': state is ' + str(state)) elif what.startswith == 'in_attachment': self.assertIn(what.split(':')[1], checkdict[check].attachments[0].text) else: self.assertFalse(what)
def run_spec(self, spec): ''' Run all tests for a test spec.... ''' # pylint: disable=C0111,W0212 class Null(object): def write(self, msg): pass argv = ['-rn', spec.testcase, '-x', 'generic-large-docs', '--no-build'] argv.extend(spec.args) self.init_test(spec.testcase, wd=spec.workdir, argv=argv) helper = ReviewHelper() Mock.clear_builddir() if os.path.exists('BUILD'): if os.path.islink('BUILD'): os.unlink('BUILD') else: shutil.rmtree('BUILD') stdout = sys.stdout sys.stdout = Null() rc = helper.run('review.txt') self.assertEqual(rc, 0) sys.stdout = stdout checkdict = helper.checks.get_checks() for check in checkdict.itervalues(): self.assertTrue(check.is_run) if check.is_passed or check.is_pending or check.is_failed: self.assertIn(check.group, spec.groups_ok, check.name + ': group is ' + check.group) for (what, check) in spec.expected: state = checkdict[check].state if what in ['pass', 'fail', 'pending']: self.assertEqual(state, what, check + ': state is ' + str(state)) elif what == 'na': self.assertEqual(state, None, check + ': state is ' + str(state)) elif what.startswith == 'in_attachment': self.assertIn( what.split(':')[1], checkdict[check].attachments[0].text) else: self.assertFalse(what)
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()])
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()])