From 33ccf6dfbed5fa2f00848c86def3b892e97eb615 Mon Sep 17 00:00:00 2001 From: Joachim Filip Ignacy Bartosik Date: Sat, 17 Apr 2010 14:21:04 +0200 Subject: [PATCH 1/2] Added check for $P in SRC_URI to repoman. --- pym/repoman/checks.py | 16 +++++- .../tests/checks/P_shouldnt_be_in_source_ri.py | 61 ++++++++++++++++++++ 2 files changed, 76 insertions(+), 1 deletions(-) create mode 100644 pym/repoman/tests/checks/P_shouldnt_be_in_source_ri.py diff --git a/pym/repoman/checks.py b/pym/repoman/checks.py index 23f1267..39b0c36 100644 --- a/pym/repoman/checks.py +++ b/pym/repoman/checks.py @@ -436,6 +436,20 @@ class BuiltWithUse(LineCheck): re = re.compile('^.*built_with_use') error = errors.BUILT_WITH_USE +class PNotInSourceUri(LineCheck): + fail = False + pv = '' + def new(self, pkg): + self.pv = pkg.cpv_split[1] + '.' + pkg.cpv_split[2] + self.re = re.compile(self.pv, re.I) + self.src_uri = pkg.metadata["SRC_URI"] + self.fail = self.re.search( self.src_uri) + + def check(self, num, line): + if self.fail: + return "SRC_URI: '" + self.src_uri + "' conntains $P: '" \ + + self.pv + "' but it shouldn't." + # EAPI-3 checks class Eapi3DeprecatedFuncs(LineCheck): repoman_check_name = 'EAPI.deprecated' @@ -496,7 +510,7 @@ _constant_checks = tuple((c() for c in ( EbuildPatches, EbuildQuotedA, EapiDefinition, IUseUndefined, InheritAutotools, EMakeParallelDisabled, EMakeParallelDisabledViaMAKEOPTS, NoAsNeeded, - DeprecatedBindnowFlags, SrcUnpackPatches, WantAutoDefaultValue, + DeprecatedBindnowFlags,PNotInSourceUri, SrcUnpackPatches, WantAutoDefaultValue, SrcCompileEconf, Eapi3DeprecatedFuncs, Eapi4IncompatibleFuncs, Eapi4GoneVars, BuiltWithUse))) diff --git a/pym/repoman/tests/checks/P_shouldnt_be_in_source_ri.py b/pym/repoman/tests/checks/P_shouldnt_be_in_source_ri.py new file mode 100644 index 0000000..3308e55 --- /dev/null +++ b/pym/repoman/tests/checks/P_shouldnt_be_in_source_ri.py @@ -0,0 +1,61 @@ +import unittest +from portage.tests import TestCase +from repoman.checks import PNotInSourceUri +''' + using real _emerge.Package.Package turned out to be very troublesome. + I had + #begin source... don't mind abusing spaces it's just a comment + import portage + from portage import portdb + from _emerge.Package import Package + from _emerge.RootConfig import RootConfig + + cpv = "app-editors/vim-7.2.402" + allvars = set(x for x in portage.auxdbkeys if not x.startswith("UNUSED_")) + metadata = portdb.aux_get( cpv, allvars) + root_config = RootConfig(portage.config(), "/usr/portage", None) + pkg = Package( cpv = cpv, metadata = metadata, root_config = root_config) + #end source + + but it still didn't work so I gave up and wrote FakePackage. + Making test a lot more complicated than tested code is wong IMO. +''' +class FakePackage: + metadata = dict() + cpv_split = (u'c', u'p', u'v', 'r') + +class TestPNotInSourceUri(unittest.TestCase): + uri_name_ok= ( + (u'http://foomatic/foobar.tar.gz', (u'foo-matic', u'foobar', u'1', u'r0')), + (u'http://foomatic.org/1/foobar.tar.gz', (u'foo-matic', u'foobar', u'1', u'r0'))) + + uri_name_bad= ( + (u'http://foomatic.org/foobar/1.tgz', (u'foo-matic', u'foobar', u'1', u'r0')), + (u'http://foomatic.org/foobar-1.tar.gz', (u'foo-matic', u'foobar', u'1', u'r0')), + (u'http://foomatic/FOOBAR-1.htm', (u'foo-matic', u'foobar', u'1', u'r0')), + (u'http://foomatic/foobar-1/get_me.tar.gz', (u'foo-matic', u'foobar', u'1', u'r0'))) + + testee = PNotInSourceUri() + pkg = FakePackage( ) + + def check_returns_none(self, uri, cpv): + self.pkg.metadata['SRC_URI'] = uri + self.pkg.cpv_split = cpv + self.testee.new( self.pkg) + return self.testee.check( 1, "") is None + + def test_accept_any_EAPI(self): + for eapi in ('0', '1', '2', '3', '3_pre2', '4'): + self.assertTrue(self.testee.check_eapi(eapi)) + + def test_accept_no_p_in_src_uri(self): + for uri_name in self.uri_name_ok: + self.assertTrue(self.check_returns_none(uri_name[0], uri_name[1])) + + def test_reject_p_in_src_uri(self): + for uri_name in self.uri_name_bad: + self.assertFalse(self.check_returns_none(uri_name[0], uri_name[1])) + +if __name__ == '__main__': + suite = unittest.TestLoader().loadTestsFromTestCase(TestPNotInSourceUri) + unittest.TextTestRunner(verbosity=2).run(suite) -- 1.7.0.4