OLD | NEW |
1 #!/usr/bin/python2.4 | 1 #!/usr/bin/python2.4 |
2 # | 2 # |
3 # Copyright 2008 Google Inc. | 3 # Copyright 2008 Google Inc. |
4 # | 4 # |
5 # Licensed under the Apache License, Version 2.0 (the "License"); | 5 # Licensed under the Apache License, Version 2.0 (the "License"); |
6 # you may not use this file except in compliance with 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 | 7 # You may obtain a copy of the License at |
8 # | 8 # |
9 # http://www.apache.org/licenses/LICENSE-2.0 | 9 # http://www.apache.org/licenses/LICENSE-2.0 |
10 # | 10 # |
(...skipping 13 matching lines...) Expand all Loading... |
24 the expected behavior of the mock object (what methods are to be | 24 the expected behavior of the mock object (what methods are to be |
25 called on it, with what parameters, what they should return, and in | 25 called on it, with what parameters, what they should return, and in |
26 what order). | 26 what order). |
27 | 27 |
28 Once you have set up the expected mock behavior, you put it in replay | 28 Once you have set up the expected mock behavior, you put it in replay |
29 mode. Now the mock responds to method calls just as you told it to. | 29 mode. Now the mock responds to method calls just as you told it to. |
30 If an unexpected method (or an expected method with unexpected | 30 If an unexpected method (or an expected method with unexpected |
31 parameters) is called, then an exception will be raised. | 31 parameters) is called, then an exception will be raised. |
32 | 32 |
33 Once you are done interacting with the mock, you need to verify that | 33 Once you are done interacting with the mock, you need to verify that |
34 all the expected interactions occured. (Maybe your code exited | 34 all the expected interactions occurred. (Maybe your code exited |
35 prematurely without calling some cleanup method!) The verify phase | 35 prematurely without calling some cleanup method!) The verify phase |
36 ensures that every expected method was called; otherwise, an exception | 36 ensures that every expected method was called; otherwise, an exception |
37 will be raised. | 37 will be raised. |
38 | 38 |
39 Suggested usage / workflow: | 39 Suggested usage / workflow: |
40 | 40 |
41 # Create Mox factory | 41 # Create Mox factory |
42 my_mox = Mox() | 42 my_mox = Mox() |
43 | 43 |
44 # Create a mock data access object | 44 # Create a mock data access object |
(...skipping 1347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1392 Sets up a "mox" attribute which is an instance of Mox - any mox tests will | 1392 Sets up a "mox" attribute which is an instance of Mox - any mox tests will |
1393 want this. Also automatically unsets any stubs and verifies that all mock | 1393 want this. Also automatically unsets any stubs and verifies that all mock |
1394 methods have been called at the end of each test, eliminating boilerplate | 1394 methods have been called at the end of each test, eliminating boilerplate |
1395 code. | 1395 code. |
1396 """ | 1396 """ |
1397 | 1397 |
1398 __metaclass__ = MoxMetaTestBase | 1398 __metaclass__ = MoxMetaTestBase |
1399 | 1399 |
1400 def setUp(self): | 1400 def setUp(self): |
1401 self.mox = Mox() | 1401 self.mox = Mox() |
OLD | NEW |