Helper classes for easier mocking and patching tests.
from mockie import TestCase
from mymodule import clean
class MyTest(TestCase):
def test_my_function_with_side_effects(self):
dir_path = "/path/to/dir/"
self.patch("package.db.database.os")
mock_shutil = self.patch("package.db.database.shutil")
clean()
self.assertCalledOnceWith(self.mock_shutil.rmtree, dir_path)
from mockie import TestCase
from mymodule import clean
class MyTest(TestCase):
def test_my_function_with_side_effects(self):
dir_path = "/path/to/dir/"
dbfile = "database.db"
with patch("package.db.database.os"):
with patch("package.db.database.shutil") as mock_shutil:
clean()
mock_shutil.rmtree.assert_called_once_with(dir_path)
self.Mock
self.MagicMock
self.patch
self.patch_object
self.patch_multiple
self.patch_dict
self.mock_open
self.assertCalled
self.assertCalledOnceWith
self.assertAnyCall
self.assertIsMocked
self.assertIsMock
self.assertIsMagicMock
The MIT License (MIT)
Copyright (c) 2015 marcwebbie.
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.