本文整理汇总了Python中mock.Mock.location方法的典型用法代码示例。如果您正苦于以下问题:Python Mock.location方法的具体用法?Python Mock.location怎么用?Python Mock.location使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mock.Mock
的用法示例。
在下文中一共展示了Mock.location方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_linked_problem
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import location [as 别名]
def test_linked_problem(self):
"""
Check to see if a peer grading module with a linked problem loads properly.
"""
# Mock the linked problem descriptor.
linked_descriptor = Mock()
linked_descriptor.location = self.coe_location
# Mock the peer grading descriptor.
pg_descriptor = Mock()
pg_descriptor.location = self.problem_location
pg_descriptor.get_required_module_descriptors = lambda: [linked_descriptor, ]
# Setup the proper field data for the peer grading module.
field_data = DictFieldData({
'data': '<peergrading/>',
'location': self.problem_location,
'use_for_single_location': True,
'link_to_location': self.coe_location,
})
# Initialize the peer grading module.
peer_grading = PeerGradingModule(
pg_descriptor,
self.test_system,
field_data,
ScopeIds(None, None, self.problem_location, self.problem_location)
)
# Ensure that it is properly setup.
self.assertTrue(peer_grading.use_for_single_location)
示例2: _create_peer_grading_with_linked_problem
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import location [as 别名]
def _create_peer_grading_with_linked_problem(self, location, valid_linked_descriptor=True):
"""
Create a peer grading problem with a linked location.
"""
# Mock the linked problem descriptor.
linked_descriptor = Mock()
linked_descriptor.location = location
# Mock the peer grading descriptor.
pg_descriptor = Mock()
pg_descriptor.location = self.problem_location
if valid_linked_descriptor:
pg_descriptor.get_required_module_descriptors = lambda: [linked_descriptor, ]
else:
pg_descriptor.get_required_module_descriptors = lambda: []
test_system = self.get_module_system(pg_descriptor)
# Initialize the peer grading module.
peer_grading = PeerGradingModule(
pg_descriptor,
test_system,
self.field_data,
self.scope_ids,
)
return peer_grading
示例3: test_distance
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import location [as 别名]
def test_distance(self):
from warlord.path import distance
tileA = Mock()
tileB = Mock()
tileA.location = (0, 0)
tileB.location = (0, 1)
self.assertEquals(distance(tileA, tileB), 1)
示例4: create
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import location [as 别名]
def create(system, source_is_error_module=False):
"""
return a dict of modules: the conditional with a single source and a single child.
Keys are 'cond_module', 'source_module', and 'child_module'.
if the source_is_error_module flag is set, create a real ErrorModule for the source.
"""
descriptor_system = get_test_descriptor_system()
# construct source descriptor and module:
source_location = Location("edX", "conditional_test", "test_run", "problem", "SampleProblem", None)
if source_is_error_module:
# Make an error descriptor and module
source_descriptor = NonStaffErrorDescriptor.from_xml(
"some random xml data",
system,
id_generator=CourseLocationManager(source_location.course_key),
error_msg="random error message",
)
else:
source_descriptor = Mock(name="source_descriptor")
source_descriptor.location = source_location
source_descriptor.runtime = descriptor_system
source_descriptor.render = lambda view, context=None: descriptor_system.render(source_descriptor, view, context)
# construct other descriptors:
child_descriptor = Mock(name="child_descriptor")
child_descriptor._xmodule.student_view.return_value.content = u"<p>This is a secret</p>"
child_descriptor.student_view = child_descriptor._xmodule.student_view
child_descriptor.displayable_items.return_value = [child_descriptor]
child_descriptor.runtime = descriptor_system
child_descriptor.xmodule_runtime = get_test_system()
child_descriptor.render = lambda view, context=None: descriptor_system.render(child_descriptor, view, context)
child_descriptor.location = source_location.replace(category="html", name="child")
descriptor_system.load_item = {
child_descriptor.location: child_descriptor,
source_location: source_descriptor,
}.get
system.descriptor_runtime = descriptor_system
# construct conditional module:
cond_location = Location("edX", "conditional_test", "test_run", "conditional", "SampleConditional", None)
field_data = DictFieldData(
{"data": "<conditional/>", "xml_attributes": {"attempted": "true"}, "children": [child_descriptor.location]}
)
cond_descriptor = ConditionalDescriptor(
descriptor_system, field_data, ScopeIds(None, None, cond_location, cond_location)
)
cond_descriptor.xmodule_runtime = system
system.get_module = lambda desc: desc
cond_descriptor.get_required_module_descriptors = Mock(return_value=[source_descriptor])
# return dict:
return {"cond_module": cond_descriptor, "source_module": source_descriptor, "child_module": child_descriptor}
示例5: mock_descriptor
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import location [as 别名]
def mock_descriptor(fields=[], lms_fields=[]):
descriptor = Mock()
descriptor.stores_state = True
descriptor.location = location('def_id')
descriptor.module_class.fields = fields
descriptor.module_class.lms.fields = lms_fields
return descriptor
示例6: mock_descriptor
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import location [as 别名]
def mock_descriptor(fields=[]):
descriptor = Mock()
descriptor.location = location('def_id')
descriptor.module_class.fields.values.return_value = fields
descriptor.fields.values.return_value = fields
descriptor.module_class.__name__ = 'MockProblemModule'
return descriptor
示例7: mock_descriptor
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import location [as 别名]
def mock_descriptor(fields=[], lms_fields=[]):
descriptor = Mock()
descriptor.location = location('def_id')
descriptor.module_class.fields = fields
descriptor.module_class.lms.fields = lms_fields
descriptor.module_class.__name__ = 'MockProblemModule'
return descriptor
示例8: test_combat_raises_out_of_range_when_not_in_range
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import location [as 别名]
def test_combat_raises_out_of_range_when_not_in_range(self):
from warlord.combat import UnitOutOfRangeError, combat
unitA = Mock()
unitB = Mock()
weapon = Mock()
weapon.attack_range = [0]
unitA.equipped_item = weapon
tileA = Mock()
tileA.location = (0, 0)
tileA.unit = unitA
unitA.tile = tileA
tileB = Mock()
tileB.location = (0, 2)
tileB.unit = unitB
unitB.tile = tileB
self.assertRaises(UnitOutOfRangeError, combat, unitA, unitB)
示例9: create
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import location [as 别名]
def create(system, source_is_error_module=False):
"""
return a dict of modules: the conditional with a single source and a single child.
Keys are 'cond_module', 'source_module', and 'child_module'.
if the source_is_error_module flag is set, create a real ErrorModule for the source.
"""
descriptor_system = get_test_descriptor_system()
# construct source descriptor and module:
source_location = Location(["i4x", "edX", "conditional_test", "problem", "SampleProblem"])
if source_is_error_module:
# Make an error descriptor and module
source_descriptor = NonStaffErrorDescriptor.from_xml(
'some random xml data',
system,
org=source_location.org,
course=source_location.course,
error_msg='random error message'
)
else:
source_descriptor = Mock()
source_descriptor.location = source_location
source_descriptor.runtime = descriptor_system
source_descriptor.render = lambda view, context=None: descriptor_system.render(source_descriptor, view, context)
# construct other descriptors:
child_descriptor = Mock()
child_descriptor._xmodule.student_view.return_value.content = u'<p>This is a secret</p>'
child_descriptor.student_view = child_descriptor._xmodule.student_view
child_descriptor.displayable_items.return_value = [child_descriptor]
child_descriptor.runtime = descriptor_system
child_descriptor.xmodule_runtime = get_test_system()
child_descriptor.render = lambda view, context=None: descriptor_system.render(child_descriptor, view, context)
descriptor_system.load_item = {'child': child_descriptor, 'source': source_descriptor}.get
# construct conditional module:
cond_location = Location(["i4x", "edX", "conditional_test", "conditional", "SampleConditional"])
field_data = DictFieldData({
'data': '<conditional/>',
'xml_attributes': {'attempted': 'true'},
'children': ['child'],
})
cond_descriptor = ConditionalDescriptor(
descriptor_system,
field_data,
ScopeIds(None, None, cond_location, cond_location)
)
cond_descriptor.xmodule_runtime = system
system.get_module = lambda desc: desc
cond_descriptor.get_required_module_descriptors = Mock(return_value=[source_descriptor])
# return dict:
return {'cond_module': cond_descriptor,
'source_module': source_descriptor,
'child_module': child_descriptor}
示例10: test_scanned_columns_count_is_equal_to_config_column_count
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import location [as 别名]
def test_scanned_columns_count_is_equal_to_config_column_count(self):
symbols = []
symbol = Mock()
symbol.location = ((50, 50), (50, 60), (60, 60), (60, 50))
columns_count = 1
symbol.data = "[1,%d]" % (columns_count)
symbols.append(symbol)
self.assertRaises(IOError, mapper.Mapper, (symbols))
示例11: test_usingCopyAsParent
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import location [as 别名]
def test_usingCopyAsParent(self):
from niprov.commandline import Commandline
self.dependencies.config.verbosity = 'info'
cmd = Commandline(self.dependencies)
cmd.log = Mock()
copy = Mock()
copy.location = 'moon:/copy/location'
cmd.usingCopyAsParent(copy)
cmd.log.assert_called_with('warning',
'Used provenance from copy found at '+str(copy.location))
示例12: create
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import location [as 别名]
def create(system, source_is_error_module=False):
"""
return a dict of modules: the conditional with a single source and a single child.
Keys are 'cond_module', 'source_module', and 'child_module'.
if the source_is_error_module flag is set, create a real ErrorModule for the source.
"""
# construct source descriptor and module:
source_location = Location(["i4x", "edX", "conditional_test", "problem", "SampleProblem"])
if source_is_error_module:
# Make an error descriptor and module
source_descriptor = NonStaffErrorDescriptor.from_xml('some random xml data',
system,
org=source_location.org,
course=source_location.course,
error_msg='random error message')
source_module = source_descriptor.xmodule(system)
else:
source_descriptor = Mock()
source_descriptor.location = source_location
source_module = Mock()
# construct other descriptors:
child_descriptor = Mock()
cond_descriptor = Mock()
cond_descriptor.runtime = system
cond_descriptor.get_required_module_descriptors = lambda: [source_descriptor, ]
cond_descriptor.get_children = lambda: [child_descriptor, ]
cond_descriptor.xml_attributes = {"attempted": "true"}
# create child module:
child_module = Mock()
child_module.runtime = system
child_module.get_html.return_value = u'<p>This is a secret</p>'
child_module.student_view.return_value = Fragment(child_module.get_html.return_value)
child_module.displayable_items = lambda: [child_module]
module_map = {source_descriptor: source_module, child_descriptor: child_module}
system.get_module = lambda descriptor: module_map[descriptor]
# construct conditional module:
cond_location = Location(["i4x", "edX", "conditional_test", "conditional", "SampleConditional"])
field_data = DictFieldData({'data': '<conditional/>', 'location': cond_location})
cond_module = ConditionalModule(
cond_descriptor,
system,
field_data,
ScopeIds(None, None, cond_location, cond_location)
)
# return dict:
return {'cond_module': cond_module,
'source_module': source_module,
'child_module': child_module}
示例13: test_do_build_oserror
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import location [as 别名]
def test_do_build_oserror(self):
"""Test running of do_build"""
from unuo.docker import Docker_1_1_x
with patch.object(Docker_1_1_x, 'run_and_log') as run_and_log:
run_and_log.side_effect = OSError(1, 'oh no')
logmanager = Mock()
build = Mock()
build.repo = 'arepo'
build.dockertag = 'atag'
build.location = 'alocation'
docker = Docker_1_1_x(logmanager)
self.assertEquals('oh no', docker.do_build(build).next())
示例14: setUp
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import location [as 别名]
def setUp(self):
self.symbols = []
# columns
self.columns_count = -1
for i in range(0, 8, 1):
symbol = Mock()
symbol.location = ((0 + (7 - i) * 20, 0), ((7 - i) * 20, 10), (10 + (7 - i) * 20, 10), (10 + (7 - i) * 20, 0))
symbol.data = "__"
self.symbols.append(symbol)
self.columns_count += 1
# cards
self.cards_count = 0
for i in range(0, 7, 1):
symbol = Mock()
symbol.location = ((5 + i * 20, 5), (5 + i * 20, 15), (15 + i * 20, 15), (15 + i * 20, 5))
symbol.data = "T" + str(i) * 5
self.symbols.append(symbol)
self.cards_count += 1
# config symbol
symbol = Mock()
symbol.location = ((50, 50), (50, 60), (60, 60), (60, 50))
self.board_id = 1
symbol.data = "[%d,%d]" % (self.board_id, self.columns_count)
self.symbols.append(symbol)
示例15: _create_peer_grading_with_linked_problem
# 需要导入模块: from mock import Mock [as 别名]
# 或者: from mock.Mock import location [as 别名]
def _create_peer_grading_with_linked_problem(self, location, valid_linked_descriptor=True):
"""
Create a peer grading problem with a linked location.
"""
# Mock the linked problem descriptor.
linked_descriptor = Mock()
linked_descriptor.location = location
# Mock the peer grading descriptor.
pg_descriptor = Mock()
pg_descriptor.location = self.problem_location
if valid_linked_descriptor:
pg_descriptor.get_required_module_descriptors = lambda: [linked_descriptor, ]
else:
pg_descriptor.get_required_module_descriptors = lambda: []
# Setup the proper field data for the peer grading module.
field_data = DictFieldData({
'data': '<peergrading/>',
'location': self.problem_location,
'use_for_single_location': True,
'link_to_location': self.coe_location.url(),
'graded': True,
})
# Initialize the peer grading module.
peer_grading = PeerGradingModule(
pg_descriptor,
self.test_system,
field_data,
ScopeIds(None, None, self.problem_location, self.problem_location)
)
return peer_grading