--- /dev/null
+UnitTests
+---------
+
+Portage has some tests that use the unittest framework that ships with python (2.3-2.4ish)
+Tests have a specific naming convention.
+
+in tests/ there is a runTest script that invokes tests/__init__.py
+
+This init looks at a hardcoded list of test dirs to search for tests.
+If you add a new dir and don't see your new tests, make sure that the dir is in this list.
+
+On the subject of adding more directories; the layout is basically 1 directory per portage
+file at this point (we have few files, and even fewer large files). Inside of the dir
+you should have files of the form test_${function}.py.
+
+So if I was to write a vercmp test, and vercmp is in portage_versions.
+
+tests/portage_versions/test_vercmp.py
+
+would be the filename.
+
+The __init__.py file in tests only goes 1 deep (it's non-recursive, in other words). If
+you end up with more directories it will probably break at present. Need to replace the
+'/' in the directory path with a '.' (for proper importing). This should be trivial to fix.
# Distributed under the terms of the GNU General Public License v2
# $Id$
-import unittest
+import os, unittest
def main():
- tests = ["test_vercmp", "test_util"]
+ testDirs = ["portage", "portage_util"]
suite = unittest.TestSuite()
- for mod in tests:
- try:
- test_mod = __import__(mod)
- suite.addTest(test_mod.suite())
- except ImportError:
- pass
+ basedir = os.path.dirname(__file__)
+ for mydir in testDirs:
+ suite.addTests(getTests(os.path.join(basedir, mydir)))
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 ):
+ """
+
+ 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_module = ".".join(("tests", os.path.basename(path)))
+ 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
--- /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: __init__.py 5522 2007-01-10 12:30:05Z antarus $
--- /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: test_atoms.py 5525 2007-01-10 13:35:03Z antarus $
+
+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.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
# $Id$
from unittest import TestCase
-from unittest import TestLoader
from portage_versions import vercmp
class VerCmpTestCase(TestCase):
""" A simple testCase for portage_versions.vercmp()
"""
-
def testVerCmpGreater(self):
("0", "0.0")]
for test in tests:
self.failIf( vercmp( test[0], test[1]) == 0, msg="%s == %s? Wrong!" % (test[0],test[1]))
-
-def suite():
- return TestLoader().loadTestsFromTestCase(VerCmpTestCase)
-
--- /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: __init__.py 5522 2007-01-10 12:30:05Z antarus $
+
--- /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: test_vercmp.py 5213 2006-12-08 00:12:41Z antarus $
+
+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.failUnless(normalize_path(path) == good, msg="NormalizePath(%s) failed to produce %s" % (path, good))
+
-# test_vercmp.py -- Portage Unit Testing Functionality
+# test_stackDictList.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
+from unittest import TestCase
+
+class StackDictListTestCase(TestCase):
-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
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))
-
-def suite():
- return TestLoader().loadTestsFromTestCase(UtilTestCase)
-
--- /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: test_vercmp.py 5213 2006-12-08 00:12:41Z antarus $
+
+from unittest import TestCase
+
+class StackDictsTestCase(TestCase):
+
+ def testStackDicts(self):
+ pass
--- /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: test_vercmp.py 5213 2006-12-08 00:12:41Z antarus $
+
+from unittest import TestCase
+
+class StackListsTestCase(TestCase):
+
+ def testStackLists(self):
+ pass
--- /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: test_vercmp.py 5213 2006-12-08 00:12:41Z antarus $
+
+from unittest import TestCase
+
+class UniqueArrayTestCase(TestCase):
+
+ def testUniqueArray(self):
+ pass
--- /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: test_vercmp.py 5213 2006-12-08 00:12:41Z antarus $
+
+from unittest import TestCase, TestLoader
+
+class VarExpandTestCase(TestCase):
+
+ def testVarexpand(self):
+ pass
# $Id$
-import sys
+import os, sys
import os.path as osp
-# Grab SVN portage files instead of normal ones.
-sys.path.insert(0,'../pym')
-
# 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.abspath(__file__))))
+# Grab SVN portage files instead of normal ones.
+sys.path.insert(0, os.path.join(sys.path[0], "pym"))
+
import tests
if __name__ == "__main__":
result = tests.main()