Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 292394 | Differences between
and this patch

Collapse All | Expand All

(-)a/pym/repoman/tests/checks/P_shouldnt_be_in_source_ri.py (-62 lines)
Lines 1-61 Link Here
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
	metadata = dict()
25
	cpv_split = (u'c', u'p', u'v', 'r')
26
27
class TestPNotInSourceUri(unittest.TestCase):
28
	uri_name_ok= (
29
		(u'http://foomatic/foobar.tar.gz', (u'foo-matic', u'foobar', u'1', u'r0')),
30
		(u'http://foomatic.org/1/foobar.tar.gz', (u'foo-matic', u'foobar', u'1', u'r0')))
31
32
	uri_name_bad= (
33
		(u'http://foomatic.org/foobar/1.tgz', (u'foo-matic', u'foobar', u'1', u'r0')),
34
		(u'http://foomatic.org/foobar-1.tar.gz', (u'foo-matic', u'foobar', u'1', u'r0')),
35
		(u'http://foomatic/FOOBAR-1.htm', (u'foo-matic', u'foobar', u'1', u'r0')),
36
		(u'http://foomatic/foobar-1/get_me.tar.gz', (u'foo-matic', u'foobar', u'1', u'r0')))
37
38
	testee = PNotInSourceUri()
39
	pkg = FakePackage( )
40
	
41
	def check_returns_none(self, uri, cpv):
42
			self.pkg.metadata['SRC_URI'] = uri
43
			self.pkg.cpv_split = cpv
44
			self.testee.new( self.pkg)
45
			return self.testee.check( 1, "") is None
46
47
	def test_accept_any_EAPI(self):
48
		for eapi in ('0', '1', '2', '3', '3_pre2', '4'):
49
			self.assertTrue(self.testee.check_eapi(eapi))
50
	
51
	def test_accept_no_p_in_src_uri(self):
52
		for uri_name in self.uri_name_ok:
53
			self.assertTrue(self.check_returns_none(uri_name[0], uri_name[1]))
54
55
	def test_reject_p_in_src_uri(self):
56
		for uri_name in self.uri_name_bad:
57
			self.assertFalse(self.check_returns_none(uri_name[0], uri_name[1]))
58
59
if __name__ == '__main__':
60
	suite = unittest.TestLoader().loadTestsFromTestCase(TestPNotInSourceUri)
61
	unittest.TextTestRunner(verbosity=2).run(suite)
62
- 

Return to bug 292394