1 # Unit tests for stubout. 2 # 3 # Licensed under the Apache License, Version 2.0 (the "License"); 4 # you may not use this file except in compliance with the License. 5 # You may obtain a copy of the License at 6 # 7 # http://www.apache.org/licenses/LICENSE-2.0 8 # 9 # Unless required by applicable law or agreed to in writing, software 10 # distributed under the License is distributed on an "AS IS" BASIS, 11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 # See the License for the specific language governing permissions and 13 # limitations under the License. 14 # 15 # This is a fork of the pymox library intended to work with Python 3. 16 # The file was modified by quermit (at] gmail.com and dawid.fatyga (at] gmail.com 17 18 import fixtures 19 import testtools 20 21 from mox3 import mox 22 from mox3 import stubout 23 from mox3.tests import stubout_helper 24 25 26 class StubOutForTestingTest(testtools.TestCase): 27 def setUp(self): 28 super(StubOutForTestingTest, self).setUp() 29 self.mox = mox.Mox() 30 self.useFixture(fixtures.MonkeyPatch( 31 'mox3.tests.stubout_helper.SampleFunction', 32 stubout_helper.SampleFunction)) 33 34 def testSmartSetOnModule(self): 35 mock_function = self.mox.CreateMockAnything() 36 mock_function() 37 38 stubber = stubout.StubOutForTesting() 39 stubber.SmartSet(stubout_helper, 'SampleFunction', mock_function) 40 41 self.mox.ReplayAll() 42 43 stubout_helper.SampleFunction() 44 45 self.mox.VerifyAll() 46 47 48 if __name__ == '__main__': 49 testtools.main() 50