~smoser/ubuntu/wily/maas/lp1474417

« back to all changes in this revision

Viewing changes to src/maastesting/testcase.py

  • Committer: Package Import Robot
  • Author(s): Andres Rodriguez
  • Date: 2013-10-04 12:33:05 UTC
  • mto: (1.4.1)
  • mto: This revision was merged to the branch mainline in revision 40.
  • Revision ID: package-import@ubuntu.com-20131004123305-vzkyhovgnvn1arco
Tags: upstream-1.4+bzr1693+dfsg
ImportĀ upstreamĀ versionĀ 1.4+bzr1693+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
9
9
    unicode_literals,
10
10
    )
11
11
 
 
12
str = None
 
13
 
12
14
__metaclass__ = type
13
15
__all__ = [
14
16
    'MAASTestCase',
15
17
    ]
16
18
 
17
19
from contextlib import contextmanager
 
20
import doctest
18
21
import unittest
19
22
 
20
 
from fixtures import TempDir
21
23
from maastesting.factory import factory
 
24
from maastesting.fixtures import TempDirectory
22
25
from maastesting.scenarios import WithScenarios
23
26
import mock
24
27
from nose.proxy import ResultProxy
26
29
from provisioningserver.testing.worker_cache import WorkerCacheFixture
27
30
import testresources
28
31
import testtools
 
32
import testtools.matchers
29
33
 
30
34
 
31
35
@nottest
103
107
        This is a convenience wrapper around a fixture incantation.  That's
104
108
        the only reason why it's on the test case and not in a factory.
105
109
        """
106
 
        return self.useFixture(TempDir()).path
 
110
        return self.useFixture(TempDirectory()).path
107
111
 
108
112
    def make_file(self, name=None, contents=None):
109
113
        """Create, and write to, a file.
118
122
    # probably only added to support compatibility with python 2.6.
119
123
    assertItemsEqual = unittest.TestCase.assertItemsEqual
120
124
 
 
125
    doctest_flags = doctest.ELLIPSIS | doctest.NORMALIZE_WHITESPACE
 
126
 
 
127
    def assertDocTestMatches(self, expected, observed, flags=None):
 
128
        """See if `observed` matches `expected`, a doctest sample.
 
129
 
 
130
        By default uses the doctest flags `NORMALIZE_WHITESPACE` and
 
131
        `ELLIPSIS`.
 
132
        """
 
133
        self.assertThat(observed, testtools.matchers.DocTestMatches(
 
134
            expected, self.doctest_flags if flags is None else flags))
 
135
 
121
136
    def run(self, result=None):
122
137
        with active_test(result, self):
123
138
            super(MAASTestCase, self).run(result)