--- /dev/null
+# tests/__init__.py -- Portage Unit Test functionality
+# Copyright 2006 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+# $Id$
+
+import os, unittest
+
+def main():
+
+ testDirs = ["portage", "portage/util","portage/versions", "portage/dep"]
+
+ suite = unittest.TestSuite()
+
+ basedir = os.path.dirname(__file__)
+ for mydir in testDirs:
+ suite.addTests(getTests(os.path.join(basedir, mydir), basedir) )
+
+ return unittest.TextTestRunner(verbosity=2).run(suite)
+
+def my_import(name):
+ mod = __import__(name)
+ components = name.split('.')
+ for comp in components[1:]:
+ mod = getattr(mod, comp)
+ return mod
+
+def getTests( path, base_path ):
+ """
+
+ path is the path to a given subdir ( 'portage/' for example)
+ This does a simple filter on files in that dir to give us modules
+ to import
+
+ """
+ import os
+ files = os.listdir( path )
+ files = [ f[:-3] for f in files if f.startswith("test_") and f.endswith(".py") ]
+ parent_path = path[len(base_path)+1:]
+ parent_module = ".".join(("portage","tests", parent_path))
+ parent_module = parent_module.replace('/','.')
+ result = []
+ for mymodule in files:
+ try:
+ # Make the trailing / a . for module importing
+ modname = ".".join((parent_module, mymodule))
+ mod = my_import(modname)
+ result.append( unittest.TestLoader().loadTestsFromModule(mod) )
+ except ImportError:
+ raise
+ return result
+
+test_cpvs = ['sys-apps/portage','virtual/portage']
+test_versions = ['1.0', '1.0-r1','2.3_p4','1.0_alpha57']
+test_slots = [ None, '1','gentoo-sources-2.6.17','spankywashere']
+test_usedeps = ['foo','-bar', ['foo','bar'],['foo','-bar'] ]
--- /dev/null
+# tests/portage/__init__.py -- Portage Unit Test functionality
+# Copyright 2006 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+# $Id$
--- /dev/null
+# tests/portage.dep/__init__.py -- Portage Unit Test functionality
+# Copyright 2006 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+# $Id$
--- /dev/null
+# test_dep_getcpv.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
+from portage.dep import dep_getcpv
+
+class DepGetCPV(TestCase):
+ """ A simple testcase for isvalidatom
+ """
+
+ def testDepGetCPV(self):
+
+ prefix_ops = ["<", ">", "=", "~", "!", "<=",
+ ">=", "!=", "!<", "!>", "!~",""]
+
+ bad_prefix_ops = [ ">~", "<~", "~>", "~<" ]
+ postfix_ops = [ "*", "" ]
+
+ cpvs = ["sys-apps/portage", "sys-apps/portage-2.1", "sys-apps/portage-2.1",
+ "sys-apps/portage-2.1"]
+ slots = [None,":",":2"]
+ for cpv in cpvs:
+ for slot in slots:
+ for prefix in prefix_ops:
+ for postfix in postfix_ops:
+ if slot:
+ self.assertEqual( dep_getcpv(
+ prefix + cpv + slot + postfix ), cpv )
+ else:
+ self.assertEqual( dep_getcpv(
+ prefix + cpv + postfix ), cpv )
+ for prefix in bad_prefix_ops:
+ for postfix in postfix_ops:
+ if slot:
+ self.assertNotEqual( dep_getcpv(
+ prefix + cpv + slot + postfix ), cpv )
+ else:
+ self.assertNotEqual( dep_getcpv(
+ prefix + cpv + postfix ), cpv )
\ No newline at end of file
--- /dev/null
+# test_dep_getslot.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
+from portage.dep import dep_getslot
+
+class DepGetSlot(TestCase):
+ """ A simple testcase for isvalidatom
+ """
+
+ def testDepGetSlot(self):
+
+ slot_char = ":"
+ slots = ( "a", "1.2", "1", "IloveVapier", None )
+ cpvs = ["sys-apps/portage"]
+ versions = ["2.1.1","2.1-r1"]
+ for cpv in cpvs:
+ for version in versions:
+ for slot in slots:
+ mycpv = cpv[:]
+ if version:
+ cpv += version
+ if slot:
+ self.assertEqual( dep_getslot(
+ cpv + slot_char + slot ), slot )
+ else:
+ self.assertEqual( dep_getslot( cpv ), slot )
+
+ self.assertEqual( dep_getslot( "sys-apps/portage:"), "" )
--- /dev/null
+# test_dep_getusedeps.py -- Portage Unit Testing Functionality
+# Copyright 2007 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+# $Id: test_dep_getslot.py 5794 2007-01-27 18:16:08Z antarus $
+
+from unittest import TestCase
+from portage.dep import dep_getusedeps
+
+import sys
+from portage.tests import test_cpvs, test_slots, test_versions, test_usedeps
+
+class DepGetUseDeps(TestCase):
+ """ A simple testcase for dep_getusedeps
+ """
+
+ def testDepGetUseDeps(self):
+
+
+ for mycpv in test_cpvs:
+ for version in test_versions:
+ for slot in test_slots:
+ for use in test_usedeps:
+ cpv = mycpv[:]
+ if version:
+ cpv += version
+ if slot:
+ cpv += ":" + slot
+ if isinstance( use, list ):
+ for u in use:
+ cpv = cpv + "[" + u + "]"
+ self.assertEqual( dep_getusedeps(
+ cpv ), use )
+ else:
+ if len(use):
+ self.assertEqual( dep_getusedeps(
+ cpv + "[" + use + "]" ), [use] )
+ else:
+ self.assertEqual( dep_getusedeps(
+ cpv + "[" + use + "]" ), [] )
--- /dev/null
+# test_match_from_list.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
+from portage.dep import get_operator
+
+class GetOperator(TestCase):
+
+ def testGetOperator(self):
+
+ # get_operator does not validate operators
+ tests = [ ( "~", "~" ), ( "=", "=" ), ( ">", ">" ),
+ ( ">=", ">=" ), ( "<=", "<=" ) , ( "", None ),
+ ( ">~", ">" ), ("~<", "~"), ( "=~", "=" ),
+ ( "=>", "=" ), ("=<", "=") ]
+
+ test_cpvs = ["sys-apps/portage","sys-apps/portage-2.1"]
+ slots = [ None,"1","linux-2.5.6" ]
+ for cpv in test_cpvs:
+ for test in tests:
+ for slot in slots:
+ atom = cpv[:]
+ if slot:
+ atom += ":" + slot
+ result = get_operator( test[0] + atom )
+ self.assertEqual( result, test[1] )
+
+ result = get_operator( "=sys-apps/portage*" )
+ self.assertEqual( result , "=*" )
--- /dev/null
+# test_isjustname.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
+from portage.dep import isjustname
+
+class IsJustName(TestCase):
+
+ def testIsJustName(self):
+
+ cats = ( "", "sys-apps/", "foo/", "virtual/" )
+ pkgs = ( "portage", "paludis", "pkgcore", "notARealPkg" )
+ vers = ( "", "-2.0-r3", "-1.0_pre2", "-3.1b" )
+
+ for pkg in pkgs:
+ for cat in cats:
+ for ver in vers:
+ if len(ver):
+ self.assertFalse( isjustname( cat + pkg + ver ),
+ msg="isjustname(%s) is True!" % (cat + pkg + ver) )
+ else:
+ self.assertTrue( isjustname( cat + pkg + ver ),
+ msg="isjustname(%s) is False!" % (cat + pkg + ver) )
--- /dev/null
+# test_isvalidatom.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
+from portage.dep import isvalidatom
+
+class IsValidAtom(TestCase):
+ """ A simple testcase for isvalidatom
+ """
+
+ def testIsValidAtom(self):
+
+ tests = [ ( "sys-apps/portage", True ),
+ ( "=sys-apps/portage-2.1", True ),
+ ( "=sys-apps/portage-2.1*", True ),
+ ( ">=sys-apps/portage-2.1", True ),
+ ( "<=sys-apps/portage-2.1", True ),
+ ( ">sys-apps/portage-2.1", True ),
+ ( "<sys-apps/portage-2.1", True ),
+ ( "~sys-apps/portage-2.1", True ),
+ ( "sys-apps/portage-2.1:foo", True ),
+ ( "sys-apps/portage-2.1:", False ),
+ ( ">~cate-gory/foo-1.0", False ),
+ ( ">~category/foo-1.0", False ),
+ ( "<~category/foo-1.0", False ),
+ ( "###cat/foo-1.0", False ),
+ ( "~sys-apps/portage", False ),
+ ( "portage", False ) ]
+
+ for test in tests:
+ if test[1]:
+ atom_type = "valid"
+ else:
+ atom_type = "invalid"
+ self.assertEqual( bool(isvalidatom( test[0] )), test[1],
+ msg="isvalidatom(%s) != %s" % ( test[0], test[1] ) )
--- /dev/null
+# test_match_from_list.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
+from portage.dep import match_from_list
+
+class AtomCmpEqualGlob(TestCase):
+ """ A simple testcase for =* glob matching
+ """
+
+ def testEqualGlobPass(self):
+ tests = [ ("=sys-apps/portage-45*", "sys-apps/portage-045" ),
+ ("=sys-fs/udev-1*", "sys-fs/udev-123"),
+ ("=sys-fs/udev-4*", "sys-fs/udev-456" ) ]
+
+# I need to look up the cvs syntax
+# ("=sys-fs/udev_cvs*","sys-fs/udev_cvs_pre4" ) ]
+
+ for test in tests:
+ self.assertEqual( len(match_from_list( test[0], [test[1]] )), 1 )
+
+ def testEqualGlobFail(self):
+ tests = [ ("=sys-apps/portage-2*", "sys-apps/portage-2.1" ),
+ ("=sys-apps/portage-2.1*", "sys-apps/portage-2.1.2" ) ]
+ for test in tests:
+ try:
+ self.assertEqual( len( match_from_list( test[0], [test[1]] ) ), 1 )
+ except TypeError: # failure is ok here
+ pass
--- /dev/null
+# tests/portage.news/__init__.py -- Portage Unit Test functionality
+# Copyright 2007 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+# $Id$
--- /dev/null
+# test_NewsItem.py -- Portage Unit Testing Functionality
+# Copyright 2007 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+# $Id: test_varExpand.py 5596 2007-01-12 08:08:53Z antarus $
+
+from unittest import TestCase, TestLoader
+from portage.news import NewsItem
+from portage.const import PROFILE_PATH
+
+class NewsItemTestCase(TestCase):
+
+ self.fakeItem = """
+Title: YourSQL Upgrades from 4.0 to 4.1
+Author: Ciaran McCreesh <ciaranm@gentoo.org>
+Content-Type: text/plain
+Posted: 01-Nov-2005
+Revision: 1
+#Display-If-Installed:
+#Display-If-Profile:
+#Display-If-Arch:
+
+YourSQL databases created using YourSQL version 4.0 are incompatible
+with YourSQL version 4.1 or later. There is no reliable way to
+automate the database format conversion, so action from the system
+administrator is required before an upgrade can take place.
+
+Please see the Gentoo YourSQL Upgrade Guide for instructions:
+
+ http://www.gentoo.org/doc/en/yoursql-upgrading.xml
+
+Also see the official YourSQL documentation:
+
+ http://dev.yoursql.com/doc/refman/4.1/en/upgrading-from-4-0.html
+
+After upgrading, you should also recompile any packages which link
+against YourSQL:
+
+ revdep-rebuild --library=libyoursqlclient.so.12
+
+The revdep-rebuild tool is provided by app-portage/gentoolkit.
+"""
+
+ from portage import settings
+ import time
+
+ def testDisplayIfProfile():
+ from portage.const import PROFILE_PATH
+ tmpItem = self.fakeItem.replace("#Display-If-Profile:", "Display-If-Profile: %s" %
+ os.readlink( PROFILE_PATH ) )
+
+ item = _processItem(tmpItem)
+ self.assertTrue( item.isRelevant( os.readlink( PROFILE_PATH ) ),
+ msg="Expected %s to be relevant, but it was not!" % tmpItem )
+
+ def testDisplayIfInstalled():
+ tmpItem = self.fakeItem.replace("#Display-If-Installed:", "Display-If-Profile: %s" %
+ "sys-apps/portage" )
+
+ item = _processItem(tmpItem)
+ self.assertTrue( item.isRelevant( portage.settings ),
+ msg="Expected %s to be relevant, but it was not!" % tmpItem )
+
+
+ def testDisplayIfKeyword():
+ from portage import settings
+ tmpItem = self.fakeItem.replace("#Display-If-Keyword:", "Display-If-Keyword: %s" %
+ settings["ACCEPT_KEYWORDS"].split()[0] )
+
+ item = _processItem(tmpItem)
+ self.assertTrue( item.isRelevant( os.readlink( PROFILE_PATH ) ),
+ msg="Expected %s to be relevant, but it was not!" % tmpItem )
+
+
+ def _processItem( self, item ):
+
+ path = os.path.join( settings["PORTAGE_TMPDIR"], str(time.time())
+ f = open( os.path.join( path )
+ f.write(item)
+ f.close
+ try:
+ return NewsItem( path, 0 )
+ except TypeError:
+ self.fail("Error while processing news item %s" % path )
--- /dev/null
+# tests/portage.util/__init__.py -- Portage Unit Test functionality
+# Copyright 2006 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+# $Id$
+
--- /dev/null
+# test_grabDict.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 grabdict
+
+class GrabDictTestCase(TestCase):
+
+ def testGrabDictPass(self):
+ pass
--- /dev/null
+# test_normalizePath.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
+
+class NormalizePathTestCase(TestCase):
+
+ def testNormalizePath(self):
+
+ from portage.util import normalize_path
+ path = "///foo/bar/baz"
+ good = "/foo/bar/baz"
+ self.assertEqual(normalize_path(path), good)
--- /dev/null
+# test_stackDictList.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
+
+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']} ))
+ for test in tests:
+ self.assertEqual(
+ stack_dictlist([test[0],test[1]],incremental=test[2]), test[3] )
--- /dev/null
+# test_stackDicts.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
+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 ], 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] )
+
+ 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.assertNotEqual( result , test[1] )
--- /dev/null
+# test_stackLists.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
+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 ) ]
+
+ for test in tests:
+ result = stack_lists( test[0], test[2] )
+ self.assertEqual( result , test[1] )
--- /dev/null
+# test_uniqueArray.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
+from portage.util import unique_array
+
+class UniqueArrayTestCase(TestCase):
+
+ 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) )
--- /dev/null
+# 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 ) )
--- /dev/null
+# tests/portage.versions/__init__.py -- Portage Unit Test functionality
+# Copyright 2006 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+# $Id$
--- /dev/null
+# test_vercmp.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
+from portage.versions import vercmp
+
+class VerCmpTestCase(TestCase):
+ """ A simple testCase for portage.versions.vercmp()
+ """
+
+ def testVerCmpGreater(self):
+
+ tests = [ ( "6.0", "5.0"), ("5.0","5")]
+ for test in tests:
+ self.failIf( vercmp( test[0], test[1] ) <= 0, msg="%s < %s? Wrong!" % (test[0],test[1]) )
+
+ def testVerCmpLess(self):
+ """
+ pre < alpha < beta < rc < p -> test each of these, they are inductive (or should be..)
+ """
+ tests = [ ( "4.0", "5.0"), ("5", "5.0"), ("1.0_pre2","1.0_p2"),
+ ("1.0_alpha2", "1.0_p2"),("1.0_alpha1", "1.0_beta1"),("1.0_beta3","1.0_rc3")]
+ for test in tests:
+ self.failIf( vercmp( test[0], test[1]) >= 0, msg="%s > %s? Wrong!" % (test[0],test[1]))
+
+
+ def testVerCmpEqual(self):
+
+ tests = [ ("4.0", "4.0") ]
+ for test in tests:
+ self.failIf( vercmp( test[0], test[1]) != 0, msg="%s != %s? Wrong!" % (test[0],test[1]))
+
+ def testVerNotEqual(self):
+
+ tests = [ ("1","2"),("1.0_alpha","1.0_pre"),("1.0_beta","1.0_alpha"),
+ ("0", "0.0")]
+ for test in tests:
+ self.failIf( vercmp( test[0], test[1]) == 0, msg="%s == %s? Wrong!" % (test[0],test[1]))
--- /dev/null
+#!/usr/bin/python
+# runTests.py -- Portage Unit Test Functionality
+# Copyright 2006 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+# $Id$
+
+
+import os, sys
+import os.path as osp
+
+# Insert our parent dir so we can do shiny import "tests"
+# This line courtesy of Marienz and Pkgcore ;)
+sys.path.insert(0, osp.dirname(osp.dirname(osp.dirname(osp.abspath(__file__)))))
+
+import portage.tests as tests
+
+if __name__ == "__main__":
+ result = tests.main()
+ if result.failures:
+ sys.exit(1)