# $Id: test_vercmp.py 5213 2006-12-08 00:12:41Z antarus $
from unittest import TestCase
+from portage_util import stack_dicts
+
class StackDictsTestCase(TestCase):
- def testStackDicts(self):
- pass
+ def testStackDictsPass(self):
+
+ tests = [ ( [ { "a":"b" }, { "b":"c" } ], { "a":"b", "b":"c" },
+ False, [], False ),
+ ( [ { "a":"b" }, { "a":"c" } ], { "a":"b c" },
+ True, [], False ),
+ ( [ { "a":"b" }, { "a":"c" } ], { "a":"b c" },
+ False, ["a"], False ),
+ ( [ { "a":"b" }, None ], { "a":"b" },
+ False, [], True ),
+ ( [ None ], None, False, [], False ),
+ ( [ None, {}], {}, False, [], True ) ]
+
+
+ for test in tests:
+ result = stack_dicts( test[0], test[2], test[3], test[4] )
+ self.failIf( result != test[1], msg="Expected %s = %s" \
+ % ( result, test[1] ) )
+
+ def testStackDictsFail(self):
+
+ tests = [ ( [ None, {} ], None, False, [], True ),
+ ( [ { "a":"b"}, {"a":"c" } ], { "a":"b c" },
+ False, [], False ) ]
+ for test in tests:
+ result = stack_dicts( test[0], test[2], test[3], test[4] )
+ self.failIf( result == test[1], msg="Expected %s != %s, got \
+ %s == %s!" % (result, test[1], result, test[1]) )
# $Id: test_vercmp.py 5213 2006-12-08 00:12:41Z antarus $
from unittest import TestCase
+from portage_util import unique_array
class UniqueArrayTestCase(TestCase):
- def testUniqueArray(self):
- pass
+ def testUniqueArrayPass(self):
+ """
+ test portage_util.uniqueArray()
+ """
+
+ import os
+
+ tests = [ ( ["a","a","a",os,os,[],[],[]], ['a',os,[]] ),
+ ( [1,1,1,2,3,4,4] , [1,2,3,4]) ]
+
+ for test in tests:
+ result = unique_array( test[0] )
+ for item in test[1]:
+ number = result.count(item)
+ self.failIf( number is not 1, msg="%s contains %s of %s, \
+ should be only 1" % (result, number, item) )
# $Id: test_vercmp.py 5213 2006-12-08 00:12:41Z antarus $
from unittest import TestCase, TestLoader
+from portage_util import varexpand
class VarExpandTestCase(TestCase):
- def testVarexpand(self):
- pass
+ 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 ) )