| OLD | NEW |
| (Empty) |
| 1 #!/usr/bin/python2.4 | |
| 2 # | |
| 3 # Copyright 2008 Google Inc. | |
| 4 # | |
| 5 # Licensed under the Apache License, Version 2.0 (the "License"); | |
| 6 # you may not use this file except in compliance with the License. | |
| 7 # You may obtain a copy of the License at | |
| 8 # | |
| 9 # http://www.apache.org/licenses/LICENSE-2.0 | |
| 10 # | |
| 11 # Unless required by applicable law or agreed to in writing, software | |
| 12 # distributed under the License is distributed on an "AS IS" BASIS, | |
| 13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 14 # See the License for the specific language governing permissions and | |
| 15 # limitations under the License. | |
| 16 | |
| 17 """A very basic test class derived from mox.MoxTestBase, used by mox_test.py. | |
| 18 | |
| 19 The class defined in this module is used to test the features of | |
| 20 MoxTestBase and is not intended to be a standalone test. It needs to | |
| 21 be in a separate module, because otherwise the tests in this class | |
| 22 (which should not all pass) would be executed as part of the | |
| 23 mox_test.py test suite. | |
| 24 | |
| 25 See mox_test.MoxTestBaseTest for how this class is actually used. | |
| 26 """ | |
| 27 | |
| 28 import os | |
| 29 | |
| 30 import mox | |
| 31 | |
| 32 class ExampleMoxTestMixin(object): | |
| 33 """Mix-in class for mox test case class. | |
| 34 | |
| 35 It stubs out the same function as one of the test methods in | |
| 36 the example test case. Both tests must pass as meta class wraps | |
| 37 test methods in all base classes. | |
| 38 """ | |
| 39 | |
| 40 def testStat(self): | |
| 41 self.mox.StubOutWithMock(os, 'stat') | |
| 42 os.stat(self.DIR_PATH) | |
| 43 self.mox.ReplayAll() | |
| 44 os.stat(self.DIR_PATH) | |
| 45 | |
| 46 | |
| 47 class ExampleMoxTest(mox.MoxTestBase, ExampleMoxTestMixin): | |
| 48 | |
| 49 DIR_PATH = '/path/to/some/directory' | |
| 50 | |
| 51 def testSuccess(self): | |
| 52 self.mox.StubOutWithMock(os, 'listdir') | |
| 53 os.listdir(self.DIR_PATH) | |
| 54 self.mox.ReplayAll() | |
| 55 os.listdir(self.DIR_PATH) | |
| 56 | |
| 57 def testExpectedNotCalled(self): | |
| 58 self.mox.StubOutWithMock(os, 'listdir') | |
| 59 os.listdir(self.DIR_PATH) | |
| 60 self.mox.ReplayAll() | |
| 61 | |
| 62 def testUnexpectedCall(self): | |
| 63 self.mox.StubOutWithMock(os, 'listdir') | |
| 64 os.listdir(self.DIR_PATH) | |
| 65 self.mox.ReplayAll() | |
| 66 os.listdir('/path/to/some/other/directory') | |
| 67 os.listdir(self.DIR_PATH) | |
| 68 | |
| 69 def testFailure(self): | |
| 70 self.assertTrue(False) | |
| 71 | |
| 72 def testStatOther(self): | |
| 73 self.mox.StubOutWithMock(os, 'stat') | |
| 74 os.stat(self.DIR_PATH) | |
| 75 self.mox.ReplayAll() | |
| 76 os.stat(self.DIR_PATH) | |
| OLD | NEW |