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