More portage_util tests
authorAlec Warner <antarus@gentoo.org>
Thu, 11 Jan 2007 08:45:13 +0000 (08:45 -0000)
committerAlec Warner <antarus@gentoo.org>
Thu, 11 Jan 2007 08:45:13 +0000 (08:45 -0000)
svn path=/main/trunk/; revision=5547

tests/portage_util/test_stackDicts.py
tests/portage_util/test_uniqueArray.py
tests/portage_util/test_varExpand.py

index dd07435091e2a9815e49f3d0c1b37cde3f40ec20..ac0e67ef81f6ca4861d62a9b79ca7860d09e1375 100644 (file)
@@ -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]) )
index 654eb4b1c7c262024cfaf7c439d6663e21732d12..bc0b750b994c80d679e342b6627f732d7ffb49b3 100644 (file)
@@ -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) )
index e7bb62b6735b576972515977642f99ee3bd0ce63..f3602727359f3eb777c18797a164c5e72aca4711 100644 (file)
@@ -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 ) )