~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/selftest/TestUtil.py

  • Committer: Aaron Bentley
  • Date: 2005-09-13 02:42:07 UTC
  • mto: (1185.1.16)
  • mto: This revision was merged to the branch mainline in revision 1390.
  • Revision ID: aaron.bentley@utoronto.ca-20050913024207-489d573af4b76c4d
Fixed issues with pull not having a default location after branch

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
20
20
import logging
21
21
import unittest
22
22
 
23
 
# Mark this python module as being part of the implementation
24
 
# of unittest: this gives us better tracebacks where the last
25
 
# shown frame is the test code, not our assertXYZ.
26
 
__unittest = 1
27
 
 
28
23
 
29
24
class LogCollector(logging.Handler):
30
25
    def __init__(self):
74
69
 
75
70
 
76
71
class TestLoader(unittest.TestLoader):
77
 
    """Custom  TestLoader to address some quirks in the stock python one."""
 
72
    """Custome TestLoader to set the right TestSuite class."""
78
73
    suiteClass = TestSuite
79
74
 
80
 
    def loadTestsFromModuleNames(self, names):
81
 
        """use a custom means to load tests from modules.
82
 
 
83
 
        There is an undesirable glitch in the python TestLoader where a 
84
 
        import error is ignore. We think this can be solved by ensuring the 
85
 
        requested name is resolvable, if its not raising the original error.
86
 
        """
87
 
        result = self.suiteClass()
88
 
        for name in names:
89
 
            _load_module_by_name(name)
90
 
            result.addTests(self.loadTestsFromName(name))
91
 
        return result
92
 
 
93
 
 
94
 
def _load_module_by_name(mod_name):
95
 
    parts = mod_name.split('.')
96
 
    module = __import__(mod_name)
97
 
    del parts[0]
98
 
    # for historical reasons python returns the top-level module even though
99
 
    # it loads the submodule; we need to walk down to get the one we want.
100
 
    while parts:
101
 
        module = getattr(module, parts.pop(0))
102
 
    return module
103
 
 
104
 
 
105
75
class TestVisitor(object):
106
76
    """A visitor for Tests"""
107
77
    def visitSuite(self, aTestSuite):