本文整理汇总了Python中unittest.mock.Mock.assert_not_called方法的典型用法代码示例。如果您正苦于以下问题:Python Mock.assert_not_called方法的具体用法?Python Mock.assert_not_called怎么用?Python Mock.assert_not_called使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类unittest.mock.Mock
的用法示例。
在下文中一共展示了Mock.assert_not_called方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_compute_distances_distance_no_data
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import assert_not_called [as 别名]
def test_compute_distances_distance_no_data(self):
widget = self.widget
distance = Mock()
try:
orig_metrics = METRICS[widget.distance_index]
METRICS[widget.distance_index] = ("foo", distance)
data = Table("iris")
data, refs = data[:10], data[-5:]
self.send_signals([(widget.Inputs.data, data),
(widget.Inputs.reference, None)])
distance.assert_not_called()
self.assertIsNone(widget.distances)
self.send_signal(widget.Inputs.data, data)
distance.assert_not_called()
self.assertIsNone(widget.distances)
self.send_signals([(widget.Inputs.data, None),
(widget.Inputs.reference, refs)])
distance.assert_not_called()
self.assertIsNone(widget.distances)
self.send_signals([(widget.Inputs.data, data),
(widget.Inputs.reference, None)])
distance.assert_not_called()
self.assertIsNone(widget.distances)
data, refs = data[:0], data[:0]
self.send_signals([(widget.Inputs.data, data),
(widget.Inputs.reference, None)])
distance.assert_not_called()
self.assertIsNone(widget.distances)
finally:
METRICS[widget.distance_index] = orig_metrics
示例2: test_run_command
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import assert_not_called [as 别名]
def test_run_command(self, subprocess):
pdfparser = PDFParser()
comm_err = Mock(return_value=(b'', b'an error'))
comm_out = Mock(return_value=(b'success', b''))
proc_out = Mock(communicate=comm_out)
proc_err = Mock(communicate=comm_err)
popen_yes = Mock(return_value=proc_out)
popen_bad = Mock(return_value=proc_err)
# check the good case
subprocess.Popen = popen_yes
args = ['pdf_action', 'go']
full_args = ['java', '-jar', 'pdfparser.jar'] + args
result = pdfparser.run_command(args)
self.assertEqual('success', result)
popen_yes.assert_called_once_with(full_args,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
comm_out.assert_called_once_with()
proc_out.assert_not_called()
# check the bad case
subprocess.reset_mock()
subprocess.Popen = popen_bad
args = ['go']
with self.assertRaises(PDFParserError):
pdfparser.run_command(args)
full_args = ['java', '-jar', 'pdfparser.jar'] + args
proc_err.assert_not_called()
comm_err.assert_called_once_with()
popen_bad.assert_called_once_with(full_args,
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
示例3: test_run_command
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import assert_not_called [as 别名]
def test_run_command(self, subprocess):
pdftk = PDFTKWrapper()
comm_err = Mock(return_value=(b'', b'an error'))
comm_out = Mock(return_value=(b'success', b''))
proc_out = Mock(communicate=comm_out)
proc_err = Mock(communicate=comm_err)
popen_yes = Mock(return_value=proc_out)
popen_bad = Mock(return_value=proc_err)
# check the good case
subprocess.Popen = popen_yes
args = ['pdftk', 'go']
result = pdftk.run_command(args)
self.assertEqual('success', result)
popen_yes.assert_called_once_with(args,
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
comm_out.assert_called_once_with()
proc_out.assert_not_called()
# check the arg fixing
popen_yes.reset_mock()
result = pdftk.run_command(['dostuff'])
popen_yes.assert_called_once_with(['pdftk','dostuff'],
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
# check the bad case
subprocess.reset_mock()
subprocess.Popen = popen_bad
args = ['go']
with self.assertRaises(PdftkError):
pdftk.run_command(args)
proc_err.assert_not_called()
comm_err.assert_called_once_with()
popen_bad.assert_called_once_with(['pdftk','go'],
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
示例4: test_process_callback_mode
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import assert_not_called [as 别名]
def test_process_callback_mode(self):
"""Test if after_update_callback is called after update of Climate object was changed."""
# pylint: disable=no-self-use
xknx = XKNX(loop=self.loop)
climate_mode = ClimateMode(
xknx,
'TestClimate',
group_address_operation_mode='1/2/5')
after_update_callback = Mock()
async def async_after_update_callback(device):
"""Async callback."""
after_update_callback(device)
climate_mode.register_device_updated_cb(async_after_update_callback)
self.loop.run_until_complete(asyncio.Task(
climate_mode.set_operation_mode(HVACOperationMode.COMFORT)))
after_update_callback.assert_called_with(climate_mode)
after_update_callback.reset_mock()
self.loop.run_until_complete(asyncio.Task(
climate_mode.set_operation_mode(HVACOperationMode.COMFORT)))
after_update_callback.assert_not_called()
after_update_callback.reset_mock()
self.loop.run_until_complete(asyncio.Task(
climate_mode.set_operation_mode(HVACOperationMode.FROST_PROTECTION)))
after_update_callback.assert_called_with(climate_mode)
after_update_callback.reset_mock()
示例5: test_frequency_shift
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import assert_not_called [as 别名]
def test_frequency_shift():
component = p.FrequencyShift(None)
data_port = pyflo.ports.Outport({"name": "data"})
data_port.connect(component.inports["in"])
shift_port = pyflo.ports.Outport({"name": "shift"})
shift_port.connect(component.inports["shift"])
test_spectrum = numpy.zeros(128, 'complex')
test_spectrum[0] = 1
target_fid = numpy.fft.ifft(test_spectrum)
target_data = suspect.MRSData(target_fid, 1.0 / 128, 123)
shifted_spectrum = numpy.roll(test_spectrum, 16)
shifted_fid = numpy.fft.ifft(shifted_spectrum)
shifted_data = suspect.MRSData(shifted_fid, 1.0 / 128, 123)
target_port = pyflo.ports.Inport({"name": "result"})
component.outports["out"].connect(target_port)
mock = Mock()
target_port.on('data', mock)
data_port.send_data(shifted_data)
mock.assert_not_called()
shift_port.send_data(-16.0)
numpy.testing.assert_almost_equal(target_data, mock.call_args[0][0])
# try sending the data the other way
mock = Mock()
target_port.on('data', mock)
shift_port.send_data(-16.0)
mock.assert_not_called()
data_port.send_data(shifted_data)
numpy.testing.assert_almost_equal(target_data, mock.call_args[0][0])
示例6: test_caching_of_values
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import assert_not_called [as 别名]
def test_caching_of_values(self):
"""Test that caching of values for authenticate users."""
session_mock = MagicMock()
session_dict = {}
session_mock.__setitem__.side_effect = session_dict.__setitem__
session_mock.__getitem__.side_effect = session_dict.__getitem__
session_mock.__contains__.side_effect = session_dict.__contains__
self.request.session = session_mock
mock = Mock(return_value=False)
self.request.user.groups.filter().exists = mock
self.assertFalse(is_user_admin(self.request))
mock.assert_called_once_with()
session_mock.__setitem__.assert_called_once_with(
'cache_user_is_admin', False)
mock = Mock(return_value=False)
self.request.user.groups.filter().exists = mock
self.assertFalse(is_user_admin(self.request, cached=True))
mock.assert_not_called()
session_mock.__getitem__.assert_called_once_with(
'cache_user_is_admin')
mock = Mock(return_value=False)
self.request.user.groups.filter().exists = mock
self.assertFalse(is_user_admin(self.request, cached=False))
mock.assert_called_once_with()
session_mock.__getitem__.assert_called_once_with(
'cache_user_is_admin')
示例7: test_run_tests_using_unittest_and_display_results
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import assert_not_called [as 别名]
def test_run_tests_using_unittest_and_display_results(qtbot, tmpdir,
monkeypatch):
"""Basic check."""
os.chdir(tmpdir.strpath)
testfilename = tmpdir.join('test_foo.py').strpath
with open(testfilename, 'w') as f:
f.write("import unittest\n"
"class MyTest(unittest.TestCase):\n"
" def test_ok(self): self.assertEqual(1+1, 2)\n"
" def test_fail(self): self.assertEqual(1+1, 3)\n")
MockQMessageBox = Mock()
monkeypatch.setattr('spyder_unittest.widgets.unittestgui.QMessageBox',
MockQMessageBox)
widget = UnitTestWidget(None)
qtbot.addWidget(widget)
config = Config(wdir=tmpdir.strpath, framework='unittest')
with qtbot.waitSignal(widget.sig_finished, timeout=10000, raising=True):
widget.run_tests(config)
MockQMessageBox.assert_not_called()
model = widget.testdatamodel
assert model.rowCount() == 2
assert model.index(0, 0).data(Qt.DisplayRole) == 'FAIL'
assert model.index(0, 1).data(Qt.DisplayRole) == 't.M.test_fail'
assert model.index(0, 1).data(Qt.ToolTipRole) == 'test_foo.MyTest.test_fail'
assert model.index(0, 2).data(Qt.DisplayRole) == ''
assert model.index(1, 0).data(Qt.DisplayRole) == 'ok'
assert model.index(1, 1).data(Qt.DisplayRole) == 't.M.test_ok'
assert model.index(1, 1).data(Qt.ToolTipRole) == 'test_foo.MyTest.test_ok'
assert model.index(1, 2).data(Qt.DisplayRole) == ''
示例8: test_run_tests_and_display_results
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import assert_not_called [as 别名]
def test_run_tests_and_display_results(qtbot, tmpdir, monkeypatch, framework):
"""Basic integration test."""
os.chdir(tmpdir.strpath)
testfilename = tmpdir.join('test_foo.py').strpath
with open(testfilename, 'w') as f:
f.write("def test_ok(): assert 1+1 == 2\n"
"def test_fail(): assert 1+1 == 3\n")
MockQMessageBox = Mock()
monkeypatch.setattr('spyder_unittest.widgets.unittestgui.QMessageBox',
MockQMessageBox)
widget = UnitTestWidget(None)
qtbot.addWidget(widget)
config = Config(wdir=tmpdir.strpath, framework=framework)
with qtbot.waitSignal(widget.sig_finished, timeout=10000, raising=True):
widget.run_tests(config)
MockQMessageBox.assert_not_called()
model = widget.testdatamodel
assert model.rowCount() == 2
assert model.index(0, 0).data(Qt.DisplayRole) == 'ok'
assert model.index(0, 1).data(Qt.DisplayRole) == 't.test_ok'
assert model.index(0, 1).data(Qt.ToolTipRole) == 'test_foo.test_ok'
assert model.index(0, 2).data(Qt.DisplayRole) == ''
assert model.index(1, 0).data(Qt.DisplayRole) == 'failure'
assert model.index(1, 1).data(Qt.DisplayRole) == 't.test_fail'
assert model.index(1, 1).data(Qt.ToolTipRole) == 'test_foo.test_fail'
示例9: test_multi
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import assert_not_called [as 别名]
def test_multi(self):
loop = asyncio.get_event_loop()
run = loop.run_until_complete
m = get_task('multi')()
run(m.start(['date', 'sleep', 'date'], [(['%d-%m-%Y %H:%M %Z'], {'utc':True}), ([1], {}),
(['%d-%m-%Y %H:%M %Z'], {'utc':False}),]))
cb = Mock()
t = run(m.next_task())
self.assertEqual(t.task_name, 'date')
self.assertEqual(t.task_no, 0)
run(m.update_task_result(0, result=0, on_all_finished=cb))
cb.assert_not_called()
t = run(m.next_task())
self.assertEqual(t.task_name, 'sleep')
self.assertEqual(t.task_no, 1)
run(m.update_task_result(1, result=1, on_all_finished=cb))
cb.assert_not_called()
t = run(m.next_task())
self.assertEqual(t.task_name, 'date')
self.assertEqual(t.task_no, 2)
self.assertEqual(t.task_kwargs, {'utc':False})
run(m.update_task_result(2, result=2, on_all_finished=cb))
self.assertEqual(cb.call_count, 1)
self.assertEqual(cb.call_args[0][0]['results'], [0,1,2])
self.assertTrue(cb.call_args[0][0]['duration']>0 )
t = run(m.next_task())
self.assertTrue(t is None)
示例10: test_stack_wait_axis
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import assert_not_called [as 别名]
def test_stack_wait_axis():
component = pyflo.components.numpy.StackComponent(None)
data_port = pyflo.ports.Outport({"name": "data"})
data_port.connect(component.inports["in"])
axis_port = pyflo.ports.Outport({"name": "axis"})
axis_port.connect(component.inports["axis"])
target_port = pyflo.ports.Inport({"name": "target"})
begin_mock = Mock()
data_mock = Mock()
end_mock = Mock()
target_port.on('beginGroup', begin_mock)
target_port.on('data', data_mock)
target_port.on('endGroup', end_mock)
component.outports["out"].connect(target_port)
data_port.begin_group()
data_port.begin_group()
begin_mock.assert_called_once_with()
data_port.send_data(numpy.arange(10))
data_port.send_data(numpy.ones(10))
data_port.end_group()
data_port.end_group()
end_mock.assert_not_called()
axis_port.send_data(1)
target = numpy.stack([numpy.arange(10), numpy.ones(10)], axis=1)
numpy.testing.assert_almost_equal(data_mock.call_args[0][0], target)
end_mock.assert_called_once_with()
示例11: test_build_bundled_pdf_with_no_filled_pdfs
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import assert_not_called [as 别名]
def test_build_bundled_pdf_with_no_filled_pdfs(self):
cc_pubdef = auth_models.Organization.objects.get(
slug=constants.Organizations.COCO_PUBDEF)
sub = SubmissionsService.create_for_organizations(
[cc_pubdef], answers={})
bundle = BundlesService.create_bundle_from_submissions(
organization=cc_pubdef, submissions=[sub], skip_pdf=True)
get_pdfs_mock = Mock()
bundle.get_individual_filled_pdfs = get_pdfs_mock
BundlesService.build_bundled_pdf_if_necessary(bundle)
get_pdfs_mock.assert_not_called()
示例12: test_feed_none
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import assert_not_called [as 别名]
def test_feed_none(self):
feed_none = FeedNone()
not_called = Mock()
not_called.feed_creature = Mock()
not_called.kill_creature = Mock()
not_called.fat_feed = Mock()
player = Mock()
feed_none.enact(player, [], not_called)
player.assert_not_called()
not_called.feed_creature.assert_not_called()
not_called.kill_creature.assert_not_called()
not_called.fat_feed.assert_not_called()
示例13: test_cant_feed
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import assert_not_called [as 别名]
def test_cant_feed(self):
cant_feed = CannotFeed()
not_called = Mock()
not_called.feed_creature = Mock()
not_called.kill_creature = Mock()
not_called.fat_feed = Mock()
player = Mock()
cant_feed.enact(player, [], not_called)
player.assert_not_called()
not_called.feed_creature.assert_not_called()
not_called.kill_creature.assert_not_called()
not_called.fat_feed.assert_not_called()
示例14: TestEpochLambda
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import assert_not_called [as 别名]
class TestEpochLambda(unittest.TestCase):
def setUp(self):
self._metric_function = Mock(return_value='test')
self._metric = EpochLambda('test', self._metric_function, step_size=3)
self._metric.reset({torchbearer.DEVICE: 'cpu', torchbearer.DATA_TYPE: torch.float32})
self._states = [{torchbearer.BATCH: 0, torchbearer.Y_TRUE: torch.LongTensor([0]), torchbearer.Y_PRED: torch.FloatTensor([0.0]), torchbearer.DEVICE: 'cpu'},
{torchbearer.BATCH: 1, torchbearer.Y_TRUE: torch.LongTensor([1]), torchbearer.Y_PRED: torch.FloatTensor([0.1]), torchbearer.DEVICE: 'cpu'},
{torchbearer.BATCH: 2, torchbearer.Y_TRUE: torch.LongTensor([2]), torchbearer.Y_PRED: torch.FloatTensor([0.2]), torchbearer.DEVICE: 'cpu'},
{torchbearer.BATCH: 3, torchbearer.Y_TRUE: torch.LongTensor([3]), torchbearer.Y_PRED: torch.FloatTensor([0.3]), torchbearer.DEVICE: 'cpu'},
{torchbearer.BATCH: 4, torchbearer.Y_TRUE: torch.LongTensor([4]), torchbearer.Y_PRED: torch.FloatTensor([0.4]), torchbearer.DEVICE: 'cpu'}]
def test_train(self):
self._metric.train()
calls = [[torch.FloatTensor([0.0]), torch.LongTensor([0])],
[torch.FloatTensor([0.0, 0.1, 0.2, 0.3]), torch.LongTensor([0, 1, 2, 3])]]
for i in range(len(self._states)):
self._metric.process(self._states[i])
self.assertEqual(2, len(self._metric_function.call_args_list))
for i in range(len(self._metric_function.call_args_list)):
self.assertTrue(torch.eq(self._metric_function.call_args_list[i][0][0], calls[i][0]).all)
self.assertTrue(torch.lt(torch.abs(torch.add(self._metric_function.call_args_list[i][0][1], -calls[i][1])), 1e-12).all)
self._metric_function.reset_mock()
self._metric.process_final({})
self._metric_function.assert_called_once()
self.assertTrue(torch.eq(self._metric_function.call_args_list[0][0][1], torch.LongTensor([0, 1, 2, 3, 4])).all)
self.assertTrue(torch.lt(torch.abs(torch.add(self._metric_function.call_args_list[0][0][0], -torch.FloatTensor([0.0, 0.1, 0.2, 0.3, 0.4]))), 1e-12).all)
def test_validate(self):
self._metric.eval()
for i in range(len(self._states)):
self._metric.process(self._states[i])
self._metric_function.assert_not_called()
self._metric.process_final_validate({})
self._metric_function.assert_called_once()
self.assertTrue(torch.eq(self._metric_function.call_args_list[0][0][1], torch.LongTensor([0, 1, 2, 3, 4])).all)
self.assertTrue(torch.lt(torch.abs(torch.add(self._metric_function.call_args_list[0][0][0], -torch.FloatTensor([0.0, 0.1, 0.2, 0.3, 0.4]))), 1e-12).all)
def test_not_running(self):
metric = EpochLambda('test', self._metric_function, running=False, step_size=6)
metric.reset({torchbearer.DEVICE: 'cpu', torchbearer.DATA_TYPE: torch.float32})
metric.train()
for i in range(12):
metric.process(self._states[0])
self._metric_function.assert_not_called()
示例15: SignalTest
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import assert_not_called [as 别名]
class SignalTest(unittest.TestCase):
def setUp(self):
self.stack = modstack.UndoStack()
self.canUndoChanged = Mock()
self.canRedoChanged = Mock()
self.stack.canUndoChanged.connect(self.canUndoChanged)
self.stack.canRedoChanged.connect(self.canRedoChanged)
def testPush(self):
self.stack.push(CallMock(), CallMock())
self.canRedoChanged.assert_called_once_with(False)
self.canUndoChanged.assert_called_once_with(True)
def testMacro(self):
self.stack.beginMacro()
self.stack.push(CallMock(), CallMock())
self.canRedoChanged.assert_not_called()
self.canUndoChanged.assert_not_called()
self.stack.endMacro()
self.canRedoChanged.assert_called_once_with(False)
self.canUndoChanged.assert_called_once_with(True)
def testUndo(self):
self.stack.push(CallMock(), CallMock())
self.canRedoChanged.reset_mock()
self.canUndoChanged.reset_mock()
self.stack.undo()
self.canRedoChanged.assert_called_once_with(True)
self.canUndoChanged.assert_called_once_with(False)
def testRedo(self):
self.stack.push(CallMock(), CallMock())
self.stack.undo()
self.canRedoChanged.reset_mock()
self.canUndoChanged.reset_mock()
self.stack.redo()
self.canRedoChanged.assert_called_once_with(False)
self.canUndoChanged.assert_called_once_with(True)
def testClear(self):
self.stack.push(CallMock(), CallMock())
self.canRedoChanged.reset_mock()
self.canUndoChanged.reset_mock()
self.stack.clear()
self.canRedoChanged.assert_called_once_with(False)
self.canUndoChanged.assert_called_once_with(False)