~ubuntu-branches/ubuntu/quantal/maas/quantal-security

« back to all changes in this revision

Viewing changes to src/maastesting/tests/test_testcase.py

  • Committer: Package Import Robot
  • Author(s): Andres Rodriguez
  • Date: 2012-08-02 09:01:43 UTC
  • mto: (1.2.1)
  • mto: This revision was merged to the branch mainline in revision 21.
  • Revision ID: package-import@ubuntu.com-20120802090143-dutqktdjpiz61b61
Tags: upstream-0.1+bzr971+dfsg
ImportĀ upstreamĀ versionĀ 0.1+bzr971+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
from shutil import rmtree
17
17
from tempfile import mkdtemp
18
18
 
 
19
from maastesting.factory import factory
19
20
from maastesting.testcase import TestCase
 
21
from mock import MagicMock
20
22
from testtools.matchers import (
21
23
    DirExists,
22
24
    FileExists,
48
50
        self.patch(self, 'make_dir', lambda: directory)
49
51
        dir_part, file_part = os.path.split(self.make_file())
50
52
        self.assertEqual(directory, dir_part)
 
53
 
 
54
    def test_patch_can_mock(self):
 
55
        # The patch method patches-in and returns a new MagicMock() instance
 
56
        # if no attribute value is given.
 
57
        attribute_name = factory.make_name("attribute")
 
58
        self.assertRaises(AttributeError, getattr, self, attribute_name)
 
59
        attribute = self.patch(self, attribute_name)
 
60
        self.assertIs(getattr(self, attribute_name), attribute)
 
61
        self.assertIsInstance(attribute, MagicMock)