本文整理汇总了Python中mock.Mock.assert_not_called方法的典型用法代码示例。如果您正苦于以下问题:Python Mock.assert_not_called方法的具体用法?Python Mock.assert_not_called怎么用?Python Mock.assert_not_called使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mock.Mock
的用法示例。
在下文中一共展示了Mock.assert_not_called方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: report_changed_test
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import assert_not_called [as 别名]
def report_changed_test(self):
"""Test reporting changed properties."""
test1 = self.Test1()
callback = Mock()
test1.PropertiesChanged.connect(callback)
test1.flush_changes()
callback.assert_not_called()
test1.report_changed_property("A")
test1.flush_changes()
callback.assert_called_once_with("I1", {"A": 1}, [])
callback.reset_mock()
test1.report_changed_property("B")
test1.flush_changes()
callback.assert_called_once_with("I1", {"B": 2}, [])
callback.reset_mock()
test1.report_changed_property("B")
test1.report_changed_property("A")
test1.flush_changes()
callback.assert_called_once_with("I1", {"A": 1, "B": 2}, [])
callback.reset_mock()
示例2: test_DBExporter
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import assert_not_called [as 别名]
def test_DBExporter():
path = u'apa/movie'
xt = u'tree:tiger:ASDASDSADASDASDSADASDASDSADASDASDSADASD'
db = DB(':memory:')
db.update(Object(u"dir:apa", {
u'directory': ValueSet(u"dir:/apa"),
}))
db.update(Object('some_file', {
u'directory': ValueSet(u"dir:apa/movie"),
u'xt': ValueSet(xt),
}))
asset = Mock()
asset.__enter__ = Mock(return_value=asset)
asset.__exit__ = Mock(return_value=False)
asset.status = Mock(
return_value=proto.AssetStatus(status=proto.SUCCESS))
bithorde = Mock()
bithorde.open = Mock(return_value=asset)
bithorde.pool = Mock(return_value=itertools)
writer = Mock()
magnet = u'magnet:?xt=urn:' + xt
exp = links.DBExporter(db, bithorde, writer)
exp.export(False)
writer.assert_called_once_with(path, magnet)
writer.reset_mock()
exp.export(False)
writer.assert_not_called()
exp.export(True)
writer.assert_called_once_with(path, magnet)
示例3: test_execute_with_ids
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import assert_not_called [as 别名]
def test_execute_with_ids(self):
engine = Mock()
engine.log = Mock()
engine.log.info = MagicMock()
engine.log.failed = MagicMock()
topics1 = [Mock()]
get_topics_mock1 = Mock(return_value=topics1)
topics2 = []
get_topics_mock2 = Mock(return_value=topics2)
execute_mock1 = Mock()
# Exception shouldn't be thrown because there are no tocpis for plugin
execute_mock2 = Mock(return_value=Exception)
self.tracker1.execute = execute_mock1
self.tracker1.get_topics = get_topics_mock1
self.tracker2.execute = execute_mock2
self.tracker2.get_topics = get_topics_mock2
ids = [1, 2]
self.trackers_manager.execute(engine, ids)
self.assertTrue(engine.log.info.called)
self.assertFalse(engine.log.failed.called) # Check that exception from tracker2 wasn't raised
get_topics_mock1.assert_called_with(ids)
execute_mock1.assert_called_with(topics1, engine)
get_topics_mock2.assert_called_with(ids)
execute_mock2.assert_not_called()
示例4: test_change_day_in_battle
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import assert_not_called [as 别名]
def test_change_day_in_battle(self):
mock_process = Mock()
f = FieldClock()
field = MagicMock(in_battle=True,
process_battle_and_movement=mock_process)
f.change_day(field)
mock_process.assert_not_called()
示例5: test_keyspace_flag_raises_before_v5
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import assert_not_called [as 别名]
def test_keyspace_flag_raises_before_v5(self):
keyspace_message = QueryMessage('a', consistency_level=3, keyspace='ks')
io = Mock(name='io')
with self.assertRaisesRegexp(UnsupportedOperation, 'Keyspaces.*set'):
keyspace_message.send_body(io, protocol_version=4)
io.assert_not_called()
示例6: test_command_has_no_sub___action_from_command_is_called
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import assert_not_called [as 别名]
def test_command_has_no_sub___action_from_command_is_called(self, action_res, other_action_res, sub_parser_names, command_name):
selected = choice(sub_parser_names)
action_mock = Mock(return_value=action_res)
other_action_mock = Mock(return_value=other_action_res)
class SubCmd(cmd.Base):
def action(self, args):
return action_mock(args)
class OtherSubCmd(cmd.Base):
def action(self, args):
return other_action_mock(args)
class Cmd(cmd.Base):
sub_commands = dict(
(n, (SubCmd if n == selected else OtherSubCmd)) for n in sub_parser_names
)
sys.argv = ['foo', selected]
command = Cmd(command_name)
res = command.run()
self.assertEqual(res, action_res)
action_mock.assert_called_once_with(command.parse_args())
other_action_mock.assert_not_called()
示例7: test_lazylist_map_no_call
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import assert_not_called [as 别名]
def test_lazylist_map_no_call():
mock_func = Mock()
double_func = lambda x: x * 2
ll = LazyList([mock_func])
ll_mapped = ll.map(double_func)
assert id(ll) != id(ll_mapped)
mock_func.assert_not_called()
示例8: test_init_adds_members
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import assert_not_called [as 别名]
def test_init_adds_members(self):
mock_connection = Mock()
obj = type('TestType', (ObjectProxy,), {})(mock_connection, ['a:get', 'a:set', 'setTest'])
self.assertTrue(hasattr(type(obj), 'a'))
self.assertTrue(hasattr(obj, 'setTest'))
mock_connection.assert_not_called()
示例9: test_enforce_hostname_middleware
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import assert_not_called [as 别名]
def test_enforce_hostname_middleware():
get_resp_mock = Mock()
mw = EnforceHostnameMiddleware(get_resp_mock)
req = RequestFactory().get('/', HTTP_HOST='basket.mozilla.org')
resp = mw(req)
get_resp_mock.assert_called_once_with(req)
get_resp_mock.reset_mock()
req = RequestFactory().get('/', HTTP_HOST='basket.allizom.org')
resp = mw(req)
get_resp_mock.assert_not_called()
assert resp.status_code == 301
assert resp['location'] == 'http://basket.mozilla.org/'
# IP address should not redirect
get_resp_mock.reset_mock()
req = RequestFactory().get('/', HTTP_HOST='123.123.123.123')
resp = mw(req)
get_resp_mock.assert_called_once_with(req)
# IP with port should also work
get_resp_mock.reset_mock()
req = RequestFactory().get('/', HTTP_HOST='1.2.3.4:12345')
resp = mw(req)
get_resp_mock.assert_called_once_with(req)
示例10: test_update
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import assert_not_called [as 别名]
def test_update(self, include_prerelease, is_started, start_interval, enabled, interval, start_called, stop_called):
checker = NewVersionChecker(False)
def start_side_effect(i):
checker.interval = i
start_mock = Mock(side_effect=start_side_effect)
stop_mock = Mock()
is_started_mock = Mock(return_value=is_started)
checker.interval = start_interval
checker.start = start_mock
checker.stop = stop_mock
checker.is_started = is_started_mock
checker.update(include_prerelease, enabled, interval)
self.assertEqual(checker.interval, interval)
self.assertEqual(checker.include_prereleases, include_prerelease)
if start_called:
start_mock.assert_called_once_with(interval)
else:
start_mock.assert_not_called()
if stop_called:
stop_mock.assert_called_once()
else:
stop_mock.assert_not_called()
示例11: test_callbacks_and_pool_when_oto
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import assert_not_called [as 别名]
def test_callbacks_and_pool_when_oto(self):
"""
Test to ensure the callbacks are correcltly called and the connection
is returned when there is an OTO
@since 3.12
@jira_ticket PYTHON-630
@expected_result the connection is correctly returned to the pool
after an OTO, also the only the errback is called and not the callback
when the message finally arrives.
@test_category metadata
"""
start_and_prime_singledc()
cluster = Cluster(protocol_version=PROTOCOL_VERSION, compression=False)
session = cluster.connect()
self.addCleanup(cluster.shutdown)
query_to_prime = "SELECT * from testkesypace.testtable"
server_delay = 2 # seconds
prime_query(query_to_prime, then={"delay_in_ms": server_delay * 1000})
future = session.execute_async(query_to_prime, timeout=1)
callback, errback = Mock(name='callback'), Mock(name='errback')
future.add_callbacks(callback, errback)
self.assertRaises(OperationTimedOut, future.result)
assert_quiescent_pool_state(self, cluster)
time.sleep(server_delay + 1)
# PYTHON-630 -- only the errback should be called
errback.assert_called_once()
callback.assert_not_called()
示例12: test_listeners
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import assert_not_called [as 别名]
def test_listeners():
"""`listeners()` returns a copied list of listeners."""
call_me = Mock()
ee = BaseEventEmitter()
@ee.on('event')
def event_handler():
pass
@ee.once('event')
def once_handler():
pass
listeners = ee.listeners('event')
assert listeners[0] == event_handler
assert listeners[1] == once_handler
# listeners is a copy, you can't mutate the innards this way
listeners[0] = call_me
ee.emit('event')
call_me.assert_not_called()
示例13: test__play_card
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import assert_not_called [as 别名]
def test__play_card(self):
board = Mock()
self.p.play_card(board)
self.assertEqual(self.p.gold, 9)
board.assert_not_called()
self.sp.play_card(board)
self.assertEqual(self.sp.gold, 8)
board.assert_not_called()
示例14: test_ecr_login_image_exists
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import assert_not_called [as 别名]
def test_ecr_login_image_exists(_check_output):
session_mock = Mock()
image = '520713654638.dkr.ecr.us-east-1.amazonaws.com/image-i-have:1.0'
sagemaker.local.image._ecr_login_if_needed(session_mock, image)
session_mock.assert_not_called()
_check_output.assert_called()
示例15: test__del__0
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import assert_not_called [as 别名]
def test__del__0(self):
self.ftp.connected = Mock(return_value=False)
m_disconnect = Mock()
self.ftp.disconnect = m_disconnect
del(self.ftp)
m_disconnect.assert_not_called()