class TestRChecks(unittest.TestCase): def setUp(self): sys.argv = ['fedora-review','-rpn','R-Rdummypkg'] os.chdir('test-R') if os.path.exists('R-Rdummypkg'): shutil.rmtree('R-Rdummypkg') Settings.init(True) ReviewDirs.reset() @unittest.skipIf(no_net, 'No network available') def test_all_checks(self): ''' Run all automated review checks''' self.bug = NameBug('R-Rdummypkg') self.bug.find_urls() self.bug.download_files() self.checks = Checks(self.bug.spec_file, self.bug.srpm_file) self.checks.run_checks(writedown=False) for check in self.checks.checks: if check.is_applicable(): self.assertTrue(check.header == 'Generic' or check.header == 'R') result = check.get_result() self.assertTrue(result.result in ['pass', 'pending', 'fail']) os.chdir('..')
def test_source_file(self): """ Test the SourceFile class """ if os.path.exists('python-test'): shutil.rmtree('python-test') sys.argv = ['fedora-review', '-n', 'python-test'] Settings.init(True) ReviewDirs.reset() ReviewDirs.workdir_setup('.', True) bug = NameBug('python-test') bug.find_urls() bug.download_files() spec = SpecFile(bug.spec_file) sources = Sources(spec) source = Source(sources, 'Source0', TEST_SRC) # check that source exists and source.filename point to the right location expected = os.path.abspath('./upstream/python-test-1.0.tar.gz') self.assertEqual(source.filename, expected) self.assertEqual(source.is_archive(), True) self.assertTrue(os.path.exists(source.filename)) self.assertEqual( source.check_source_checksum(), "7ef644ee4eafa62cfa773cad4056cdcea592e27dacd5ae" "b4e8b11f51f5bf60d3") os.chdir(self.startdir)
def test_exclude(self): """ test --exclude/-x option. """ self.init_test(["fedora-review", "-n", "python-test", "-x", "CheckRequires"]) bug = NameBug(Settings.name) bug.find_urls() bug.download_files() checks = Checks(bug.spec_file, bug.srpm_file) self.assertFalse("CheckRequires" in checks.get_checks())
def test_flags_2(self): ''' Flag defined in python, not set by user' ''' self.init_test('test_misc', argv=['-n','python-test', '--cache', '--no-build']) bug = NameBug('python-test') bug.find_urls() bug.download_files() checks = Checks(bug.spec_file, bug.srpm_file) self.assertFalse(checks.flags['EPEL5'])
def test_flags_3(self): ''' Flag not defined , set by user' ''' self.init_test('test_misc', argv=['-n','python-test', '--cache', '--no-build', '-D', 'EPEL8']) bug = NameBug('python-test') bug.find_urls() bug.download_files() with self.assertRaises(ReviewError): checks = Checks(bug.spec_file, bug.srpm_file)
def test_exclude(self): ''' test --exclude/-x option. ''' self.init_test(['fedora-review', '-n','python-test', '-x', 'CheckRequires']) bug = NameBug(Settings.name) bug.find_urls() bug.download_files() checks = Checks(bug.spec_file, bug.srpm_file) self.assertFalse('CheckRequires' in checks.get_checks())
def test_single(self): """ test --single/-s option """ self.init_test(["fedora-review", "-n", "python-test", "-s", "CheckRequires"]) bug = NameBug(Settings.name) bug.find_urls() bug.download_files() checks = Checks(bug.spec_file, bug.srpm_file) self.assertEqual(len(checks.checks), 1) check = checks.checks[0] self.assertEqual(check.name, "CheckRequires")
def test_bad_specname(self): self.init_test('bad-specname', argv=['-rn','python-test', '--cache']) ReviewDirs.reset(os.getcwd()) bug = NameBug('python-test') bug.find_urls() bug.download_files() checks = Checks(bug.spec_file, bug.srpm_file) check = checks.checkdict['CheckSpecAsInSRPM'] check.run() self.assertTrue(check.is_failed) self.assertIn('Bad spec filename:', check.result.output_extra)
def test_flags_4(self): ''' Flag defined in shell script , set by user to value ''' os.environ['XDG_DATA_HOME'] = os.getcwd() self.init_test('test_misc', argv=['-n','python-test', '--cache', '--no-build', '-D', 'EPEL6=foo']) bug = NameBug('python-test') bug.find_urls() bug.download_files() checks = Checks(bug.spec_file, bug.srpm_file) self.assertEqual(str(checks.flags['EPEL6']), 'foo')
def test_rpm_spec(self): self.init_test('test_misc', argv=['-rn','python-test', '--cache', '--no-build']) ReviewDirs.reset() bug = NameBug('python-test') bug.find_urls() expected = 'src/test/test_misc/python-test-1.0-1.fc16.src.rpm' self.assertTrue(bug.srpm_url.endswith(expected)) expected = 'src/test/test_misc/review-python-test/srpm-unpacked/python-test.spec' print bug.spec_url self.assertTrue(bug.spec_url.endswith(expected))
def test_local_repo(self): self.init_test('test_misc', argv=['-rn','python-test', '--local-repo', 'repo', '--cache']) ReviewDirs.reset(os.getcwd()) bug = NameBug('python-test') bug.find_urls() bug.download_files() checks = Checks(bug.spec_file, bug.srpm_file) check = checks.checkdict['CheckPackageInstalls'] check.run() self.assertTrue(check.is_passed) self.assertTrue(Mock.is_installed('dummy'))
def test_rpm_spec(self): sys.argv = ['fedora-review','-rn','python-test'] Settings.init(True) ReviewDirs.reset() if os.path.exists('python-test'): shutil.rmtree('python-test') bug = NameBug('python-test') bug.find_urls() expected = 'src/test/python-test-1.0-1.fc16.src.rpm' self.assertTrue(bug.srpm_url.endswith(expected)) expected = 'src/test/python-test/srpm-unpacked/python-test.spec' self.assertTrue(bug.spec_url.endswith(expected)) os.chdir(self.startdir)
def test_single(self): ''' test --single/-s option ''' self.init_test(['fedora-review', '-n','python-test', '-s', 'CheckRequires']) bug = NameBug(Settings.name) bug.find_urls() bug.download_files() checks = Checks(bug.spec_file, bug.srpm_file) self.assertEqual(len(checks.checks), 1) check = checks.checks[0] self.assertEqual(check.name, 'CheckRequires')
def test_107_source_same_as_name(self): """ Test the case when Source is equal to %{name} """ srpm_file = os.path.join(os.path.abspath('.'), 'test_regressions', 'test_107_2-1.0-1.fc17.src.rpm') self.init_test('test_regressions', argv=['-rn', srpm_file, '--cache']) ReviewDirs.reset(os.getcwd()) bug = NameBug(srpm_file) bug.find_urls() self.assertNotEqual(None, bug.srpm_file) self.assertNotEqual(None, bug.spec_file)
def test_rpm_spec(self): sys.argv = ['fedora-review', '-rn', 'python-test'] Settings.init(True) ReviewDirs.reset() if os.path.exists('python-test'): shutil.rmtree('python-test') bug = NameBug('python-test') bug.find_urls() expected = 'src/test/python-test-1.0-1.fc16.src.rpm' self.assertTrue(bug.srpm_url.endswith(expected)) expected = 'src/test/python-test/srpm-unpacked/python-test.spec' self.assertTrue(bug.spec_url.endswith(expected)) os.chdir(self.startdir)
def test_sh_api(self): ''' Basic shell API test. ''' self.init_test('test_ext', argv=['-pn','python-test', '--cache', '--no-build']) bug = NameBug('python-test') bug.find_urls() bug.download_files() checks = Checks(bug.spec_file, bug.srpm_file) checks.checkdict['CreateEnvCheck'].run() checks.checkdict['unittest-test2'].run() self.assertTrue(checks.checkdict['unittest-test2'].is_pending) self.assertNotIn('CheckLargeDocs', checks.checkdict)
def test_prebuilt_sources(self): self.init_test('test_misc', argv=['-n','python-test', '--prebuilt']) ReviewDirs.startdir = os.getcwd() bug = NameBug('python-test') bug.find_urls() bug.download_files() checks = Checks(bug.spec_file, bug.srpm_file) subprocess.check_call('touch orvar.rpm', shell=True) rpms = checks.srpm.get_used_rpms() self.assertEqual(len(rpms), 2) rpms = checks.srpm.get_used_rpms('.src.rpm') os.unlink('orvar.rpm') self.assertEqual(len(rpms), 1)
def test_md5sum_diff_fail(self): self.init_test('md5sum-diff-fail', argv=['-rpn','python-test', '--cache', '--no-build']) ReviewDirs.reset(os.getcwd()) bug = NameBug('python-test') bug.find_urls() checks = Checks(bug.spec_file, bug.srpm_file).get_checks() checks.set_single_check('CheckSourceMD5') check = checks['CheckSourceMD5'] check.run() self.assertTrue(check.is_failed) expected = 'diff -r also reports differences' self.assertTrue(expected in check.result.attachments[0].text)
def test_srv_opt(self): ''' Test check of no files in /srv, /opt and /usr/local. ''' self.init_test('srv-opt', argv=['-rn','dummy', '--cache', '--no-build']) ReviewDirs.reset(os.getcwd()) bug = NameBug('dummy') bug.find_urls() bug.download_files() checks = Checks(bug.spec_file, bug.srpm_file) check = checks.checkdict['CreateEnvCheck'].run() check = checks.checkdict['check-srv-opt-local'] check.run() self.assertTrue( '/srv' in check.result.output_extra) self.assertTrue( '/opt' in check.result.output_extra) self.assertTrue( '/usr/local' in check.result.output_extra)
def test_sources(self): self.init_test('test_misc', argv=['-n','python-test', '--cache', '--no-build']) bug = NameBug('python-test') bug.find_urls() bug.download_files() checks = Checks(bug.spec_file, bug.srpm_file).get_checks() checks.set_single_check('CheckSourceMD5') check = checks['CheckSourceMD5'] check.run() result = check.result self.log.debug('test_source, result : ' + result.result) if result.output_extra: self.log.debug("Result extra text: " + result.output_extra) self.assertTrue(check.is_passed)
def test_name(self): """ Test -name option """ self.init_test(['fedora-review','-n','python-test']) bug = NameBug(Settings.name) bug.find_urls() expected = abs_file_url('./python-test-1.0-1.fc16.src.rpm') self.assertEqual(expected, bug.srpm_url) expected = abs_file_url('./python-test.spec') self.assertEqual(expected, bug.spec_url), bug.download_files() expected = os.path.abspath('./python-test-1.0-1.fc16.src.rpm') self.assertEqual(expected, bug.srpm_file), expected = os.path.abspath('./python-test.spec') self.assertEqual(expected, bug.spec_file),
def test_name(self): """ Test -name option """ self.init_test(["fedora-review", "-n", "python-test"]) bug = NameBug(Settings.name) bug.find_urls() expected = abs_file_url("./python-test-1.0-1.fc16.src.rpm") self.assertEqual(expected, bug.srpm_url) expected = abs_file_url("./python-test.spec") self.assertEqual(expected, bug.spec_url), bug.download_files() expected = os.path.abspath("./python-test-1.0-1.fc16.src.rpm") self.assertEqual(expected, bug.srpm_file), expected = os.path.abspath("./python-test.spec") self.assertEqual(expected, bug.spec_file),
def test_perl_module(self): ''' test basic perl python + shell test ''' self.init_test('perl', argv=['-rn','perl-RPM-Specfile', '--no-build']) ReviewDirs.reset(os.getcwd()) bug = NameBug('perl-RPM-Specfile') bug.find_urls() bug.download_files() checks = Checks(bug.spec_file, bug.srpm_file) checks.checkdict['CreateEnvCheck'].run() check = checks.checkdict['PerlCheckBuildRequires'] check.run() self.assertTrue(check.is_pending) check = checks.checkdict['perl-url-tag'] check.run() self.assertTrue(check.is_pending)
def test_md5sum_diff_fail(self): os.chdir('md5sum-diff-fail') sys.argv = ['fedora-review','-rpn','python-test'] Settings.init(True) ReviewDirs.reset() if os.path.exists('python-test'): shutil.rmtree('python-test') bug = NameBug('python-test') bug.find_urls() checks = Checks(bug.spec_file, bug.srpm_file) checks.set_single_check('CheckSourceMD5') self.assertEqual(len(checks.checks), 1) check = checks.checks[0] check.run() self.assertEqual(check.state, 'fail') expected = 'diff -r also reports differences' self.assertTrue(expected in check.attachments[0].text) os.chdir(self.startdir)
def test_md5sum_diff_fail(self): os.chdir('md5sum-diff-fail') sys.argv = ['fedora-review', '-rpn', 'python-test'] Settings.init(True) ReviewDirs.reset() if os.path.exists('python-test'): shutil.rmtree('python-test') bug = NameBug('python-test') bug.find_urls() checks = Checks(bug.spec_file, bug.srpm_file) checks.set_single_check('CheckSourceMD5') self.assertEqual(len(checks.checks), 1) check = checks.checks[0] check.run() self.assertEqual(check.state, 'fail') expected = 'diff -r also reports differences' self.assertTrue(expected in check.attachments[0].text) os.chdir(self.startdir)
def test_mock_uniqueext(self): self.init_test('test_misc', argv=['-n','python-test'], options='--uniqueext=hugo') bug = NameBug('python-test') bug.find_urls() bug.download_files() checks = Checks(bug.spec_file, bug.srpm_file) Mock.init() for dirt in glob.glob('results/*.*'): os.unlink(dirt) check = checks.checkdict['CheckBuild'] check.run() self.assertTrue(check.is_passed) results = glob.glob('results/*.rpm') self.assertEqual(len(results), 2) for dirt in glob.glob('results/*.*'): os.unlink(dirt)
def test_jsonapi(self): self.init_test('test_misc', argv=['-rpn','python-test', '--no-build']) ReviewDirs.reset(os.getcwd()) os.environ['REVIEW_EXT_DIRS'] = os.path.normpath(os.getcwd() + '/../api') bug = NameBug('python-test') bug.find_urls() bug.download_files() checks = Checks(bug.spec_file, bug.srpm_file).get_checks() test1 = checks['test1'] test2 = checks['ExtShellTest2'] self.assertEqual( test1.group, 'Generic') self.assertEqual( test1.type, 'EXTRA') self.assertEqual( test1.text, 'A check solely for test purposes.') self.assertEqual( test2.group, 'Generic') self.assertEqual( test2.type, 'EXTRA') self.assertEqual( test2.text, 'A second check solely for test purposes.')
def test_rpm_spec(self): """ Test --rpm-spec/-r option """ self.init_test(["fedora-review", "-rn", "python-test"], "desktop-file") if os.path.exists("python-test"): shutil.rmtree("python-test") ReviewDirs.reset() bug = NameBug(Settings.name) bug.find_urls() expected = abs_file_url("../python-test-1.0-1.fc16.src.rpm") self.assertEqual(expected, bug.srpm_url) expected = abs_file_url("./srpm-unpacked/python-test.spec") self.assertEqual(expected, bug.spec_url), bug.download_files() expected = os.path.abspath("../python-test-1.0-1.fc16.src.rpm") self.assertEqual(expected, bug.srpm_file), expected = os.path.abspath("./srpm-unpacked/python-test.spec") self.assertEqual(expected, bug.spec_file), os.chdir(startdir)
def test_rpm_spec(self): """ Test --rpm-spec/-r option """ self.init_test(['fedora-review','-rn','python-test'], 'desktop-file') if os.path.exists('python-test'): shutil.rmtree('python-test') ReviewDirs.reset() bug = NameBug(Settings.name) bug.find_urls() expected = abs_file_url('../python-test-1.0-1.fc16.src.rpm') self.assertEqual(expected, bug.srpm_url) expected = abs_file_url('./srpm-unpacked/python-test.spec') self.assertEqual(expected, bug.spec_url), bug.download_files() expected = os.path.abspath('../python-test-1.0-1.fc16.src.rpm') self.assertEqual(expected, bug.srpm_file), expected = os.path.abspath('./srpm-unpacked/python-test.spec') self.assertEqual(expected, bug.spec_file), os.chdir(startdir)
def test_sources(self): if os.path.exists('python-test'): shutil.rmtree('python-test') sys.argv = ['fedora-review','-n','python-test'] Settings.init(True) ReviewDirs.reset() ReviewDirs.workdir_setup('.', True) bug = NameBug('python-test') bug.find_urls() bug.download_files() checks = Checks(bug.spec_file, bug.srpm_file) checks.set_single_check('CheckSourceMD5') self.assertEqual(len(checks.checks), 1) check = checks.checks[0] check.run() result = check.get_result() self.log.debug('result : ' + result.result) if result.output_extra: self.log.debug("Result extra text: " + result.output_extra) self.assertEqual( result.result, 'pass') os.chdir(self.startdir)
def test_sources(self): if os.path.exists('python-test'): shutil.rmtree('python-test') sys.argv = ['fedora-review', '-n', 'python-test'] Settings.init(True) ReviewDirs.reset() ReviewDirs.workdir_setup('.', True) bug = NameBug('python-test') bug.find_urls() bug.download_files() checks = Checks(bug.spec_file, bug.srpm_file) checks.set_single_check('CheckSourceMD5') self.assertEqual(len(checks.checks), 1) check = checks.checks[0] check.run() result = check.get_result() self.log.debug('result : ' + result.result) if result.output_extra: self.log.debug("Result extra text: " + result.output_extra) self.assertEqual(result.result, 'pass') os.chdir(self.startdir)
def test_dirty_resultdir(self): self.init_test('test_misc', argv=['-n','python-test', '--cache']) bug = NameBug('python-test') bug.find_urls() bug.download_files() checks = Checks(bug.spec_file, bug.srpm_file).get_checks() checks.set_single_check('CheckResultdir') check = checks['CheckResultdir'] for dirt in glob.glob('results/*.*'): os.unlink(dirt) check.run() self.assertTrue(check.is_passed) subprocess.check_call('touch results/orvar.rpm', shell=True) self.assertRaises(ReviewError, check.run) Settings.nobuild = True check.run() self.assertTrue(check.is_passed) os.unlink('results/orvar.rpm')
class TestRChecks(FR_TestCase): R_TEST_SRPM = 'https://fedorahosted.org/releases/F/e' \ '/FedoraReview/R-Rdummypkg-1.0-2.fc15.src.rpm' R_TEST_SPEC = FR_TestCase.BASE_URL + 'R-Rdummypkg.spec' R_TEST_SRC = FR_TestCase.BASE_URL + 'Rdummypkg_1.0.tar.gz' @unittest.skipIf(FAST_TEST, 'slow test disabled by REVIEW_FAST_TEST') def test_all_checks(self): ''' Run all automated review checks''' self.init_test('test-R', argv=['-rpn','R-Rdummypkg', '--no-build']) ReviewDirs.reset() self.bug = NameBug('R-Rdummypkg') self.bug.find_urls() self.bug.download_files() self.checks = Checks(self.bug.spec_file, self.bug.srpm_file) self.checks.run_checks(writedown=False) for check in self.checks.checkdict.itervalues(): if check.is_passed or check.is_pending or check.is_failed: self.assertIn(check.group, ['Generic', 'R'])
def test_sh_attach(self): ''' Test shell attachments. ''' self.init_test('test_ext', argv=['-rn','python-test', '--no-build']) ReviewDirs.reset(os.getcwd()) bug = NameBug('python-test') bug.find_urls() bug.download_files() checks = Checks(bug.spec_file, bug.srpm_file).get_checks() checks['CreateEnvCheck'].run() check = checks['test-attachments'] check.run() self.assertEqual(len(check.result.attachments), 2) a1 = filter( lambda a: 'attachment 1' in a.text, check.result.attachments)[0] a2 = filter( lambda a: 'attachment 2' in a.text, check.result.attachments)[0] self.assertEqual('Heading 1', a1.header) self.assertEqual(8, a1.order_hint) self.assertEqual('Heading 2', a2.header) self.assertEqual(9, a2.order_hint)
class TestRChecks(unittest.TestCase): def setUp(self): sys.argv = ['fedora-review', '-rpn', 'R-Rdummypkg'] os.chdir('test-R') if os.path.exists('R-Rdummypkg'): shutil.rmtree('R-Rdummypkg') Settings.init(True) ReviewDirs.reset() @unittest.skipIf(no_net, 'No network available') def test_all_checks(self): ''' Run all automated review checks''' self.bug = NameBug('R-Rdummypkg') self.bug.find_urls() self.bug.download_files() self.checks = Checks(self.bug.spec_file, self.bug.srpm_file) self.checks.run_checks(writedown=False) for check in self.checks.checks: if check.is_applicable(): self.assertTrue(check.header == 'Generic' or check.header == 'R') result = check.get_result() self.assertTrue(result.result in ['pass', 'pending', 'fail']) os.chdir('..')
def test_source_file(self): """ Test the SourceFile class """ if os.path.exists('python-test'): shutil.rmtree('python-test') sys.argv = ['fedora-review','-n','python-test'] Settings.init(True) ReviewDirs.reset() ReviewDirs.workdir_setup('.', True) bug = NameBug('python-test') bug.find_urls() bug.download_files() spec = SpecFile(bug.spec_file) sources = Sources(spec) source = Source(sources, 'Source0', TEST_SRC) # check that source exists and source.filename point to the right location expected = os.path.abspath('./upstream/python-test-1.0.tar.gz') self.assertEqual(source.filename, expected) self.assertEqual(source.is_archive(), True) self.assertTrue(os.path.exists(source.filename)) self.assertEqual(source.check_source_checksum(), "7ef644ee4eafa62cfa773cad4056cdcea592e27dacd5ae" "b4e8b11f51f5bf60d3") os.chdir(self.startdir)