Here are the examples of the python api mock.call.run taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
2 Examples
3
Example 1
@patch('golemapp.GNRNode')
def test_task(self, mock_node):
a = A()
dump = os.path.join(self.path, 'testcalssdump')
with open(dump, 'w') as f:
cPickle.dump(a, f)
args = self.args + ['--task', dump, '--task', dump]
return_value = CliRunner().invoke(start, args, catch_exceptions=False)
self.assertEqual(return_value.exit_code, 0)
mock_node.assert_has_calls([call().run(use_rpc=True)])
call_names = [name for name, arg, kwarg in mock_node.mock_calls]
self.assertTrue('().add_tasks' in call_names)
task_num = call_names.index('().add_tasks')
task_arg = mock_node.mock_calls[task_num][1][0]
self.assertEqual(len(task_arg), 2)
self.assertIsInstance(task_arg[0], A)
0
Example 2
Project: golem Source File: test_gnr_node.py
@patch('golemapp.GNRNode')
def test_task_from_json(self, mock_node):
test_json_file = os.path.join(self.path, 'task.json')
a1 = A()
a1.name = 'Jake the Dog'
a2 = A()
a2.child = a1
with open(test_json_file, 'w') as f:
j = jsonpickle.encode(a2)
f.write(j)
try:
runner = CliRunner()
args = self.args + ['--task', test_json_file]
return_value = runner.invoke(start, args, catch_exceptions=False)
self.assertEqual(return_value.exit_code, 0)
mock_node.assert_has_calls([call().run(use_rpc=True)])
call_names = [name for name, arg, kwarg in mock_node.mock_calls]
self.assertTrue('().add_tasks' in call_names)
add_tasks_num = call_names.index('().add_tasks')
(task_arg, ) = mock_node.mock_calls[add_tasks_num][1][0]
self.assertIsInstance(task_arg, A)
self.assertEqual(task_arg.child.name, 'Jake the Dog')
finally:
if os.path.exists(test_json_file):
os.remove(test_json_file)