Here are the examples of the python api mock.patch.multiple taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
185 Examples
3
Example 1
@mock.patch.multiple('scalarizr.linux.coreutils',
losetup_all=mock.DEFAULT)
@mock.patch('scalarizr.linux.coreutils.losetup')
@mock.patch.object(os.path, 'exists')
@mock.patch.object(os, 'stat')
def test_ensure_existed(self, stat, exists, losetup, losetup_all):
stat.return_value = mock.Mock(st_size=1073741931)
exists.return_value=True
losetup_all.return_value.__getitem__.return_value = '/mnt/loopdev0'
vol = storage2.volume(
type='loop',
device='/dev/loop0',
file='/mnt/loopdev0'
)
vol.ensure()
losetup_all.assert_called_once_with()
3
Example 2
Project: littlechef-rackspace Source File: test_runner.py
def test_create_with_postplugins_parses_postplugins_into_array(self):
with mock.patch.multiple(
"littlechef_rackspace.runner",
RackspaceApi=self.api_class,
ChefDeployer=self.deploy_class,
RackspaceCreate=self.create_class):
r = Runner(options={})
post_plugins = 'plugin1,plugin2,plugin3'
r.main(self.create_args + ['--post-plugins', post_plugins])
call_args = self.create_command.execute.call_args_list[0][1]
self.assertEquals(
post_plugins.split(','),
call_args["post_plugins"]
)
3
Example 3
Project: pyolite Source File: test_pyolite.py
def test_if_pyolite_object_has_all_attributes(self):
mocked_repository = MagicMock()
mocked_user = MagicMock()
with patch.multiple('pyolite.pyolite',
RepositoryManager=mocked_repository,
UserManager=mocked_user):
pyolite = Pyolite('my_repo')
eq_(pyolite.admin_repository, 'my_repo')
mocked_repository.assert_called_once_with('my_repo')
mocked_user.assert_called_once_with('my_repo')
3
Example 4
Project: requests-kerberos Source File: test_requests_kerberos.py
def test_principal_override(self):
with patch.multiple(kerberos_module_name,
authGSSClientInit=clientInit_complete,
authGSSClientResponse=clientResponse,
authGSSClientStep=clientStep_continue):
response = requests.Response()
response.url = "http://www.example.org/"
response.headers = {'www-authenticate': 'negotiate token'}
host = urlparse(response.url).hostname
auth = requests_kerberos.HTTPKerberosAuth(principal="user@REALM")
auth.generate_request_header(response, host)
clientInit_complete.assert_called_with(
"[email protected]",
gssflags=(
kerberos.GSS_C_MUTUAL_FLAG |
kerberos.GSS_C_SEQUENCE_FLAG),
principal="user@REALM")
3
Example 5
Project: silver Source File: test_subscription.py
def test_sub_canceled_now_w_consolidated_billing(self):
plan = PlanFactory.create(generate_after=120)
subscription = SubscriptionFactory.create(
plan=plan,
state=Subscription.STATES.CANCELED,
start_date=datetime.date(2015, 8, 10),
cancel_date=datetime.date(2015, 8, 22)
)
correct_billing_date = datetime.date(2015, 9, 1)
incorrect_billing_date = datetime.date(2015, 8, 23)
true_property = PropertyMock(return_value=True)
with patch.multiple(
Subscription,
_has_existing_customer_with_consolidated_billing=true_property
):
assert subscription.should_be_billed(correct_billing_date) is True
assert subscription.should_be_billed(incorrect_billing_date) is False
3
Example 6
def test_get_user(self):
mocked_user = MagicMock()
mocked_user.get_by_name.return_value = 'test_user'
UserManager.__bases__ = (MockManager,)
with patch.multiple('pyolite.managers.user', User=mocked_user):
users = UserManager('~/path/to/admin/gitolite/repo')
eq_('test_user', users.get('test_user'))
mocked_user.get_by_name.assert_called_once_with('test_user',
mocked_path,
mocked_git)
3
Example 7
Project: littlechef-rackspace Source File: test_runner.py
def test_create_instantiates_api_and_deploy_with_default_private_key(self):
with mock.patch.multiple(
"littlechef_rackspace.runner",
RackspaceApi=self.api_class,
ChefDeployer=self.deploy_class,
RackspaceCreate=self.create_class):
r = Runner(options={})
r.main(self.create_args)
self.api_class.assert_any_call(
username="username",
key="deadbeef",
region='dfw')
self.deploy_class.assert_any_call(key_filename="~/.ssh/id_rsa")
3
Example 8
def test_readdir(self):
mocked_os = MagicMock()
mocked_os.path.join = os.path.join
mocked_os.path.is_dir.return_value = True
mocked_os.listdir.return_value = ['one_dir', 'one_file', '.git']
with patch.multiple('gitfs.views.passthrough', os=mocked_os):
view = PassthroughView(repo=self.repo, repo_path=self.repo_path)
result = view.readdir("/magic/path", 0)
dirents = [directory for directory in result]
assert dirents == ['.', '..', 'one_dir', 'one_file']
path = '/the/root/path/magic/path'
mocked_os.path.isdir.assert_called_once_with(path)
mocked_os.listdir.assert_called_once_with(path)
3
Example 9
Project: littlechef-rackspace Source File: test_runner.py
def test_create_with_use_opscode_chef_to_false(self):
with mock.patch.multiple(
"littlechef_rackspace.runner",
RackspaceApi=self.api_class,
ChefDeployer=self.deploy_class,
RackspaceCreate=self.create_class):
r = Runner(options={})
r.main(self.create_args + ['--use-opscode-chef', '0'])
call_args = self.create_command.execute.call_args_list[0][1]
self.assertEquals(False, call_args["use_opscode_chef"])
3
Example 10
Project: pyolite Source File: test_manager.py
@raises(NotImplementedError)
def test_get_abstract_method_method(self):
mocked_path = MagicMock()
mocked_git = MagicMock()
with patch.multiple('pyolite.managers.manager',
Path=MagicMock(return_value=mocked_path),
Git=MagicMock(return_value=mocked_git)):
with patch.multiple('pyolite.managers.manager.Manager',
__abstractmethods__=set()):
manager = Manager('/path/to/admin/repo')
manager.get('entity')
3
Example 11
Project: requests-kerberos Source File: test_requests_kerberos.py
def test_authenticate_server(self):
with patch.multiple(kerberos_module_name, authGSSClientStep=clientStep_complete):
response_ok = requests.Response()
response_ok.url = "http://www.example.org/"
response_ok.status_code = 200
response_ok.headers = {
'www-authenticate': 'negotiate servertoken',
'authorization': 'Negotiate GSSRESPONSE'}
auth = requests_kerberos.HTTPKerberosAuth()
auth.context = {"www.example.org": "CTX"}
result = auth.authenticate_server(response_ok)
self.assertTrue(result)
clientStep_complete.assert_called_with("CTX", "servertoken")
3
Example 12
Project: silver Source File: test_subscription.py
def test_new_active_sub_no_trial_wa_consolidated_billing(self):
plan = PlanFactory.create(generate_after=120)
subscription = SubscriptionFactory.create(
plan=plan,
state=Subscription.STATES.ACTIVE,
start_date=datetime.date(2015, 8, 12)
)
correct_billing_date_1 = datetime.date(2015, 8, 12)
correct_billing_date_2 = datetime.date(2015, 8, 20)
true_property = PropertyMock(return_value=True)
false_property = PropertyMock(return_value=False)
with patch.multiple(
Subscription,
is_billed_first_time=true_property,
_has_existing_customer_with_consolidated_billing=false_property,
):
assert subscription.should_be_billed(correct_billing_date_1) is True
assert subscription.should_be_billed(correct_billing_date_2) is True
3
Example 13
Project: pyolite Source File: test_user.py
@raises(ValueError)
def test_create_user_with_no_key(self):
with patch.multiple('pyolite.managers.manager',
Git=MagicMock(),
Path=MagicMock()):
users = UserManager('~/path/to/admin/gitolite/repo')
users.create('test_username')
3
Example 14
@mock.patch.multiple('scalarizr.linux.mount',
mounts=mock.DEFAULT, mount=mock.DEFAULT)
def test_mount_already_mounted(self, mounts, mount):
mounts.return_value.__getitem__.return_value = mock.Mock(mpoint='/mnt')
vol = base.Volume(device='/dev/sdb', mpoint='/mnt')
vol.mount()
mounts.return_value.__getitem__.assert_called_once_with('/dev/sdb')
assert mount.call_count == 0, "Mount wasn't called"
3
Example 15
def test_in_cache(self):
mocked_inspect = MagicMock()
mocked_inspect.getargspec.return_value = [["file"]]
mocked_gitignore = MagicMock()
mocked_gitignore.get.return_value = True
mocked_look_at = MagicMock()
mocked_look_at.cache = mocked_gitignore
with patch.multiple("gitfs.utils.decorators.not_in",
inspect=mocked_inspect):
with pytest.raises(FuseOSError):
not_in(mocked_look_at, check=["file"]).check_args(None, "file")
3
Example 16
Project: docker-rpmbuild Source File: packagercontext_test.py
@patch.multiple('shutil', copy=DEFAULT, copytree=DEFAULT)
@patch('tempfile.mkdtemp', return_value='/context')
def test_packager_context_setup_spec_sources_dir(self, mkdtemp, copy, copytree):
with patch('rpmbuild.open', self.open, create=True):
context = PackagerContext('foo', spec='foo.spec', sources_dir='/tmp')
context.setup()
copy.assert_called_with('foo.spec', '/context')
copytree.assert_called_with('/tmp', '/context/SOURCES')
3
Example 17
Project: pyolite Source File: test_user.py
def test_if_user_is_admin(self):
mocks = self.set_mocks()
with patch.multiple('pyolite.models.user', Path=mocks['path'],
ListKeys=mocks['keys']):
user = User(mocks['initial_path'], mocks['git'], 'vtemian', [],
[mocks['first_key']])
eq_(user.is_admin, False)
user.repos = ['/path/to/gitolite/admin/gitolite.conf']
eq_(user.is_admin, True)
3
Example 18
Project: littlechef-rackspace Source File: test_runner.py
def test_create_with_runlist_parses_runlist_into_array(self):
with mock.patch.multiple(
"littlechef_rackspace.runner",
RackspaceApi=self.api_class,
ChefDeployer=self.deploy_class,
RackspaceCreate=self.create_class):
r = Runner(options={})
runlist = 'role[test],recipe[web],recipe[apache2]'
r.main(self.create_args + ['--runlist', runlist])
call_args = self.create_command.execute.call_args_list[0][1]
self.assertEquals(runlist.split(','), call_args["runlist"])
3
Example 19
Project: gitfs Source File: test_mount.py
def test_get_https_credentials(self):
mocked_user_pass = MagicMock()
mocked_credentials = MagicMock(return_value="credentials_obj")
mocked_args = MagicMock(password="password", username="username")
with patch.multiple('gitfs.mounter', UserPass=mocked_user_pass,
RemoteCallbacks=mocked_credentials):
assert get_credentials(mocked_args) == "credentials_obj"
mocked_user_pass.assert_called_once_with("username", "password")
3
Example 20
Project: littlechef-rackspace Source File: test_runner.py
def test_create_without_skip_opscode_chef(self):
with mock.patch.multiple(
"littlechef_rackspace.runner",
RackspaceApi=self.api_class,
ChefDeployer=self.deploy_class,
RackspaceCreate=self.create_class):
r = Runner(options={})
r.main(self.create_args)
call_args = self.create_command.execute.call_args_list[0][1]
self.assertEquals(None, call_args.get("use_opscode_chef"))
3
Example 21
Project: pyolite Source File: test_repo.py
def test_it_should_retrieve_all_users_from_repo(self):
path = 'tests/fixtures/repo_users.conf'
mocked_path = MagicMock()
mocked_path.__str__ = lambda x: path
mocked_path.exists.return_value = True
mocked_re = MagicMock()
mocked_user1 = MagicMock()
mocked_user2 = MagicMock()
mocked_re.compile('=( *)(\w+)').finditer.return_value = [mocked_user1,
mocked_user2]
mocked_user1.group.return_value = 'user1'
mocked_user2.group.return_value = 'user2'
with patch.multiple('pyolite.repo', re=mocked_re):
repo = Repo(mocked_path)
eq_(repo.users, ['user1', 'user2'])
3
Example 22
Project: silver Source File: test_subscription.py
def test_sub_canceled_at_end_of_bc_w_consolidated_billing(self):
plan = PlanFactory.create(generate_after=120)
subscription = SubscriptionFactory.create(
plan=plan,
state=Subscription.STATES.CANCELED,
start_date=datetime.date(2015, 8, 22),
cancel_date=datetime.date(2015, 9, 1)
)
correct_billing_date = datetime.date(2015, 9, 2)
incorrect_billing_date = datetime.date(2015, 8, 22)
true_property = PropertyMock(return_value=True)
with patch.multiple(
Subscription,
_has_existing_customer_with_consolidated_billing=true_property
):
assert subscription.should_be_billed(correct_billing_date) is True
assert subscription.should_be_billed(incorrect_billing_date) is False
3
Example 23
Project: gitfs Source File: test_mount.py
def test_get_ssh_credentials(self):
mocked_keypair = MagicMock()
mocked_credentials = MagicMock(return_value="credentials_obj")
mocked_args = MagicMock(ssh_user="user", ssh_key="key", password=None)
with patch.multiple('gitfs.mounter', Keypair=mocked_keypair,
RemoteCallbacks=mocked_credentials):
assert get_credentials(mocked_args) == "credentials_obj"
asserted_call = ("user", "key.pub", "key", "")
mocked_keypair.assert_called_once_with(*asserted_call)
3
Example 24
Project: silver Source File: test_subscription.py
def test_canceled_sub_wa_consolidated_billing(self):
plan = PlanFactory.create(generate_after=120)
subscription = SubscriptionFactory.create(
plan=plan,
state=Subscription.STATES.CANCELED,
start_date=datetime.date(2015, 8, 10),
cancel_date=datetime.date(2015, 8, 22)
)
correct_billing_date = datetime.date(2015, 8, 23)
false_property = PropertyMock(return_value=False)
with patch.multiple(
Subscription,
_has_existing_customer_with_consolidated_billing=false_property
):
assert subscription.should_be_billed(correct_billing_date) is True
3
Example 25
Project: pyolite Source File: test_manager.py
@raises(NotImplementedError)
def test_create_abstract_method_method(self):
mocked_path = MagicMock()
mocked_git = MagicMock()
with patch.multiple('pyolite.managers.manager',
Path=MagicMock(return_value=mocked_path),
Git=MagicMock(return_value=mocked_git)):
with patch.multiple('pyolite.managers.manager.Manager',
__abstractmethods__=set()):
manager = Manager('/path/to/admin/repo')
manager.create('entity')
3
Example 26
Project: requests-kerberos Source File: test_requests_kerberos.py
def test_no_force_preemptive(self):
with patch.multiple(kerberos_module_name,
authGSSClientInit=clientInit_complete,
authGSSClientResponse=clientResponse,
authGSSClientStep=clientStep_continue):
auth = requests_kerberos.HTTPKerberosAuth()
request = requests.Request(url="http://www.example.org")
auth.__call__(request)
self.assertTrue('Authorization' not in request.headers)
3
Example 27
Project: provy Source File: helpers.py
@contextmanager
def mock_role_methods(self, *methods):
'''
Same as mock_role_method, except that several methods can be provided.
'''
methods_to_mock = dict((method, DEFAULT) for method in methods)
with patch.multiple(self.role.__class__, **methods_to_mock) as mocks:
yield tuple(mocks[method] for method in methods)
3
Example 28
Project: pyolite Source File: test_repository.py
@raises(ValueError)
def test_create_new_repository_that_already_exists(self):
mocked_repository = MagicMock()
mocked_file = MagicMock()
mocked_path.return_value = mocked_file
mocked_file.exists.return_value = True
RepositoryManager.__bases__ = (MockManager,)
with patch.multiple('pyolite.managers.repository',
Path=mocked_path,
Repository=mocked_repository):
repos = RepositoryManager('/path/to/admin/repo/')
repos.create('already_exists')
3
Example 29
Project: requests-kerberos Source File: test_requests_kerberos.py
def test_generate_request_header_custom_service(self):
with patch.multiple(kerberos_module_name,
authGSSClientInit=clientInit_complete,
authGSSClientResponse=clientResponse,
authGSSClientStep=clientStep_continue):
response = requests.Response()
response.url = "http://www.example.org/"
response.headers = {'www-authenticate': 'negotiate token'}
host = urlparse(response.url).hostname
auth = requests_kerberos.HTTPKerberosAuth(service="barfoo")
auth.generate_request_header(response, host),
clientInit_complete.assert_called_with(
"[email protected]",
gssflags=(
kerberos.GSS_C_MUTUAL_FLAG |
kerberos.GSS_C_SEQUENCE_FLAG),
principal=None)
3
Example 30
def test_decorator(self):
mocked_function = MagicMock()
mocked_function.__name__ = "function"
mocked_object = MagicMock()
mocked_object.ignore = CachedIgnore()
mocked_inspect = MagicMock()
mocked_inspect.getargspec.return_value = [["file"]]
with patch.multiple("gitfs.utils.decorators.not_in",
inspect=mocked_inspect):
not_in("ignore", check=["file"])(mocked_function)(mocked_object,
"file")
mocked_function.assert_called_once_with(mocked_object, "file")
3
Example 31
Project: requests-kerberos Source File: test_requests_kerberos.py
def test_realm_override(self):
with patch.multiple(kerberos_module_name,
authGSSClientInit=clientInit_complete,
authGSSClientResponse=clientResponse,
authGSSClientStep=clientStep_continue):
response = requests.Response()
response.url = "http://www.example.org/"
response.headers = {'www-authenticate': 'negotiate token'}
host = urlparse(response.url).hostname
auth = requests_kerberos.HTTPKerberosAuth(hostname_override="otherhost.otherdomain.org")
auth.generate_request_header(response, host)
clientInit_complete.assert_called_with(
"[email protected]",
gssflags=(
kerberos.GSS_C_MUTUAL_FLAG |
kerberos.GSS_C_SEQUENCE_FLAG),
principal=None)
3
Example 32
Project: pyolite Source File: test_user.py
def test_create_user_succesfully(self):
mocked_user_obj = MagicMock()
mocked_user = MagicMock(return_value=mocked_user_obj)
UserManager.__bases__ = (MockManager,)
with patch.multiple('pyolite.managers.user', User=mocked_user,
Manager=MagicMock()):
users = UserManager('~/path/to/admin/gitolite/repo')
eq_(mocked_user_obj, users.create('test_username', 'key_path'))
mocked_user.assert_called_once_with(mocked_path, mocked_git,
'test_username')
mocked_user_obj.keys.append.assert_called_once_with('key_path')
3
Example 33
@mock.patch.multiple('scalarizr.linux.coreutils',
dd=mock.DEFAULT,
losetup=mock.DEFAULT,
losetup_all=mock.DEFAULT)
def test_ensure_new(self, dd, losetup, losetup_all):
losetup_all.return_value.__getitem__.return_value = '/dev/loop0'
vol = storage2.volume(type='loop', size=1, zerofill=True)
vol.ensure()
assert vol.device == '/dev/loop0'
assert vol.file.startswith('/mnt/loopdev')
dd.assert_called_once_with(**{
'if': '/dev/zero',
'of': vol.file,
'bs': '1M',
'count': 1024})
losetup.assert_called_with(vol.file, find=True)
3
Example 34
def test_args(self):
mocked_parser = MagicMock()
mocked_args = MagicMock()
mocked_args.return_value = "args"
with patch.multiple('gitfs.mounter', Args=mocked_args):
assert parse_args(mocked_parser) == "args"
asserted_calls = [call('remote_url', help='repo to be cloned'),
call('mount_point',
help='where the repo should be mount'),
call('-o', help='other options: repo_path, ' +
'user, group, branch, max_size, ' +
'max_offset, fetch_timeout, merge_timeout')]
mocked_parser.add_argument.has_calls(asserted_calls)
3
Example 35
Project: python-scrapinghub Source File: test_retry.py
@patch.multiple('scrapinghub.HubstorageClient',
RETRY_DEFAULT_JITTER_MS=1,
RETRY_DEFAULT_EXPONENTIAL_BACKOFF_MS=1)
def hsclient_with_retries(max_retries=3, max_retry_time=1):
return HubstorageClient(
auth=TEST_AUTH, endpoint=TEST_ENDPOINT,
max_retries=max_retries, max_retry_time=max_retry_time,
)
3
Example 36
Project: pyolite Source File: test_repository.py
def test_if_we_find_only_directories_should_return_none(self):
mocked_users = MagicMock()
mocked_dir = MagicMock()
mocked_path = MagicMock()
mocked_dir.isdir.return_value = True
mocked_path.walk.return_value = [mocked_dir]
with patch.multiple('pyolite.models.repository',
Path=MagicMock(return_value=mocked_path),
ListUsers=MagicMock(return_value=mocked_users)):
repo = Repository.get_by_name('new_one', 'simple_path', 'git')
eq_(repo, None)
3
Example 37
Project: docker-rpmbuild Source File: packagercontext_test.py
@patch.multiple('shutil', copy=DEFAULT, rmtree=DEFAULT)
@patch('tempfile.mkdtemp', return_value='/context')
def test_packager_context_teardown(self, mkdtemp, copy, rmtree):
with patch('rpmbuild.open', self.open, create=True):
context = PackagerContext('foo', spec='foo.spec')
context.setup()
context.teardown()
rmtree.assert_called_with('/context')
3
Example 38
def test_has_key(self):
mocked_inspect = MagicMock()
mocked_inspect.getargspec.return_value = [["file"]]
mocked_gitignore = MagicMock()
mocked_gitignore.get.return_value = False
mocked_look_at = MagicMock()
mocked_look_at.cache = mocked_gitignore
mocked_look_at.check_key.return_value = True
with patch.multiple("gitfs.utils.decorators.not_in",
inspect=mocked_inspect):
with pytest.raises(FuseOSError):
not_in(mocked_look_at, check=["file"]).check_args(None, "file")
3
Example 39
Project: littlechef-rackspace Source File: test_runner.py
def test_create_creates_node_with_specified_public_key(self):
with mock.patch.multiple(
"littlechef_rackspace.runner",
RackspaceApi=self.api_class,
ChefDeployer=self.deploy_class,
RackspaceCreate=self.create_class):
r = Runner(options={})
r.main(self.create_args)
self.create_class.assert_any_call(rackspace_api=self.rackspace_api,
chef_deployer=self.chef_deployer)
call_args = self.create_command.execute.call_args_list[0][1]
self.assertEquals("123", call_args["image"])
self.assertEquals("2", call_args["flavor"])
self.assertEquals("test-node", call_args["name"])
self.assertEquals('README.md', call_args['public_key_file'].name)
3
Example 40
Project: pyolite Source File: test_user.py
@raises(ValueError)
def test_get_user_by_nothing_it_should_raise_value_error(self):
mocks = self.set_mocks()
with patch.multiple('pyolite.models.user', Path=mocks['path'],
ListKeys=mocks['keys']):
User.get(MagicMock(), mocks['git'], mocks['path'])
3
Example 41
Project: littlechef-rackspace Source File: test_runner.py
def test_create_with_plugins_parses_plugins_into_array(self):
with mock.patch.multiple(
"littlechef_rackspace.runner",
RackspaceApi=self.api_class,
ChefDeployer=self.deploy_class,
RackspaceCreate=self.create_class):
r = Runner(options={})
plugins = 'plugin1,plugin2,plugin3'
r.main(self.create_args + ['--plugins', plugins])
call_args = self.create_command.execute.call_args_list[0][1]
self.assertEquals(plugins.split(','), call_args["plugins"])
3
Example 42
Project: pika Source File: async_test_base.py
@unittest.skipIf(not hasattr(select, 'epoll'), "epoll not supported")
def select_epoll_test(self):
"""SelectConnection:epoll"""
with mock.patch.multiple(select_connection, SELECT_TYPE='epoll'):
self.start(adapters.SelectConnection)
3
Example 43
Project: littlechef-rackspace Source File: test_runner.py
def test_create_with_skip_opscode_chef_to_false(self):
with mock.patch.multiple(
"littlechef_rackspace.runner",
RackspaceApi=self.api_class,
ChefDeployer=self.deploy_class,
RackspaceCreate=self.create_class):
r = Runner(options={})
r.main(self.create_args + ['--skip-opscode-chef'])
call_args = self.create_command.execute.call_args_list[0][1]
self.assertEquals(False, call_args["use_opscode_chef"])
3
Example 44
Project: pyolite Source File: test_repo.py
def test_it_should_replace_a_given_string_in_repo_conf(self):
mocked_re = MagicMock()
path = 'tests/fixtures/config.conf'
mocked_re.sub.return_value = 'another_text'
with patch.multiple('pyolite.repo', re=mocked_re):
repo = Repo(path)
repo.replace('pattern', 'string')
with open('tests/fixtures/config.conf') as f:
eq_(f.read(), 'another_text')
mocked_re.sub.assert_called_once_with('pattern', 'string',
'another_text')
3
Example 45
def test_work(self):
mocked_peasant = MagicMock()
mocked_fetch = MagicMock(side_effect=ValueError)
mocked_fetch_event = MagicMock()
with patch.multiple('gitfs.worker.fetch', Peasant=mocked_peasant,
fetch=mocked_fetch_event):
worker = FetchWorker()
worker.fetch = mocked_fetch
worker.timeout = 5
with pytest.raises(ValueError):
worker.work()
assert mocked_fetch.call_count == 1
mocked_fetch_event.wait.assert_called_once_with(5)
3
Example 46
Project: pika Source File: async_test_base.py
@unittest.skipIf(
not hasattr(select, 'poll') or
not hasattr(select.poll(), 'modify'), "poll not supported") # pylint: disable=E1101
def select_poll_test(self):
"""SelectConnection:poll"""
with mock.patch.multiple(select_connection, SELECT_TYPE='poll'):
self.start(adapters.SelectConnection)
3
Example 47
Project: pika Source File: async_test_base.py
@unittest.skipIf(not hasattr(select, 'kqueue'), "kqueue not supported")
def select_kqueue_test(self):
"""SelectConnection:kqueue"""
with mock.patch.multiple(select_connection, SELECT_TYPE='kqueue'):
self.start(adapters.SelectConnection)
3
Example 48
def test_retry(self):
mocked_time = MagicMock()
mocked_method = MagicMock(side_effect=ValueError)
with patch.multiple('gitfs.utils.decorators.retry', wraps=MockedWraps,
time=mocked_time):
again = retry(times=3)
with pytest.raises(ValueError):
again(mocked_method)("arg", kwarg="kwarg")
mocked_time.sleep.has_calls([call(3), call(3), call(1)])
mocked_method.has_calls([call("arg", kwarg="kwarg")])
3
Example 49
Project: pyolite Source File: test_repository.py
def test_get_repository(self):
mocked_repository = MagicMock()
mocked_repository.get_by_name.return_value = 'my_repo'
RepositoryManager.__bases__ = (MockManager,)
with patch.multiple('pyolite.managers.repository',
Repository=mocked_repository):
repos = RepositoryManager('/path/to/admin/repo/')
eq_(repos.get('my_repo'), 'my_repo')
mocked_repository.get_by_name.assert_called_once_with('my_repo',
mocked_path,
mocked_git)
3
Example 50
Project: requests-kerberos Source File: test_requests_kerberos.py
def test_force_preemptive(self):
with patch.multiple(kerberos_module_name,
authGSSClientInit=clientInit_complete,
authGSSClientResponse=clientResponse,
authGSSClientStep=clientStep_continue):
auth = requests_kerberos.HTTPKerberosAuth(force_preemptive=True)
request = requests.Request(url="http://www.example.org")
auth.__call__(request)
self.assertTrue('Authorization' in request.headers)
self.assertEqual(request.headers.get('Authorization'), 'Negotiate GSSRESPONSE')