From be41793f50c29aa6c0d17a8616ce214b71d81e0a Mon Sep 17 00:00:00 2001 From: Alec Warner Date: Wed, 10 Jan 2007 13:35:03 +0000 Subject: Take Genone's suggestion and break the modules up into module oriented fashion. Tests for portage.py go in portage/ and so on and so forth... svn path=/main/trunk/; revision=5525 --- tests/__init__.py | 32 ++++++++++++++----- tests/portage/__init__.py | 4 +++ tests/portage/test_atoms.py | 68 +++++++++++++++++++++++++++++++++++++++++ tests/portage_util/__init__.py | 5 +++ tests/portage_util/test_util.py | 39 +++++++++++++++++++++++ tests/test_atoms.py | 68 ----------------------------------------- tests/test_util.py | 39 ----------------------- 7 files changed, 141 insertions(+), 114 deletions(-) create mode 100644 tests/portage/__init__.py create mode 100644 tests/portage/test_atoms.py create mode 100644 tests/portage_util/__init__.py create mode 100644 tests/portage_util/test_util.py delete mode 100644 tests/test_atoms.py delete mode 100644 tests/test_util.py (limited to 'tests') diff --git a/tests/__init__.py b/tests/__init__.py index a32ca05d3..71d699770 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -7,16 +7,34 @@ import unittest def main(): - tests = ["test_atoms", "test_util"] + testDirs = ["portage/", "portage_util/"] suite = unittest.TestSuite() - for mod in tests: + for dir in testDirs: + suite.addTests(getTests(dir)) + + return unittest.TextTestRunner(verbosity=2).run(suite) + +def getTests( 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") ] + + result = [] + for file in files: try: - loadMod = __import__(mod) - tmpSuite = unittest.TestLoader().loadTestsFromModule(loadMod) - suite.addTest(tmpSuite) + # Make the trailing / a . for module importing + path2 = path[:-1] + "." + file + mod = __import__( path2, globals(), locals(), [path[-1]]) + result.append( unittest.TestLoader().loadTestsFromModule(mod) ) except ImportError: pass - - return unittest.TextTestRunner(verbosity=2).run(suite) + return result diff --git a/tests/portage/__init__.py b/tests/portage/__init__.py new file mode 100644 index 000000000..e1c0ae595 --- /dev/null +++ b/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: __init__.py 5522 2007-01-10 12:30:05Z antarus $ diff --git a/tests/portage/test_atoms.py b/tests/portage/test_atoms.py new file mode 100644 index 000000000..d051fed22 --- /dev/null +++ b/tests/portage/test_atoms.py @@ -0,0 +1,68 @@ +# 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 unittest import TestLoader +from portage_versions import vercmp +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.failIf( len(match_from_list( test[0], [test[1]] )) != 1, + msg="%s should match %s!" % (test[0], test[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.failIf( len( match_from_list( test[0], [test[1]] ) ) != 1, + msg="%s shouldn't match %s!" % (test[0], test[1]) ) + except TypeError: # failure is ok here + pass + +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/tests/portage_util/__init__.py b/tests/portage_util/__init__.py new file mode 100644 index 000000000..ede012f66 --- /dev/null +++ b/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: __init__.py 5522 2007-01-10 12:30:05Z antarus $ + diff --git a/tests/portage_util/test_util.py b/tests/portage_util/test_util.py new file mode 100644 index 000000000..e16da6c1d --- /dev/null +++ b/tests/portage_util/test_util.py @@ -0,0 +1,39 @@ +# test_vercmp.py -- Portage Unit Testing Functionality +# Copyright 2006 Gentoo Foundation +# Distributed under the terms of the GNU General Public License v2 +# $Id: test_vercmp.py 5213 2006-12-08 00:12:41Z antarus $ + +from unittest import TestCase, TestLoader + +class UtilTestCase(TestCase): + + def testUniqueArray(self): + pass + + def testVarexpand(self): + pass + + def testStackLists(self): + pass + + def testStackDicts(self): + pass + + 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.failUnless(stack_dictlist([test[0],test[1]],incremental=test[2]) == test[3], + msg="%s and %s combined, was expecting: %s and got: %s" % (test[0],test[1],test[3], + stack_dictlist([test[0],test[1]],incremental=test[2])) ) + + def testNormalizePath(self): + + from portage_util import normalize_path + path = "///foo/bar/baz" + good = "/foo/bar/baz" + self.failUnless(normalize_path(path) == good, msg="NormalizePath(%s) failed to produce %s" % (path, good)) + diff --git a/tests/test_atoms.py b/tests/test_atoms.py deleted file mode 100644 index d051fed22..000000000 --- a/tests/test_atoms.py +++ /dev/null @@ -1,68 +0,0 @@ -# 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 unittest import TestLoader -from portage_versions import vercmp -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.failIf( len(match_from_list( test[0], [test[1]] )) != 1, - msg="%s should match %s!" % (test[0], test[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.failIf( len( match_from_list( test[0], [test[1]] ) ) != 1, - msg="%s shouldn't match %s!" % (test[0], test[1]) ) - except TypeError: # failure is ok here - pass - -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/tests/test_util.py b/tests/test_util.py deleted file mode 100644 index e16da6c1d..000000000 --- a/tests/test_util.py +++ /dev/null @@ -1,39 +0,0 @@ -# test_vercmp.py -- Portage Unit Testing Functionality -# Copyright 2006 Gentoo Foundation -# Distributed under the terms of the GNU General Public License v2 -# $Id: test_vercmp.py 5213 2006-12-08 00:12:41Z antarus $ - -from unittest import TestCase, TestLoader - -class UtilTestCase(TestCase): - - def testUniqueArray(self): - pass - - def testVarexpand(self): - pass - - def testStackLists(self): - pass - - def testStackDicts(self): - pass - - 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.failUnless(stack_dictlist([test[0],test[1]],incremental=test[2]) == test[3], - msg="%s and %s combined, was expecting: %s and got: %s" % (test[0],test[1],test[3], - stack_dictlist([test[0],test[1]],incremental=test[2])) ) - - def testNormalizePath(self): - - from portage_util import normalize_path - path = "///foo/bar/baz" - good = "/foo/bar/baz" - self.failUnless(normalize_path(path) == good, msg="NormalizePath(%s) failed to produce %s" % (path, good)) - -- cgit v1.2.3-1-g7c22