From ac20fa4663bc58f6cfd1a71b7c2e1449d7007c87 Mon Sep 17 00:00:00 2001 From: Joachim Filip Ignacy Bartosik Date: Tue, 27 Apr 2010 20:22:31 +0200 Subject: [PATCH 2/2] tests. --- .../tests/checks/P_shouldnt_be_in_source_ri.py | 47 ++++++++++++++++++++ 1 files changed, 47 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..aae4327 --- /dev/null +++ b/pym/repoman/tests/checks/P_shouldnt_be_in_source_ri.py @@ -0,0 +1,47 @@ +import unittest +from portage.tests import TestCase +from repoman.checks import PNotInSourceUri + +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'SRC_URI="http://foomatic/FOOBAR-1.htm"\t ', + u'SRC_URI="http://foomatic/foobar.tgz" # some 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/get_me.tar.gz"', + u'SRC_URI="http://foomatic/foobar/1/r0/pack.tar.gz"', + u'SRC_URI="http://foomatic/foobar-1.tgz # should be ${P}"'], + (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 + 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