From c78d5fc325f9ed1cbac049e2b0bb52948a084e09 Mon Sep 17 00:00:00 2001 From: Alec Warner Date: Thu, 1 Feb 2007 18:58:23 +0000 Subject: A somewhat more intelligent layout, move tests into portaage namespace so we can import them easier, seems to be a more common layout from what I've seen. Also rewrite the test runner to work with new layout svn path=/main/trunk/; revision=5863 --- pym/portage/tests/__init__.py | 55 ++++++++++++++ pym/portage/tests/portage/__init__.py | 4 ++ pym/portage/tests/portage/dep/__init__.py | 4 ++ pym/portage/tests/portage/dep/test_dep_getcpv.py | 41 +++++++++++ pym/portage/tests/portage/dep/test_dep_getslot.py | 31 ++++++++ .../tests/portage/dep/test_dep_getusedeps.py | 39 ++++++++++ pym/portage/tests/portage/dep/test_get_operator.py | 31 ++++++++ pym/portage/tests/portage/dep/test_isjustname.py | 25 +++++++ pym/portage/tests/portage/dep/test_isvalidatom.py | 38 ++++++++++ .../tests/portage/dep/test_match_from_list.py | 31 ++++++++ pym/portage/tests/portage/news/__init__.py | 4 ++ pym/portage/tests/portage/news/test_NewsItem.py | 83 ++++++++++++++++++++++ pym/portage/tests/portage/util/__init__.py | 5 ++ pym/portage/tests/portage/util/test_grabdict.py | 12 ++++ .../tests/portage/util/test_normalizedPath.py | 15 ++++ .../tests/portage/util/test_stackDictList.py | 18 +++++ pym/portage/tests/portage/util/test_stackDicts.py | 37 ++++++++++ pym/portage/tests/portage/util/test_stackLists.py | 20 ++++++ pym/portage/tests/portage/util/test_uniqueArray.py | 26 +++++++ pym/portage/tests/portage/util/test_varExpand.py | 60 ++++++++++++++++ pym/portage/tests/portage/versions/__init__.py | 4 ++ pym/portage/tests/portage/versions/test_vercmp.py | 40 +++++++++++ pym/portage/tests/runTests | 20 ++++++ 23 files changed, 643 insertions(+) create mode 100644 pym/portage/tests/__init__.py create mode 100644 pym/portage/tests/portage/__init__.py create mode 100644 pym/portage/tests/portage/dep/__init__.py create mode 100644 pym/portage/tests/portage/dep/test_dep_getcpv.py create mode 100644 pym/portage/tests/portage/dep/test_dep_getslot.py create mode 100644 pym/portage/tests/portage/dep/test_dep_getusedeps.py create mode 100644 pym/portage/tests/portage/dep/test_get_operator.py create mode 100644 pym/portage/tests/portage/dep/test_isjustname.py create mode 100644 pym/portage/tests/portage/dep/test_isvalidatom.py create mode 100644 pym/portage/tests/portage/dep/test_match_from_list.py create mode 100644 pym/portage/tests/portage/news/__init__.py create mode 100644 pym/portage/tests/portage/news/test_NewsItem.py create mode 100644 pym/portage/tests/portage/util/__init__.py create mode 100644 pym/portage/tests/portage/util/test_grabdict.py create mode 100644 pym/portage/tests/portage/util/test_normalizedPath.py create mode 100644 pym/portage/tests/portage/util/test_stackDictList.py create mode 100644 pym/portage/tests/portage/util/test_stackDicts.py create mode 100644 pym/portage/tests/portage/util/test_stackLists.py create mode 100644 pym/portage/tests/portage/util/test_uniqueArray.py create mode 100644 pym/portage/tests/portage/util/test_varExpand.py create mode 100644 pym/portage/tests/portage/versions/__init__.py create mode 100644 pym/portage/tests/portage/versions/test_vercmp.py create mode 100755 pym/portage/tests/runTests (limited to 'pym') diff --git a/pym/portage/tests/__init__.py b/pym/portage/tests/__init__.py new file mode 100644 index 00000000..389cd241 --- /dev/null +++ b/pym/portage/tests/__init__.py @@ -0,0 +1,55 @@ +# 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'] ] diff --git a/pym/portage/tests/portage/__init__.py b/pym/portage/tests/portage/__init__.py new file mode 100644 index 00000000..920c2f7e --- /dev/null +++ b/pym/portage/tests/portage/__init__.py @@ -0,0 +1,4 @@ +# tests/portage/__init__.py -- Portage Unit Test functionality +# Copyright 2006 Gentoo Foundation +# Distributed under the terms of the GNU General Public License v2 +# $Id$ diff --git a/pym/portage/tests/portage/dep/__init__.py b/pym/portage/tests/portage/dep/__init__.py new file mode 100644 index 00000000..a3226c13 --- /dev/null +++ b/pym/portage/tests/portage/dep/__init__.py @@ -0,0 +1,4 @@ +# 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$ diff --git a/pym/portage/tests/portage/dep/test_dep_getcpv.py b/pym/portage/tests/portage/dep/test_dep_getcpv.py new file mode 100644 index 00000000..11fd1a72 --- /dev/null +++ b/pym/portage/tests/portage/dep/test_dep_getcpv.py @@ -0,0 +1,41 @@ +# 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 diff --git a/pym/portage/tests/portage/dep/test_dep_getslot.py b/pym/portage/tests/portage/dep/test_dep_getslot.py new file mode 100644 index 00000000..d3b38917 --- /dev/null +++ b/pym/portage/tests/portage/dep/test_dep_getslot.py @@ -0,0 +1,31 @@ +# 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:"), "" ) diff --git a/pym/portage/tests/portage/dep/test_dep_getusedeps.py b/pym/portage/tests/portage/dep/test_dep_getusedeps.py new file mode 100644 index 00000000..d191d43c --- /dev/null +++ b/pym/portage/tests/portage/dep/test_dep_getusedeps.py @@ -0,0 +1,39 @@ +# 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 + "]" ), [] ) diff --git a/pym/portage/tests/portage/dep/test_get_operator.py b/pym/portage/tests/portage/dep/test_get_operator.py new file mode 100644 index 00000000..b41fab0d --- /dev/null +++ b/pym/portage/tests/portage/dep/test_get_operator.py @@ -0,0 +1,31 @@ +# 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 , "=*" ) diff --git a/pym/portage/tests/portage/dep/test_isjustname.py b/pym/portage/tests/portage/dep/test_isjustname.py new file mode 100644 index 00000000..e419e3f2 --- /dev/null +++ b/pym/portage/tests/portage/dep/test_isjustname.py @@ -0,0 +1,25 @@ +# 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) ) diff --git a/pym/portage/tests/portage/dep/test_isvalidatom.py b/pym/portage/tests/portage/dep/test_isvalidatom.py new file mode 100644 index 00000000..88250e96 --- /dev/null +++ b/pym/portage/tests/portage/dep/test_isvalidatom.py @@ -0,0 +1,38 @@ +# 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 ), + ( "~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] ) ) diff --git a/pym/portage/tests/portage/dep/test_match_from_list.py b/pym/portage/tests/portage/dep/test_match_from_list.py new file mode 100644 index 00000000..4868184a --- /dev/null +++ b/pym/portage/tests/portage/dep/test_match_from_list.py @@ -0,0 +1,31 @@ +# 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 diff --git a/pym/portage/tests/portage/news/__init__.py b/pym/portage/tests/portage/news/__init__.py new file mode 100644 index 00000000..aeaa4919 --- /dev/null +++ b/pym/portage/tests/portage/news/__init__.py @@ -0,0 +1,4 @@ +# 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$ diff --git a/pym/portage/tests/portage/news/test_NewsItem.py b/pym/portage/tests/portage/news/test_NewsItem.py new file mode 100644 index 00000000..22ef298d --- /dev/null +++ b/pym/portage/tests/portage/news/test_NewsItem.py @@ -0,0 +1,83 @@ +# 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 +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 ) diff --git a/pym/portage/tests/portage/util/__init__.py b/pym/portage/tests/portage/util/__init__.py new file mode 100644 index 00000000..9a66903d --- /dev/null +++ b/pym/portage/tests/portage/util/__init__.py @@ -0,0 +1,5 @@ +# 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$ + diff --git a/pym/portage/tests/portage/util/test_grabdict.py b/pym/portage/tests/portage/util/test_grabdict.py new file mode 100644 index 00000000..9f7b5892 --- /dev/null +++ b/pym/portage/tests/portage/util/test_grabdict.py @@ -0,0 +1,12 @@ +# 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 diff --git a/pym/portage/tests/portage/util/test_normalizedPath.py b/pym/portage/tests/portage/util/test_normalizedPath.py new file mode 100644 index 00000000..bd575d26 --- /dev/null +++ b/pym/portage/tests/portage/util/test_normalizedPath.py @@ -0,0 +1,15 @@ +# 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) diff --git a/pym/portage/tests/portage/util/test_stackDictList.py b/pym/portage/tests/portage/util/test_stackDictList.py new file mode 100644 index 00000000..9e7a38ba --- /dev/null +++ b/pym/portage/tests/portage/util/test_stackDictList.py @@ -0,0 +1,18 @@ +# 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] ) diff --git a/pym/portage/tests/portage/util/test_stackDicts.py b/pym/portage/tests/portage/util/test_stackDicts.py new file mode 100644 index 00000000..9d963744 --- /dev/null +++ b/pym/portage/tests/portage/util/test_stackDicts.py @@ -0,0 +1,37 @@ +# 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] ) diff --git a/pym/portage/tests/portage/util/test_stackLists.py b/pym/portage/tests/portage/util/test_stackLists.py new file mode 100644 index 00000000..3fc02832 --- /dev/null +++ b/pym/portage/tests/portage/util/test_stackLists.py @@ -0,0 +1,20 @@ +# 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] ) diff --git a/pym/portage/tests/portage/util/test_uniqueArray.py b/pym/portage/tests/portage/util/test_uniqueArray.py new file mode 100644 index 00000000..62a31532 --- /dev/null +++ b/pym/portage/tests/portage/util/test_uniqueArray.py @@ -0,0 +1,26 @@ +# 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) ) diff --git a/pym/portage/tests/portage/util/test_varExpand.py b/pym/portage/tests/portage/util/test_varExpand.py new file mode 100644 index 00000000..47dc7de2 --- /dev/null +++ b/pym/portage/tests/portage/util/test_varExpand.py @@ -0,0 +1,60 @@ +# 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 ) ) diff --git a/pym/portage/tests/portage/versions/__init__.py b/pym/portage/tests/portage/versions/__init__.py new file mode 100644 index 00000000..5e5b216f --- /dev/null +++ b/pym/portage/tests/portage/versions/__init__.py @@ -0,0 +1,4 @@ +# 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$ diff --git a/pym/portage/tests/portage/versions/test_vercmp.py b/pym/portage/tests/portage/versions/test_vercmp.py new file mode 100644 index 00000000..ee3d3774 --- /dev/null +++ b/pym/portage/tests/portage/versions/test_vercmp.py @@ -0,0 +1,40 @@ +# 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])) diff --git a/pym/portage/tests/runTests b/pym/portage/tests/runTests new file mode 100755 index 00000000..6781796f --- /dev/null +++ b/pym/portage/tests/runTests @@ -0,0 +1,20 @@ +#!/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) -- cgit v1.2.3-65-gdbad