Line 0
Link Here
|
0 |
- |
1 |
import unittest |
|
|
2 |
from portage.tests import TestCase |
3 |
from repoman.checks import PNotInSourceUri |
4 |
''' |
5 |
using real _emerge.Package.Package turned out to be very troublesome. |
6 |
I had |
7 |
#begin source... don't mind abusing spaces it's just a comment |
8 |
import portage |
9 |
from portage import portdb |
10 |
from _emerge.Package import Package |
11 |
from _emerge.RootConfig import RootConfig |
12 |
|
13 |
cpv = "app-editors/vim-7.2.402" |
14 |
allvars = set(x for x in portage.auxdbkeys if not x.startswith("UNUSED_")) |
15 |
metadata = portdb.aux_get( cpv, allvars) |
16 |
root_config = RootConfig(portage.config(), "/usr/portage", None) |
17 |
pkg = Package( cpv = cpv, metadata = metadata, root_config = root_config) |
18 |
#end source |
19 |
|
20 |
but it still didn't work so I gave up and wrote FakePackage. |
21 |
Making test a lot more complicated than tested code is wong IMO. |
22 |
''' |
23 |
class FakePackage: |
24 |
cpv_split = (u'c', u'p', u'v', 'r') |
25 |
lines = [] |
26 |
|
27 |
class TestPNotInSourceUri(unittest.TestCase): |
28 |
lines_cpv_ok = [ |
29 |
([u'SRC_URI="http://foomatic/foobar.tar.gz"', u'\t SRC_URI="http://foomatic/1/foobar.tgz"', u'#comment on foobar-1'], |
30 |
(u'foo-matic', u'foobar', u'1', u'r0')) |
31 |
] |
32 |
|
33 |
lines_cpv_bad= [([u'SRC_URI="http://foomatic.org/foobar/1.tgz"', u'\t SRC_URI = "http://foomatic.org/foobar-1.tar.gz"', |
34 |
u'SRC_URI="http://foomatic/FOOBAR-1.htm"\t ', u'SRC_URI="http://foomatic/foobar-1/get_me.tar.gz"', |
35 |
u'SRC_URI="http://foomatic/foobar/1/r0/pack.tar.gz"'], (u'foo-matic', u'foobar', u'1', u'r0'))] |
36 |
|
37 |
testee = PNotInSourceUri() |
38 |
pkg = FakePackage( ) |
39 |
|
40 |
def check_cpvs_lines(self, lines_cpv_pairs, test): |
41 |
for lines, cpv in lines_cpv_pairs: |
42 |
self.pkg.cpv_split = cpv |
43 |
self.testee.new( self.pkg) |
44 |
num = 1 |
45 |
#print "\n\t\t", lines |
46 |
#print "\n\t\t", cpv |
47 |
for line in lines: |
48 |
self.assertTrue(test(self.testee.check(num, line)), msg = "on line '" + line + "'") |
49 |
num+=1 |
50 |
|
51 |
def test_accept_any_EAPI(self): |
52 |
for eapi in ('0', '1', '2', '3', '3_pre2', '4'): |
53 |
self.assertTrue(self.testee.check_eapi(eapi)) |
54 |
|
55 |
def test_accept_no_p_in_src_uri(self): |
56 |
self.check_cpvs_lines(self.lines_cpv_ok, lambda res: res is None) |
57 |
def test_reject_p_in_src_uri(self): |
58 |
self.check_cpvs_lines(self.lines_cpv_bad, lambda res: res is not None) |
59 |
|
60 |
if __name__ == '__main__': |
61 |
suite = unittest.TestLoader().loadTestsFromTestCase(TestPNotInSourceUri) |
62 |
unittest.TextTestRunner(verbosity=2).run(suite) |