本文整理汇总了Python中pytest_mock.mocker方法的典型用法代码示例。如果您正苦于以下问题:Python pytest_mock.mocker方法的具体用法?Python pytest_mock.mocker怎么用?Python pytest_mock.mocker使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pytest_mock
的用法示例。
在下文中一共展示了pytest_mock.mocker方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_payroll
# 需要导入模块: import pytest_mock [as 别名]
# 或者: from pytest_mock import mocker [as 别名]
def test_payroll(mocker, payroll):
# Create a mock version of Person with default return result
mocker.patch.object(people.Person, 'calculate_pay')
people.Person.calculate_pay.return_value = 250.0
result = payroll.generate_payslip(people.Person())
# Verify that mock method was called
people.Person.calculate_pay.assert_called()
# Verify that the result from payroll was correct
assert 'You earned 250.0' == result
示例2: test_process_workspace_standard
# 需要导入模块: import pytest_mock [as 别名]
# 或者: from pytest_mock import mocker [as 别名]
def test_process_workspace_standard(mocker):
workspace = {
'WorkspaceId': 'ws-68h123hty',
'DirectoryId': 'd-901230bb84',
'UserName': 'test_user',
'IpAddress': '111.16.1.233',
'State': 'AVAILABLE',
'BundleId': 'wsb-cl123qzj1',
'SubnetId': 'subnet-05d421387eaa7cf86',
'ComputerName': 'A-APPW123KP4NP',
'WorkspaceProperties': {
'RunningMode': 'ALWAYS_ON',
'RootVolumeSizeGib': 80,
'UserVolumeSizeGib': 50,
'ComputeTypeName': 'STANDARD'
},
'ModificationStates': []
}
settings = {
'region': 'us-east-1',
'hourlyLimits': 10,
'testEndOfMonth': 'yes',
'isDryRun': 'yes',
'startTime': 1,
'endTime': 2
}
workspace_helper = WorkspacesHelper(settings)
mocker.patch.object(workspace_helper.metricsHelper, 'get_billable_time')
workspace_helper.metricsHelper.get_billable_time.return_value = 444
mocker.patch.object(workspace_helper, 'check_for_skip_tag')
workspace_helper.check_for_skip_tag.return_value = True
result = workspace_helper.process_workspace(workspace)
assert result['bundleType'] == 'STANDARD'
示例3: test_react_to_intent
# 需要导入模块: import pytest_mock [as 别名]
# 或者: from pytest_mock import mocker [as 别名]
def test_react_to_intent(mocker):
from ravestate_verbaliser import verbaliser
verbaliser.add_file(join(dirname(realpath(__file__)),
"verbaliser_testfiles", "phrases_test.yml"))
import ravestate_verbaliser
import ravestate_rawio as rawio
test_dict = {'verbaliser:intent:changed': 'test1'}
ravestate_verbaliser.react_to_intent(test_dict)
assert test_dict[rawio.prop_out] in ravestate_verbaliser.verbaliser.get_phrase_list('test1')
示例4: test_react_to_intent_no_phrase
# 需要导入模块: import pytest_mock [as 别名]
# 或者: from pytest_mock import mocker [as 别名]
def test_react_to_intent_no_phrase(mocker):
from ravestate_verbaliser import verbaliser
verbaliser.add_file(join(dirname(realpath(__file__)),
"verbaliser_testfiles", "phrases_test.yml"))
import ravestate_verbaliser
test_dict = {'verbaliser:intent:changed': 'test'}
ravestate_verbaliser.react_to_intent(test_dict)
assert "rawio:out" not in test_dict
示例5: test_react_to_play_asked
# 需要导入模块: import pytest_mock [as 别名]
# 或者: from pytest_mock import mocker [as 别名]
def test_react_to_play_asked(mocker):
import ravestate_akinator as akin
import ravestate_rawio as rawio
test_dict = {}
akin.play_ask(test_dict)
assert test_dict[rawio.prop_out] == "Do you want to play 20 questions?"
示例6: test_play_question_ignored
# 需要导入模块: import pytest_mock [as 别名]
# 或者: from pytest_mock import mocker [as 别名]
def test_play_question_ignored(mocker):
import ravestate_akinator as akin
import ravestate_rawio as rawio
test_dict = {}
akin.akinator_play_question_ignored(test_dict)
assert test_dict[rawio.prop_out] == "Oh well, maybe later!"
示例7: test_execute_state
# 需要导入模块: import pytest_mock [as 别名]
# 或者: from pytest_mock import mocker [as 别名]
def test_execute_state(mocker):
record = TaintRecord()
record.stack = [True, False, True]
state = GlobalState(None, None)
state.mstate.stack = [1, 2, 3]
mocker.patch.object(state, 'get_current_instruction')
state.get_current_instruction.return_value = {"opcode": "ADD"}
# Act
new_record = TaintRunner.execute_state(record, state)
# Assert
assert new_record.stack == [True, True]
assert record.stack == [True, False, True]
示例8: test_execute_node
# 需要导入模块: import pytest_mock [as 别名]
# 或者: from pytest_mock import mocker [as 别名]
def test_execute_node(mocker):
record = TaintRecord()
record.stack = [True, True, False, False]
state_1 = GlobalState(None, None)
state_1.mstate.stack = [1, 2, 3]
state_1.mstate.pc = 1
mocker.patch.object(state_1, 'get_current_instruction')
state_1.get_current_instruction.return_value = {"opcode": "SWAP1"}
state_2 = GlobalState(None, 1)
state_2.mstate.stack = [1, 2, 4, 1]
mocker.patch.object(state_2, 'get_current_instruction')
state_2.get_current_instruction.return_value = {"opcode": "ADD"}
node = Node("Test contract")
node.states = [state_1, state_2]
# Act
records = TaintRunner.execute_node(node, record)
# Assert
assert len(records) == 2
assert records[0].stack == [True, True, False, False]
assert records[1].stack == [True, True, False]
assert state_2 in records[0].states
assert state_1 in record.states
示例9: test_execute
# 需要导入模块: import pytest_mock [as 别名]
# 或者: from pytest_mock import mocker [as 别名]
def test_execute(mocker):
state_1 = GlobalState(None, None, MachineState(gas=10000000))
state_1.mstate.stack = [1, 2]
mocker.patch.object(state_1, 'get_current_instruction')
state_1.get_current_instruction.return_value = {"opcode": "PUSH"}
state_2 = GlobalState(None, None, MachineState(gas=10000000))
state_2.mstate.stack = [1, 2, 3]
mocker.patch.object(state_2, 'get_current_instruction')
state_2.get_current_instruction.return_value = {"opcode": "ADD"}
node_1 = Node("Test contract")
node_1.states = [state_1, state_2]
state_3 = GlobalState(None, None, MachineState(gas=10000000))
state_3.mstate.stack = [1, 2]
mocker.patch.object(state_3, 'get_current_instruction')
state_3.get_current_instruction.return_value = {"opcode": "ADD"}
node_2 = Node("Test contract")
node_2.states = [state_3]
edge = Edge(node_1.uid, node_2.uid)
statespace = LaserEVM(None)
statespace.edges = [edge]
statespace.nodes[node_1.uid] = node_1
statespace.nodes[node_2.uid] = node_2
# Act
result = TaintRunner.execute(statespace, node_1, state_1, [True, True])
# Assert
print(result)
assert len(result.records) == 3
assert result.records[2].states == []
assert state_3 in result.records[1].states
示例10: test_process_workspace_performance
# 需要导入模块: import pytest_mock [as 别名]
# 或者: from pytest_mock import mocker [as 别名]
def test_process_workspace_performance(mocker):
workspace = {
'WorkspaceId': 'ws-68h123hty',
'DirectoryId': 'd-901230bb84',
'UserName': 'test_user',
'IpAddress': '111.16.1.233',
'State': 'AVAILABLE',
'BundleId': 'wsb-cl123qzj1',
'SubnetId': 'subnet-05d421387eaa7cf86',
'ComputerName': 'A-APPW123KP4NP',
'WorkspaceProperties': {
'RunningMode': 'ALWAYS_ON',
'RootVolumeSizeGib': 80,
'UserVolumeSizeGib': 50,
'ComputeTypeName': 'PERFORMANCE'
},
'ModificationStates': []
}
settings = {
'region': 'us-east-1',
'hourlyLimits': 10,
'testEndOfMonth': 'yes',
'isDryRun': 'yes',
'startTime': 1,
'endTime': 2
}
workspace_helper = WorkspacesHelper(settings)
mocker.patch.object(workspace_helper.metricsHelper, 'get_billable_time')
workspace_helper.metricsHelper.get_billable_time.return_value = 100
mocker.patch.object(workspace_helper, 'check_for_skip_tag')
workspace_helper.check_for_skip_tag.return_value = False
mocker.patch.object(workspace_helper, 'get_hourly_threshold')
workspace_helper.get_hourly_threshold.return_value = 5
mocker.patch.object(workspace_helper, 'compare_usage_metrics')
workspace_helper.compare_usage_metrics.return_value = {
'resultCode': '-N-',
'newMode': 'ALWAYS_ON'
}
result = workspace_helper.process_workspace(workspace)
assert result['bundleType'] == 'PERFORMANCE'
assert result['billableTime'] == 100