本文整理汇总了Python中unittest.mock.MagicMock.type方法的典型用法代码示例。如果您正苦于以下问题:Python MagicMock.type方法的具体用法?Python MagicMock.type怎么用?Python MagicMock.type使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类unittest.mock.MagicMock
的用法示例。
在下文中一共展示了MagicMock.type方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_objections_with_parents_without_objections
# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import type [as 别名]
def test_objections_with_parents_without_objections(self):
premise = Premise(1)
rel1 = MagicMock()
rel2 = MagicMock()
rel1.type = RelationType.support
rel2.type = RelationType.situation
premise.relations = [rel1, rel2]
self.assertEqual(premise.objects(), [])
示例2: test_objections_with_parents
# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import type [as 别名]
def test_objections_with_parents(self):
premise = Premise(1)
rel = MagicMock()
rel.type = RelationType.objection
premise.relations = [rel]
self.assertEqual(len(premise.objects()), 1)
示例3: add_change
# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import type [as 别名]
def add_change(op, dns_name, rtype, ttl, identifier, weight):
if op == 'CREATE':
x = MagicMock(weight=weight, identifier=identifier)
x.name = "myapp.example.org."
x.type = "CNAME"
records[identifier] = x
return MagicMock(name='change')
示例4: _create_warder_trees
# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import type [as 别名]
def _create_warder_trees(self, tuples):
for t in tuples:
obj = MagicMock()
obj.name = t[0]
obj.type = "Warder"
obj.max_points = t[1]
yield obj
示例5: test_generate_css_selector_prefix_is_prepended
# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import type [as 别名]
def test_generate_css_selector_prefix_is_prepended(self):
tree1 = MagicMock()
tree1.aa = [self._create_aa(0)]
tree1.type = "Archetype"
result = self.sut.generate_css([tree1], self._icon_size, self._padding, 'Prefix')
lines = result.split(os.linesep)
self.assertEqual(lines[0], "Prefix.Archetype .aa.id0 .icon { background-position: -1px -1px; }")
示例6: init_contributors
# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import type [as 别名]
def init_contributors(self):
contributor = MagicMock()
contributor.login = "Aziz"
contributor.id = 2
contributor.avatar_url = "https://github.com/images/Aziz"
contributor.html_url = "Aziz.com"
contributor.type = "User"
contributor.contributions = 150
return [contributor]
示例7: test_generate_css_two_trees
# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import type [as 别名]
def test_generate_css_two_trees(self):
tree1 = MagicMock()
tree1.aa = [self._create_aa(0), self._create_aa(1), self._create_aa(2)]
tree1.type = "Archetype"
tree2 = MagicMock()
tree2.aa = [self._create_aa(0), self._create_aa(1), self._create_aa(2)]
tree2.type = "Shadows"
result = self.sut.generate_css([tree1, tree2], self._icon_size, self._padding)
lines = result.split(os.linesep)
self.assertEqual(lines[0], ".Archetype .aa.id0 .icon { background-position: -1px -1px; }")
self.assertEqual(lines[1], ".Archetype .aa.id1 .icon { background-position: -13px -1px; }")
self.assertEqual(lines[2], ".Archetype .aa.id2 .icon { background-position: -25px -1px; }")
self.assertEqual(lines[3], ".Shadows .aa.id0 .icon { background-position: -1px -13px; }")
self.assertEqual(lines[4], ".Shadows .aa.id1 .icon { background-position: -13px -13px; }")
self.assertEqual(lines[5], ".Shadows .aa.id2 .icon { background-position: -25px -13px; }")
示例8: fake_event
# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import type [as 别名]
def fake_event(keyval, event_type=Gdk.EventType.KEY_PRESS, ctrl=False):
if isinstance(keyval, str):
keyval = ord(keyval)
ev = MagicMock()
ev.type = event_type
ev.keyval = keyval
if ctrl:
ev.state = Gdk.ModifierType.CONTROL_MASK
else:
ev.state = 0
return ev
示例9: test_draw
# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import type [as 别名]
def test_draw(self):
graph = Graph()
arg1 = MagicMock()
arg1.id = "arg1"
arg2 = MagicMock()
arg2.id = "arg2"
arg3 = MagicMock()
arg3.id = "arg3"
graph.add_arguments(arg1, arg2, arg3)
rel1 = MagicMock()
rel1.relfrom = arg1
rel1.relto = arg2
rel1.type = RelationType.support
rel2 = MagicMock()
rel2.relfrom = arg1
rel2.relto = arg3
rel2.type = RelationType.objection
graph.add_relations(rel1, rel2)
graph.draw('png', 'test')
示例10: test_generate_css_warder_tree_has_additional_selector
# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import type [as 别名]
def test_generate_css_warder_tree_has_additional_selector(self):
tree1 = MagicMock()
tree1.aa = [self._create_aa(0), self._create_aa(1), self._create_aa(2)]
tree1.type = "Warder"
tree1.name = 'War Boar'
result = self.sut.generate_css([tree1], self._icon_size, self._padding)
lines = result.split(os.linesep)
self.assertEqual(lines[0], ".Warder.WarBoar .aa.id0 .icon { background-position: -1px -1px; }")
self.assertEqual(lines[1], ".Warder.WarBoar .aa.id1 .icon { background-position: -13px -1px; }")
self.assertEqual(lines[2], ".Warder.WarBoar .aa.id2 .icon { background-position: -25px -1px; }")
示例11: init_user
# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import type [as 别名]
def init_user(self):
user = MagicMock()
user.login = "login"
user.id = 5
user.avatar_url = " avatar_url"
user.gravatar_id = 9
user.url = "user_url"
user.html_url = "html_url"
user.followers_url = " followers_url"
user.gists_url = "gists_url"
user.starred_url = "starred_url"
user.subscriptions_url = "subscriptions_url"
user.organizations_url = "organizations_url"
user.repos_url = "repos_url"
user.events_url = "events_url"
user.received_events_url = "received_events_url "
user.type = "user"
return user
示例12: _generate_mock_feed_entry
# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import type [as 别名]
def _generate_mock_feed_entry(external_id, title, distance_to_home,
coordinates, place=None,
attribution=None, time=None, updated=None,
magnitude=None, status=None,
entry_type=None, alert=None):
"""Construct a mock feed entry for testing purposes."""
feed_entry = MagicMock()
feed_entry.external_id = external_id
feed_entry.title = title
feed_entry.distance_to_home = distance_to_home
feed_entry.coordinates = coordinates
feed_entry.place = place
feed_entry.attribution = attribution
feed_entry.time = time
feed_entry.updated = updated
feed_entry.magnitude = magnitude
feed_entry.status = status
feed_entry.type = entry_type
feed_entry.alert = alert
return feed_entry
示例13: test_get_versions
# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import type [as 别名]
def test_get_versions(monkeypatch):
record = MagicMock()
record.type = 'CNAME'
record.identifier = 'app-myapp'
record.weight = 100
zone = MagicMock(name='zone')
zone.get_records.return_value = [record]
dns_conn = MagicMock(name='dns_conn')
dns_conn.get_zone.return_value = zone
group = MagicMock(name='auto scale group')
group.name = 'app-myapp-1.0'
autoscale = MagicMock(name='autoscale_conn')
autoscale.get_all_groups.return_value = [group]
monkeypatch.setattr('boto.ec2.autoscale.connect_to_region', MagicMock(return_value=autoscale))
monkeypatch.setattr('boto.route53.connect_to_region', MagicMock(return_value=dns_conn))
ctx = Context({'region': 'someregion', 'domain': 'apps.example.com'})
versions = ctx.get_versions('myapp', '0.1')
assert versions == []
versions = ctx.get_versions('myapp', '1.0')
assert len(versions) == 1
assert versions[0].application_name == 'myapp'
assert versions[0].version == '1.0'
version = ctx.get_version('myapp', '1.0')
assert version == versions[0]
with pytest.raises(Exception):
ctx.get_version('non-existing-app', '0.1')
示例14: test_send_notifications_using_services_method
# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import type [as 别名]
def test_send_notifications_using_services_method(settings, mail):
settings.CHANGE_NOTIFICATIONS_MIN_INTERVAL = 1
project = f.ProjectFactory.create()
role = f.RoleFactory.create(project=project, permissions=['view_issues', 'view_us', 'view_tasks', 'view_wiki_pages'])
member1 = f.MembershipFactory.create(project=project, role=role)
member2 = f.MembershipFactory.create(project=project, role=role)
history_change = MagicMock()
history_change.user = {"pk": member1.user.pk}
history_change.comment = ""
history_change.type = HistoryType.change
history_change.is_hidden = False
history_create = MagicMock()
history_create.user = {"pk": member1.user.pk}
history_create.comment = ""
history_create.type = HistoryType.create
history_create.is_hidden = False
history_delete = MagicMock()
history_delete.user = {"pk": member1.user.pk}
history_delete.comment = ""
history_delete.type = HistoryType.delete
history_delete.is_hidden = False
# Issues
issue = f.IssueFactory.create(project=project, owner=member2.user)
take_snapshot(issue)
services.send_notifications(issue,
history=history_create)
services.send_notifications(issue,
history=history_change)
services.send_notifications(issue,
history=history_delete)
# Userstories
us = f.UserStoryFactory.create(project=project, owner=member2.user)
take_snapshot(us)
services.send_notifications(us,
history=history_create)
services.send_notifications(us,
history=history_change)
services.send_notifications(us,
history=history_delete)
# Tasks
task = f.TaskFactory.create(project=project, owner=member2.user)
take_snapshot(task)
services.send_notifications(task,
history=history_create)
services.send_notifications(task,
history=history_change)
services.send_notifications(task,
history=history_delete)
# Wiki pages
wiki = f.WikiPageFactory.create(project=project, owner=member2.user)
take_snapshot(wiki)
services.send_notifications(wiki,
history=history_create)
services.send_notifications(wiki,
history=history_change)
services.send_notifications(wiki,
history=history_delete)
assert models.HistoryChangeNotification.objects.count() == 12
assert len(mail.outbox) == 0
time.sleep(1)
services.process_sync_notifications()
assert len(mail.outbox) == 12
示例15: test_send_notifications_using_services_method
# 需要导入模块: from unittest.mock import MagicMock [as 别名]
# 或者: from unittest.mock.MagicMock import type [as 别名]
def test_send_notifications_using_services_method(mail):
project = f.ProjectFactory.create()
member1 = f.MembershipFactory.create(project=project)
member2 = f.MembershipFactory.create(project=project)
history_change = MagicMock()
history_change.owner = member1.user
history_change.comment = ""
history_change.type = HistoryType.change
history_create = MagicMock()
history_create.owner = member1.user
history_create.comment = ""
history_create.type = HistoryType.create
history_delete = MagicMock()
history_delete.owner = member1.user
history_delete.comment = ""
history_delete.type = HistoryType.delete
# Issues
issue = f.IssueFactory.create(project=project)
services.send_notifications(issue,
history=history_create,
users={member1.user, member2.user})
services.send_notifications(issue,
history=history_change,
users={member1.user, member2.user})
services.send_notifications(issue,
history=history_delete,
users={member1.user, member2.user})
# Userstories
us = f.UserStoryFactory.create()
services.send_notifications(us,
history=history_create,
users={member1.user, member2.user})
services.send_notifications(us,
history=history_change,
users={member1.user, member2.user})
services.send_notifications(us,
history=history_delete,
users={member1.user, member2.user})
# Tasks
task = f.TaskFactory.create()
services.send_notifications(task,
history=history_create,
users={member1.user, member2.user})
services.send_notifications(task,
history=history_change,
users={member1.user, member2.user})
services.send_notifications(task,
history=history_delete,
users={member1.user, member2.user})
# Wiki pages
wiki = f.WikiPageFactory.create()
services.send_notifications(wiki,
history=history_create,
users={member1.user, member2.user})
services.send_notifications(wiki,
history=history_change,
users={member1.user, member2.user})
services.send_notifications(wiki,
history=history_delete,
users={member1.user, member2.user})
assert len(mail.outbox) == 24