3
# Copyright 2008 Google Inc.
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
9
# http://www.apache.org/licenses/LICENSE-2.0
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.
17
"""A very basic test class derived from mox.MoxTestBase, used by mox_test.py.
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.
25
See mox_test.MoxTestBaseTest for how this class is actually used.
32
class ExampleMoxTestMixin(object):
33
"""Mix-in class for mox test case class.
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.
41
self.mox.StubOutWithMock(os, 'stat')
42
os.stat(self.DIR_PATH)
44
os.stat(self.DIR_PATH)
47
class ExampleMoxTest(mox.MoxTestBase, ExampleMoxTestMixin):
49
DIR_PATH = '/path/to/some/directory'
51
def testSuccess(self):
52
self.mox.StubOutWithMock(os, 'listdir')
53
os.listdir(self.DIR_PATH)
55
os.listdir(self.DIR_PATH)
57
def testExpectedNotCalled(self):
58
self.mox.StubOutWithMock(os, 'listdir')
59
os.listdir(self.DIR_PATH)
62
def testUnexpectedCall(self):
63
self.mox.StubOutWithMock(os, 'listdir')
64
os.listdir(self.DIR_PATH)
66
os.listdir('/path/to/some/other/directory')
67
os.listdir(self.DIR_PATH)
69
def testFailure(self):
70
self.assertTrue(False)
72
def testStatOther(self):
73
self.mox.StubOutWithMock(os, 'stat')
74
os.stat(self.DIR_PATH)
76
os.stat(self.DIR_PATH)
78
def testHasStubs(self):
81
def MockListdir(directory):
82
listdir_list.append(directory)
84
self.stubs.Set(os, 'listdir', MockListdir)
85
os.listdir(self.DIR_PATH)
86
self.assertEqual([self.DIR_PATH], listdir_list)
89
class TestClassFromAnotherModule(object):