summaryrefslogtreecommitdiff
blob: 47dc7de2cad9024721f3a21849dae978914cdec5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# test_varExpand.py -- Portage Unit Testing Functionality
# Copyright 2006 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Id$

from unittest import TestCase, TestLoader
from portage.util import varexpand

class VarExpandTestCase(TestCase):
	
	def testVarExpandPass(self):

		varDict = { "a":"5", "b":"7", "c":"-5" }
		for key in varDict.keys():
			result = varexpand( "$%s" % key, varDict )
			
			self.failIf( result != varDict[key],
				msg="Got %s != %s, from varexpand( %s, %s )" % \
					( result, varDict[key], "$%s" % key, varDict ) )
			result = varexpand( "${%s}" % key, varDict )
			self.failIf( result != varDict[key],
				msg="Got %s != %s, from varexpand( %s, %s )" % \
					( result, varDict[key], "${%s}" % key, varDict ) )

	def testVarExpandDoubleQuotes(self):
		
		varDict = { "a":"5" }
		tests = [ ("\"${a}\"", "5") ]
		for test in tests:
			result = varexpand( test[0], varDict )
			self.failIf( result != test[1],
				msg="Got %s != %s from varexpand( %s, %s )" \
				% ( result, test[1], test[0], varDict ) )

	def testVarExpandSingleQuotes(self):
		
		varDict = { "a":"5" }
		tests = [ ("\'${a}\'", "${a}") ]
		for test in tests:
			result = varexpand( test[0], varDict )
			self.failIf( result != test[1],
				msg="Got %s != %s from varexpand( %s, %s )" \
				% ( result, test[1], test[0], varDict ) )

	def testVarExpandFail(self):

		varDict = { "a":"5", "b":"7", "c":"15" }

		testVars = [ "fail" ]

		for var in testVars:
			result = varexpand( "$%s" % var, varDict )
			self.failIf( len(result),
				msg="Got %s == %s, from varexpand( %s, %s )" \
					% ( result, var, "$%s" % var, varDict ) )

			result = varexpand( "${%s}" % var, varDict )
			self.failIf( len(result),
				msg="Got %s == %s, from varexpand( %s, %s )" \
					% ( result, var, "${%s}" % var, varDict ) )