diff options
Diffstat (limited to 'pym/portage/tests/util')
-rw-r--r-- | pym/portage/tests/util/test_getconfig.py | 31 | ||||
-rw-r--r-- | pym/portage/tests/util/test_stackDictList.py | 12 | ||||
-rw-r--r-- | pym/portage/tests/util/test_stackDicts.py | 41 | ||||
-rw-r--r-- | pym/portage/tests/util/test_stackLists.py | 18 | ||||
-rw-r--r-- | pym/portage/tests/util/test_uniqueArray.py | 14 | ||||
-rw-r--r-- | pym/portage/tests/util/test_varExpand.py | 80 | ||||
-rw-r--r-- | pym/portage/tests/util/test_whirlpool.py | 4 |
7 files changed, 114 insertions, 86 deletions
diff --git a/pym/portage/tests/util/test_getconfig.py b/pym/portage/tests/util/test_getconfig.py index f13b75358..e5fd60f6d 100644 --- a/pym/portage/tests/util/test_getconfig.py +++ b/pym/portage/tests/util/test_getconfig.py @@ -1,13 +1,15 @@ -# Copyright 2010-2012 Gentoo Foundation +# Copyright 2010-2014 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 import tempfile from portage import os +from portage import shutil from portage import _unicode_encode from portage.const import PORTAGE_BASE_PATH from portage.tests import TestCase from portage.util import getconfig +from portage.exception import ParseError class GetConfigTestCase(TestCase): """ @@ -18,8 +20,8 @@ class GetConfigTestCase(TestCase): _cases = { 'FETCHCOMMAND' : 'wget -t 3 -T 60 --passive-ftp -O "${DISTDIR}/${FILE}" "${URI}"', 'FETCHCOMMAND_RSYNC' : 'rsync -avP "${URI}" "${DISTDIR}/${FILE}"', - 'FETCHCOMMAND_SFTP' : 'bash -c "x=\\${2#sftp://} ; host=\\${x%%/*} ; port=\\${host##*:} ; host=\\${host%:*} ; [[ \\${host} = \\${port} ]] && port=22 ; exec sftp -P \\${port} \\"\\${host}:/\\${x#*/}\\" \\"\\$1\\"" sftp "${DISTDIR}/${FILE}" "${URI}"', - 'FETCHCOMMAND_SSH' : 'bash -c "x=\\${2#ssh://} ; host=\\${x%%/*} ; port=\\${host##*:} ; host=\\${host%:*} ; [[ \\${host} = \\${port} ]] && port=22 ; exec rsync --rsh=\\"ssh -p\\${port}\\" -avP \\"\\${host}:/\\${x#*/}\\" \\"\\$1\\"" rsync "${DISTDIR}/${FILE}" "${URI}"', + 'FETCHCOMMAND_SFTP' : 'bash -c "x=\\${2#sftp://} ; host=\\${x%%/*} ; port=\\${host##*:} ; host=\\${host%:*} ; [[ \\${host} = \\${port} ]] && port=22 ; eval \\"declare -a ssh_opts=(\\${3})\\" ; exec sftp -P \\${port} \\"\\${ssh_opts[@]}\\" \\"\\${host}:/\\${x#*/}\\" \\"\\$1\\"" sftp "${DISTDIR}/${FILE}" "${URI}" "${PORTAGE_SSH_OPTS}"', + 'FETCHCOMMAND_SSH' : 'bash -c "x=\\${2#ssh://} ; host=\\${x%%/*} ; port=\\${host##*:} ; host=\\${host%:*} ; [[ \\${host} = \\${port} ]] && port=22 ; exec rsync --rsh=\\"ssh -p\\${port} \\${3}\\" -avP \\"\\${host}:/\\${x#*/}\\" \\"\\$1\\"" rsync "${DISTDIR}/${FILE}" "${URI}" "${PORTAGE_SSH_OPTS}"', 'PORTAGE_ELOG_MAILSUBJECT' : '[portage] ebuild log for ${PACKAGE} on ${HOST}' } @@ -31,6 +33,29 @@ class GetConfigTestCase(TestCase): for k, v in self._cases.items(): self.assertEqual(d[k], v) + def testGetConfigSourceLex(self): + try: + tempdir = tempfile.mkdtemp() + make_conf_file = os.path.join(tempdir, 'make.conf') + with open(make_conf_file, 'w') as f: + f.write('source "${DIR}/sourced_file"\n') + sourced_file = os.path.join(tempdir, 'sourced_file') + with open(sourced_file, 'w') as f: + f.write('PASSES_SOURCING_TEST="True"\n') + + d = getconfig(make_conf_file, allow_sourcing=True, expand={"DIR": tempdir}) + + # PASSES_SOURCING_TEST should exist in getconfig result. + self.assertTrue(d is not None) + self.assertEqual("True", d['PASSES_SOURCING_TEST']) + + # With allow_sourcing=True and empty expand map, this should + # throw a FileNotFound exception. + self.assertRaisesMsg("An empty expand map should throw an exception", + ParseError, getconfig, make_conf_file, allow_sourcing=True, expand={}) + finally: + shutil.rmtree(tempdir) + def testGetConfigProfileEnv(self): # Test the mode which is used to parse /etc/env.d and /etc/profile.env. diff --git a/pym/portage/tests/util/test_stackDictList.py b/pym/portage/tests/util/test_stackDictList.py index 678001c38..25a723c69 100644 --- a/pym/portage/tests/util/test_stackDictList.py +++ b/pym/portage/tests/util/test_stackDictList.py @@ -8,10 +8,12 @@ class StackDictListTestCase(TestCase): def testStackDictList(self): from portage.util import stack_dictlist - - tests = [ ({'a':'b'},{'x':'y'},False,{'a':['b'],'x':['y']}) ] - tests.append(( {'KEYWORDS':['alpha','x86']},{'KEYWORDS':['-*']},True,{} )) - tests.append(( {'KEYWORDS':['alpha','x86']},{'KEYWORDS':['-x86']},True,{'KEYWORDS':['alpha']} )) + + tests = [ + ({'a': 'b'}, {'x': 'y'}, False, {'a': ['b'], 'x': ['y']}), + ({'KEYWORDS': ['alpha', 'x86']}, {'KEYWORDS': ['-*']}, True, {}), + ({'KEYWORDS': ['alpha', 'x86']}, {'KEYWORDS': ['-x86']}, True, {'KEYWORDS': ['alpha']}), + ] for test in tests: self.assertEqual( - stack_dictlist([test[0],test[1]],incremental=test[2]), test[3] ) + stack_dictlist([test[0], test[1]], incremental=test[2]), test[3]) diff --git a/pym/portage/tests/util/test_stackDicts.py b/pym/portage/tests/util/test_stackDicts.py index 0d2cadd0c..0c1dcdb78 100644 --- a/pym/portage/tests/util/test_stackDicts.py +++ b/pym/portage/tests/util/test_stackDicts.py @@ -7,30 +7,27 @@ from portage.util import stack_dicts class StackDictsTestCase(TestCase): - - 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 ], {}, False, [], False ), - ( [ None, {}], {}, False, [], True ) ] + 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], {}, False, [], False), + ([None, {}], {}, False, [], True) + ] for test in tests: - result = stack_dicts( test[0], test[2], test[3], test[4] ) - self.assertEqual( result, test[1] ) - + result = stack_dicts(test[0], test[2], test[3], test[4]) + self.assertEqual(result, test[1]) + def testStackDictsFail(self): - - tests = [ ( [ None, {} ], None, False, [], True ), - ( [ { "a":"b"}, {"a":"c" } ], { "a":"b c" }, - False, [], False ) ] + + 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.assertNotEqual( result , test[1] ) + result = stack_dicts(test[0], test[2], test[3], test[4]) + self.assertNotEqual(result, test[1]) diff --git a/pym/portage/tests/util/test_stackLists.py b/pym/portage/tests/util/test_stackLists.py index e52477255..3ba69ecd2 100644 --- a/pym/portage/tests/util/test_stackLists.py +++ b/pym/portage/tests/util/test_stackLists.py @@ -6,14 +6,16 @@ from portage.tests import TestCase from portage.util import stack_lists class StackListsTestCase(TestCase): - + def testStackLists(self): - - tests = [ ( [ ['a','b','c'], ['d','e','f'] ], ['a','c','b','e','d','f'], False ), - ( [ ['a','x'], ['b','x'] ], ['a','x','b'], False ), - ( [ ['a','b','c'], ['-*'] ], [], True ), - ( [ ['a'], ['-a'] ], [], True ) ] + + tests = [ + ([['a', 'b', 'c'], ['d', 'e', 'f']], ['a', 'c', 'b', 'e', 'd', 'f'], False), + ([['a', 'x'], ['b', 'x']], ['a', 'x', 'b'], False), + ([['a', 'b', 'c'], ['-*']], [], True), + ([['a'], ['-a']], [], True) + ] for test in tests: - result = stack_lists( test[0], test[2] ) - self.assertEqual( set(result) , set(test[1]) ) + result = stack_lists(test[0], test[2]) + self.assertEqual(set(result), set(test[1])) diff --git a/pym/portage/tests/util/test_uniqueArray.py b/pym/portage/tests/util/test_uniqueArray.py index e23428c31..aae88cce8 100644 --- a/pym/portage/tests/util/test_uniqueArray.py +++ b/pym/portage/tests/util/test_uniqueArray.py @@ -7,18 +7,20 @@ from portage.tests import TestCase from portage.util import unique_array class UniqueArrayTestCase(TestCase): - + def testUniqueArrayPass(self): """ test portage.util.uniqueArray() """ - tests = [ ( ["a","a","a",os,os,[],[],[]], ['a',os,[]] ), - ( [1,1,1,2,3,4,4] , [1,2,3,4]) ] + 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] ) + result = unique_array(test[0]) for item in test[1]: number = result.count(item) - self.assertFalse( number != 1, msg=("%s contains %s of %s, " - "should be only 1") % (result, number, item) ) + self.assertFalse(number != 1, msg=("%s contains %s of %s, " + "should be only 1") % (result, number, item)) diff --git a/pym/portage/tests/util/test_varExpand.py b/pym/portage/tests/util/test_varExpand.py index 7b528d6db..498b50ead 100644 --- a/pym/portage/tests/util/test_varExpand.py +++ b/pym/portage/tests/util/test_varExpand.py @@ -6,20 +6,20 @@ from portage.tests import TestCase from portage.util import varexpand class VarExpandTestCase(TestCase): - + def testVarExpandPass(self): - varDict = { "a":"5", "b":"7", "c":"-5" } + varDict = {"a": "5", "b": "7", "c": "-5"} for key in varDict: - result = varexpand( "$%s" % key, varDict ) - - self.assertFalse( result != varDict[key], - msg="Got %s != %s, from varexpand( %s, %s )" % \ - ( result, varDict[key], "$%s" % key, varDict ) ) - result = varexpand( "${%s}" % key, varDict ) - self.assertFalse( result != varDict[key], - msg="Got %s != %s, from varexpand( %s, %s )" % \ - ( result, varDict[key], "${%s}" % key, varDict ) ) + result = varexpand("$%s" % key, varDict) + + self.assertFalse(result != varDict[key], + msg="Got %s != %s, from varexpand(%s, %s)" % + (result, varDict[key], "$%s" % key, varDict)) + result = varexpand("${%s}" % key, varDict) + self.assertFalse(result != varDict[key], + msg="Got %s != %s, from varexpand(%s, %s)" % + (result, varDict[key], "${%s}" % key, varDict)) def testVarExpandBackslashes(self): """ @@ -49,44 +49,44 @@ class VarExpandTestCase(TestCase): ("\\'", "\\'"), ] for test in tests: - result = varexpand( test[0], varDict ) - self.assertFalse( result != test[1], - msg="Got %s != %s from varexpand( %s, %s )" \ - % ( result, test[1], test[0], varDict ) ) + result = varexpand(test[0], varDict) + self.assertFalse(result != test[1], + msg="Got %s != %s from varexpand(%s, %s)" + % (result, test[1], test[0], varDict)) def testVarExpandDoubleQuotes(self): - - varDict = { "a":"5" } - tests = [ ("\"${a}\"", "\"5\"") ] + + varDict = {"a": "5"} + tests = [("\"${a}\"", "\"5\"")] for test in tests: - result = varexpand( test[0], varDict ) - self.assertFalse( result != test[1], - msg="Got %s != %s from varexpand( %s, %s )" \ - % ( result, test[1], test[0], varDict ) ) + result = varexpand(test[0], varDict) + self.assertFalse(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}\'") ] + + varDict = {"a": "5"} + tests = [("\'${a}\'", "\'${a}\'")] for test in tests: - result = varexpand( test[0], varDict ) - self.assertFalse( result != test[1], - msg="Got %s != %s from varexpand( %s, %s )" \ - % ( result, test[1], test[0], varDict ) ) + result = varexpand(test[0], varDict) + self.assertFalse(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" } + varDict = {"a": "5", "b": "7", "c": "15"} - testVars = [ "fail" ] + testVars = ["fail"] for var in testVars: - result = varexpand( "$%s" % var, varDict ) - self.assertFalse( len(result), - msg="Got %s == %s, from varexpand( %s, %s )" \ - % ( result, var, "$%s" % var, varDict ) ) - - result = varexpand( "${%s}" % var, varDict ) - self.assertFalse( len(result), - msg="Got %s == %s, from varexpand( %s, %s )" \ - % ( result, var, "${%s}" % var, varDict ) ) + result = varexpand("$%s" % var, varDict) + self.assertFalse(len(result), + msg="Got %s == %s, from varexpand(%s, %s)" + % (result, var, "$%s" % var, varDict)) + + result = varexpand("${%s}" % var, varDict) + self.assertFalse(len(result), + msg="Got %s == %s, from varexpand(%s, %s)" + % (result, var, "${%s}" % var, varDict)) diff --git a/pym/portage/tests/util/test_whirlpool.py b/pym/portage/tests/util/test_whirlpool.py index dd0de899a..fbe7cae56 100644 --- a/pym/portage/tests/util/test_whirlpool.py +++ b/pym/portage/tests/util/test_whirlpool.py @@ -1,4 +1,4 @@ -# Copyright 2011 Gentoo Foundation +# Copyright 2011-2014 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 import subprocess @@ -11,6 +11,6 @@ from portage.tests import TestCase class WhirlpoolTestCase(TestCase): def testBundledWhirlpool(self): # execute the tests bundled with the whirlpool module - retval = subprocess.call([portage._python_interpreter, "-Wd", + retval = subprocess.call([portage._python_interpreter, "-b", "-Wd", os.path.join(PORTAGE_PYM_PATH, "portage/util/whirlpool.py")]) self.assertEqual(retval, os.EX_OK) |