From 48bed1538fa943e89bef5d4d2c9e6868ed53fca3 Mon Sep 17 00:00:00 2001 From: Joachim Filip Ignacy Bartosik Date: Sat, 24 Apr 2010 21:57:56 +0200 Subject: [PATCH 2/2] Tests for added check. --- .../tests/checks/P_shouldnt_be_in_source_ri.py | 62 ++++++++++++++++++++ 1 files changed, 62 insertions(+), 0 deletions(-) create mode 100644 pym/repoman/tests/checks/P_shouldnt_be_in_source_ri.py 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..2a97470 --- /dev/null +++ b/pym/repoman/tests/checks/P_shouldnt_be_in_source_ri.py @@ -0,0 +1,62 @@ +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: + cpv_split = (u'c', u'p', u'v', 'r') + lines = [] + +class TestPNotInSourceUri(unittest.TestCase): + lines_cpv_ok = [ + ([u'SRC_URI="http://foomatic/foobar.tar.gz"', u'\t SRC_URI="http://foomatic/1/foobar.tgz"', u'#comment on foobar-1'], + (u'foo-matic', u'foobar', u'1', u'r0')) + ] + + lines_cpv_bad= [([u'SRC_URI="http://foomatic.org/foobar/1.tgz"', u'\t SRC_URI = "http://foomatic.org/foobar-1.tar.gz"', + u'SRC_URI="http://foomatic/FOOBAR-1.htm"\t ', u'SRC_URI="http://foomatic/foobar-1/get_me.tar.gz"', + u'SRC_URI="http://foomatic/foobar/1/r0/pack.tar.gz"'], (u'foo-matic', u'foobar', u'1', u'r0'))] + + testee = PNotInSourceUri() + pkg = FakePackage( ) + + def check_cpvs_lines(self, lines_cpv_pairs, test): + for lines, cpv in lines_cpv_pairs: + self.pkg.cpv_split = cpv + self.testee.new( self.pkg) + num = 1 + #print "\n\t\t", lines + #print "\n\t\t", cpv + for line in lines: + self.assertTrue(test(self.testee.check(num, line)), msg = "on line '" + line + "'") + num+=1 + + 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): + self.check_cpvs_lines(self.lines_cpv_ok, lambda res: res is None) + def test_reject_p_in_src_uri(self): + self.check_cpvs_lines(self.lines_cpv_bad, lambda res: res is not None) + +if __name__ == '__main__': + suite = unittest.TestLoader().loadTestsFromTestCase(TestPNotInSourceUri) + unittest.TextTestRunner(verbosity=2).run(suite) -- 1.7.0.4