Line 0
Link Here
|
0 |
- |
1 |
import unittest |
|
|
2 |
from portage.tests import TestCase |
3 |
from repoman.checks import PNotInSourceUri |
4 |
|
5 |
class FakePackage: |
6 |
cpv_split = (u'c', u'p', u'v', 'r') |
7 |
lines = [] |
8 |
|
9 |
class TestPNotInSourceUri(unittest.TestCase): |
10 |
lines_cpv_ok = [([u'SRC_URI="http://foomatic/foobar.tar.gz"', |
11 |
u'\t SRC_URI="http://foomatic/1/foobar.tgz"', u'#comment on foobar-1', |
12 |
u'SRC_URI="http://foomatic/foobar.tgz" # some comment on foobar-1'], |
13 |
(u'foo-matic', u'foobar', u'1', u'r0'))] |
14 |
|
15 |
lines_cpv_bad= [([u'SRC_URI="http://foomatic.org/foobar/1.tgz"', |
16 |
u'\t SRC_URI = "http://foomatic.org/foobar-1.tar.gz"', |
17 |
u'SRC_URI="http://foomatic/FOOBAR-1.htm"\t ', |
18 |
u'SRC_URI="http://foomatic/foobar-1/get_me.tar.gz"', |
19 |
u'SRC_URI="http://foomatic/foobar/1/r0/pack.tar.gz"', |
20 |
u'SRC_URI="http://foomatic/foobar-1.tgz # should be ${P}"'], |
21 |
u'foo-matic', u'foobar', u'1', u'r0'))] |
22 |
|
23 |
testee = PNotInSourceUri() |
24 |
pkg = FakePackage( ) |
25 |
|
26 |
def check_cpvs_lines(self, lines_cpv_pairs, test): |
27 |
for lines, cpv in lines_cpv_pairs: |
28 |
self.pkg.cpv_split = cpv |
29 |
self.testee.new( self.pkg) |
30 |
num = 1 |
31 |
for line in lines: |
32 |
self.assertTrue(test(self.testee.check(num, line)), msg = "on line '" + line + "'") |
33 |
num+=1 |
34 |
|
35 |
def test_accept_any_EAPI(self): |
36 |
for eapi in ('0', '1', '2', '3', '3_pre2', '4'): |
37 |
self.assertTrue(self.testee.check_eapi(eapi)) |
38 |
|
39 |
def test_accept_no_p_in_src_uri(self): |
40 |
self.check_cpvs_lines(self.lines_cpv_ok, lambda res: res is None) |
41 |
|
42 |
def test_reject_p_in_src_uri(self): |
43 |
self.check_cpvs_lines(self.lines_cpv_bad, lambda res: res is not None) |
44 |
|
45 |
if __name__ == '__main__': |
46 |
suite = unittest.TestLoader().loadTestsFromTestCase(TestPNotInSourceUri) |
47 |
unittest.TextTestRunner(verbosity=2).run(suite) |