~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/selftest/TestUtil.py

  • Committer: Martin Pool
  • Date: 2005-09-30 05:56:05 UTC
  • mto: (1185.14.2)
  • mto: This revision was merged to the branch mainline in revision 1396.
  • Revision ID: mbp@sourcefrog.net-20050930055605-a2c534529b392a7d
- fix upgrade for transport changes

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2004, 2005, 2006 Canonical Ltd
 
1
# Copyright (c) 2004 Canonical Limited
2
2
#       Author: Robert Collins <robert.collins@canonical.com>
3
3
#
4
4
# This program is free software; you can redistribute it and/or modify
69
69
 
70
70
 
71
71
class TestLoader(unittest.TestLoader):
72
 
    """Custom  TestLoader to address some quirks in the stock python one."""
 
72
    """Custome TestLoader to set the right TestSuite class."""
73
73
    suiteClass = TestSuite
74
74
 
75
 
    def loadTestsFromModuleNames(self, names):
76
 
        """use a custom means to load tests from modules.
77
 
 
78
 
        There is an undesirable glitch in the python TestLoader where a 
79
 
        import error is ignore. We think this can be solved by ensuring the 
80
 
        requested name is resolvable, if its not raising the original error.
81
 
        """
82
 
        result = self.suiteClass()
83
 
        for name in names:
84
 
            _load_module_by_name(name)
85
 
            result.addTests(self.loadTestsFromName(name))
86
 
        return result
87
 
 
88
 
 
89
 
def _load_module_by_name(mod_name):
90
 
    parts = mod_name.split('.')
91
 
    module = __import__(mod_name)
92
 
    del parts[0]
93
 
    # for historical reasons python returns the top-level module even though
94
 
    # it loads the submodule; we need to walk down to get the one we want.
95
 
    while parts:
96
 
        module = getattr(module, parts.pop(0))
97
 
    return module
98
 
 
99
 
 
100
75
class TestVisitor(object):
101
76
    """A visitor for Tests"""
102
77
    def visitSuite(self, aTestSuite):