本文整理汇总了Python中unittest.mock.MagicMock.getProperty方法的典型用法代码示例。如果您正苦于以下问题:Python MagicMock.getProperty方法的具体用法?Python MagicMock.getProperty怎么用?Python MagicMock.getProperty使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类unittest.mock.MagicMock
的用法示例。
在下文中一共展示了MagicMock.getProperty方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_settingIsOverwritingInheritance
# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import getProperty [as 别名]
def test_settingIsOverwritingInheritance(setting_inheritance_manager, mocked_stack):
mocked_container = MagicMock()
mocked_second_container = MagicMock()
mocked_second_container.getProperty = MagicMock(return_value = 12)
mocked_container.getProperty = MagicMock(side_effect=getPropertySideEffect)
mocked_stack.getContainers = MagicMock(return_value=[mocked_second_container, mocked_container])
setting_inheritance_manager._active_container_stack = mocked_stack
assert setting_inheritance_manager._settingIsOverwritingInheritance("setting_5", mocked_stack)
示例2: getPrintInformation
# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import getProperty [as 别名]
def getPrintInformation(printer_name) -> PrintInformation:
mock_application = MagicMock(name = "mock_application")
mocked_preferences = MagicMock(name="mocked_preferences")
mocked_extruder_stack = MagicMock()
mocked_extruder_stack.getProperty = MagicMock(return_value = 3)
mocked_material = MagicMock(name= "mocked material")
mocked_material.getMetaDataEntry = MagicMock(return_value = "omgzomg")
mocked_extruder_stack.material = mocked_material
mock_application.getInstance = MagicMock(return_value = mock_application)
mocked_preferences.getValue = MagicMock(return_value = '{"omgzomg": {"spool_weight": 10, "spool_cost": 9}}')
global_container_stack = MagicMock()
global_container_stack.extruders = {"0": mocked_extruder_stack}
global_container_stack.definition.getName = MagicMock(return_value = printer_name)
mock_application.getGlobalContainerStack = MagicMock(return_value = global_container_stack)
mock_application.getPreferences = MagicMock(return_value = mocked_preferences)
multi_build_plate_model = MagicMock()
multi_build_plate_model.maxBuildPlate = 0
mock_application.getMultiBuildPlateModel = MagicMock(return_value = multi_build_plate_model)
# Mock-up the entire machine manager except the function that needs to be tested: getAbbreviatedMachineName
original_get_abbreviated_name = MachineManager.getAbbreviatedMachineName
mock_machine_manager = MagicMock()
mock_machine_manager.getAbbreviatedMachineName = functools.partial(original_get_abbreviated_name, mock_machine_manager)
mock_application.getMachineManager = MagicMock(return_value = mock_machine_manager)
Application.getInstance = MagicMock(return_value = mock_application)
with patch("json.loads", lambda x: {}):
print_information = PrintInformation.PrintInformation(mock_application)
return print_information
示例3: test_settingIsOverwritingInheritanceSingleSettingFunction
# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import getProperty [as 别名]
def test_settingIsOverwritingInheritanceSingleSettingFunction(setting_inheritance_manager, mocked_stack):
mocked_container = MagicMock()
mocked_container.getProperty = MagicMock(side_effect=getPropertySideEffect)
mocked_stack.getContainers = MagicMock(return_value=[mocked_container])
setting_inheritance_manager._active_container_stack = mocked_stack
# Setting 5 does have a value, but we only have one container filled
assert not setting_inheritance_manager._settingIsOverwritingInheritance("setting_5", mocked_stack)
示例4: test_settingIsOverwritingInheritanceNoSettingFunction
# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import getProperty [as 别名]
def test_settingIsOverwritingInheritanceNoSettingFunction(setting_inheritance_manager, mocked_stack):
mocked_container = MagicMock()
mocked_container.getProperty = MagicMock(side_effect=getPropertySideEffect)
mocked_stack.getContainers = MagicMock(return_value=[mocked_container])
# Setting 4 does have a value, but it's not a settingFunction
assert not setting_inheritance_manager._settingIsOverwritingInheritance("setting_4", mocked_stack)
示例5: test_settingIsOverwritingInheritanceNoneValue
# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import getProperty [as 别名]
def test_settingIsOverwritingInheritanceNoneValue(setting_inheritance_manager, mocked_stack):
mocked_container = MagicMock()
mocked_container.getProperty = MagicMock(side_effect=getPropertySideEffect)
mocked_stack.getContainers = MagicMock(return_value = [mocked_container])
# Setting 3 doesn't have a value, so even though the container is there, it's value is None
assert not setting_inheritance_manager._settingIsOverwritingInheritance("setting_3", mocked_stack)
示例6: test_getHasErrors
# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import getProperty [as 别名]
def test_getHasErrors(container_stack):
definition_container = DefinitionContainer(str(uuid.uuid4()))
container_stack.addContainer(definition_container)
definition_container.getAllKeys = MagicMock(return_value = {"test_key"})
container = MagicMock()
container_stack.addContainer(container)
# We won't get any wrong validation states, so it shouldn't have errors.
assert not container_stack.hasErrors()
# Fake the property so it does return validation state
container.getProperty = MagicMock(return_value = ValidatorState.MaximumError)
assert container_stack.hasErrors() # Now the container stack has errors!
assert container_stack.getErrorKeys() == ["test_key"]
示例7: mocked_stack
# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import getProperty [as 别名]
def mocked_stack():
mocked_stack = MagicMock()
mocked_stack.getProperty = MagicMock(side_effect=getPropertySideEffect)
mocked_stack.getNextStack = MagicMock(return_value = None)
mocked_stack.getAllKeys = MagicMock(return_value = ["omg", "zomg", "blarg"])
return mocked_stack