From: Alec Warner Date: Thu, 11 Jan 2007 08:45:13 +0000 (-0000) Subject: More portage_util tests X-Git-Tag: v2.1.2~84 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=848f6e5d29a84970c2356fb9af45326288f73ed6;p=portage.git More portage_util tests svn path=/main/trunk/; revision=5547 --- diff --git a/tests/portage_util/test_stackDicts.py b/tests/portage_util/test_stackDicts.py index dd0743509..ac0e67ef8 100644 --- a/tests/portage_util/test_stackDicts.py +++ b/tests/portage_util/test_stackDicts.py @@ -4,8 +4,36 @@ # $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]) ) diff --git a/tests/portage_util/test_uniqueArray.py b/tests/portage_util/test_uniqueArray.py index 654eb4b1c..bc0b750b9 100644 --- a/tests/portage_util/test_uniqueArray.py +++ b/tests/portage_util/test_uniqueArray.py @@ -4,8 +4,23 @@ # $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) ) diff --git a/tests/portage_util/test_varExpand.py b/tests/portage_util/test_varExpand.py index e7bb62b67..f36027273 100644 --- a/tests/portage_util/test_varExpand.py +++ b/tests/portage_util/test_varExpand.py @@ -4,8 +4,57 @@ # $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 ) )