本文整理汇总了Python中unittest.mock.Mock.id方法的典型用法代码示例。如果您正苦于以下问题:Python Mock.id方法的具体用法?Python Mock.id怎么用?Python Mock.id使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类unittest.mock.Mock
的用法示例。
在下文中一共展示了Mock.id方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_data
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import id [as 别名]
def test_data(self):
# Setup
effect1 = Mock()
effect1.id = 22
effect1.fitting_usage_chance_attribute = 2
effect2 = Mock()
effect2.id = 555
effect2.fitting_usage_chance_attribute = 55
effect3 = Mock()
effect3.id = 999
effect3.fitting_usage_chance_attribute = None
self.mixin.set_side_effect_status(555, False)
self.mixin.item.effects = (effect1, effect2, effect3)
self.mixin.attributes = {2: 0.5, 55: 0.1}
# Verification
side_effects = self.mixin.side_effects
self.assertEqual(len(side_effects), 2)
self.assertIn(22, side_effects)
side_effect1 = side_effects[22]
self.assertEqual(side_effect1.effect, effect1)
self.assertEqual(side_effect1.chance, 0.5)
self.assertEqual(side_effect1.status, True)
self.assertIn(555, side_effects)
side_effect2 = side_effects[555]
self.assertEqual(side_effect2.effect, effect2)
self.assertEqual(side_effect2.chance, 0.1)
self.assertEqual(side_effect2.status, False)
示例2: test_check_tag_checked
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import id [as 别名]
def test_check_tag_checked(self):
mock = Mock()
mock.id = 56
mock_2 = Mock()
mock_2.id = 15
out = Template(
"{% load check %}"
"{{ offers_on|is_checked:pgm_id }}"
).render(Context({
'offers_on': [mock, mock_2],
'pgm_id': 15
}))
self.assertEqual(out, "checked")
示例3: test_atoms_with_pagination_request
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import id [as 别名]
def test_atoms_with_pagination_request(
self,
offset: Optional[int],
limit: Optional[int],
expected_first_atom_id: int,
expected_last_atom_id: int,
):
# Create 20 mock atoms with ids 1 to 20
atoms = []
for atom_id in range(1, self._NUM_ATOMS + 1):
atom_mock = Mock(spec=Atom)
atom_mock.id = atom_id
atoms.append(atom_mock)
build_id = 1
subjob_id = 1
project_type = None
job_config = None
subjob_atoms = atoms
subjob = Subjob(build_id, subjob_id, project_type, job_config, atoms)
requested_atoms = subjob.get_atoms(offset, limit)
id_of_first_atom = requested_atoms[0].id if len(requested_atoms) else None
id_of_last_atom = requested_atoms[-1].id if len(requested_atoms) else None
num_atoms = len(requested_atoms)
self.assertEqual(id_of_first_atom, expected_first_atom_id, 'Received the wrong first atom from request')
self.assertEqual(id_of_last_atom, expected_last_atom_id, 'Received the wrong last atom from request')
if offset is not None and limit is not None:
self.assertLessEqual(num_atoms, self._PAGINATION_MAX_LIMIT, 'Received too many atoms from request')
示例4: test_find_rlinks
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import id [as 别名]
def test_find_rlinks(self):
"""Verify an item's reverse links can be found."""
mock_document_p = Mock()
mock_document_p.prefix = 'RQ'
mock_document_c = Mock()
mock_document_c.parent = 'RQ'
mock_item = Mock()
mock_item.id = 'TST001'
mock_item.links = ['RQ001']
def mock_iter(self): # pylint: disable=W0613
"""Mock Tree.__iter__ to yield a mock Document."""
def mock_iter2(self): # pylint: disable=W0613
"""Mock Document.__iter__ to yield a mock Item."""
yield mock_item
mock_document_c.__iter__ = mock_iter2
yield mock_document_c
self.item.add_link('fake1')
mock_tree = Mock()
mock_tree.__iter__ = mock_iter
mock_tree.find_item = lambda identifier: Mock(id='fake1')
rlinks, childrem = self.item.find_rlinks(mock_document_p, mock_tree)
self.assertEqual(['TST001'], rlinks)
self.assertEqual([mock_document_c], childrem)
示例5: should_claim_a_task
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import id [as 别名]
def should_claim_a_task(self, mock_post):
mock_user = Mock()
mock_user.id = "userId"
task = self.get_task()
self.task_service.claim(task, mock_user)
dict_post = {"action": "claim", "assignee": "userId"}
mock_post.assert_called_with(dict_post, "tasks", task.id)
示例6: should_add_comment
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import id [as 别名]
def should_add_comment(self, mock_post):
task = Mock()
task.id = "8"
dict_comment = {"message": "This is a comment on the task.",
"saveProcessInstanceId": True}
self.task_service.add_comment(task, "This is a comment on the task.")
mock_post.assert_called_with(dict_comment, "tasks", task.id,
"comments")
示例7: generate_mock_status
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import id [as 别名]
def generate_mock_status(id=None, text=None, created_at=None, user=None):
status = Mock(spec=classes.Status)
status.id = id
status.text = text if text else "The text for mock status {0}".format(status.id)
status.created_at = created_at if created_at else datetime.utcnow()
if user is None:
user = generate_mock_user()
status.author = user
status.in_reply_to_status_id = None
return status
示例8: buffer_add_reset
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import id [as 别名]
def buffer_add_reset(self):
"""
Add a reset instruction to Redis' download list (through a pipeline which is a buffer).
"""
entry = Mock()
entry.__all__ = AbstractDropboxEntry.__all__
epoch = datetime.datetime.utcfromtimestamp(0)
now = datetime.datetime.now()
entry.id = '{}'.format((now - epoch).total_seconds()) # Seconds.milliseconds from epoch.
entry.remote_path = 'RESET'
entry.local_name = 'RESET'
entry.operation = 'X'
self.buffer(entry)
示例9: test_form_save_item
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import id [as 别名]
def test_form_save_item(self):
sheet = Mock(spec=TxSheet)
sheet._state = Mock()
sheet._state.db = None
sheet.id = 1
Prescription.objects.create(name='Drugahol')
form = TxItemForm(data={
'med': 1,
'dose': 5,
'freq': 'BID',
'unit': 'T'
})
form.is_valid()
sheet = form.save(sheet=sheet)
self.assertIsInstance(sheet, TxItem)
示例10: test_add_and_get_trigger_with_update_run_time
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import id [as 别名]
def test_add_and_get_trigger_with_update_run_time(self):
next_run_time = datetime(year=2010, month=1, day=1, tzinfo=utc)
expected_next_run_time = int(next_run_time.timestamp())
self.lights.add_trigger(True, 10, 20)
job_id = self.lights._scheduler.get_jobs()[0].id
job = Mock()
job.id = job_id
job.next_run_time = next_run_time
self.lights._scheduler.get_jobs = MagicMock(return_value=[job])
triggers = self.lights.get_triggers()
assert_that(triggers, has_length(1))
trigger = triggers[0]
assert_that(trigger.next_run_time, is_(expected_next_run_time))
示例11: generate_mock_timeline_data
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import id [as 别名]
def generate_mock_timeline_data(naive_dt=True, datetime_fixtures=None):
"""
A list of statuses. May be set to have a utc timezone with a ``False``
value for the ``naive_dt`` argument.
"""
mock_data = dict()
if datetime_fixtures is None:
datetime_fixtures, latest = generate_datetime_fixtures()
for dt in datetime_fixtures:
status = Mock(spec=classes.Status)
status.id = len(mock_data) + 1
status.text = "The text for mock status {0}".format(status.id)
status.created_at = dt
status.author = generate_mock_user()
status.in_reply_to_status_id = None
mock_data[str(status.id)] = status
return mock_data
示例12: _compile_quali_ai
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import id [as 别名]
def _compile_quali_ai(gt):
ai = Mock()
ai.id = -gt.id
lang = next(filter(None, [
Lang.query.filter(Lang.name == "Go").first(),
Lang.query.filter(Lang.name == "Python").first(),
Lang.query.filter(Lang.name == "Java").first(),
Lang.query.first()
]))
ai.lang = lang
ai.type = gt
ai.name = "QualiKi-"+gt.name
v = ai.latest_version()
v.version_id = 1
v.lang = ai.lang
v.qualified, v.compiled, v.frozen = False, False, False
v.extras.return_value = []
ai.version_list = [v]
ai.ftp_sync = lambda: AI.ftp_sync(ai)
ai.copy_example_code = lambda: AI.copy_example_code(ai)
ai.copy_example_code()
for data, event in backend.compile(ai):
print(event, ":", data)
示例13: Mock
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import id [as 别名]
# -*- coding: utf-8 -*-
try:
from unittest.mock import Mock
except ImportError:
from mock import Mock # pragma: no cover
from crabpy.gateway.exception import GatewayRuntimeException
import colander
from pyramid import testing
import unittest
from oe_geoutils.validation.validators_address import CrabAdresSchemaNode
# Knokke-Heist
pk_8300_mock = Mock()
pk_8300_mock.id = 8300
pk_8301_mock = Mock()
pk_8301_mock.id = 8301
ns_num_6_sub_mock = Mock()
ns_num_6_sub_mock.id = 1441952
ns_num_6_sub_mock.huisnummer_id = 270059
ns_num_6_sub_mock.subadres = "1"
ns_num_69_sub_mock = Mock()
ns_num_69_sub_mock.id = 1442188
ns_num_69_sub_mock.huisnummer_id = 882821
ns_num_69_sub_mock.subadres = "11"
ns_num_6_mock = Mock()
ns_num_6_mock.id = 270059
示例14: Mock
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import id [as 别名]
from app.enums import PimpyTaskStatus
from app.exceptions.base import ValidationException, ResourceNotFoundException
from app.exceptions.pimpy import InvalidMinuteException
from app.models.group import Group
from app.models.pimpy import Task
from app.models.user import User
from app.repository import pimpy_repository, group_repository
from app.service import pimpy_service, group_service
pimpy_repository_mock = Mock(pimpy_repository)
group_repository_mock = Mock(group_repository)
pimpy_service_add_task_mock = Mock(pimpy_service._add_task)
task_mock = Mock(Task)
abc_task_mock = Mock(Task)
abc_task_mock.id = 10604
def_task_mock = Mock(Task)
def_task_mock.id = 13775
group_mock = Mock(Group)
group_mock.id = 20
foo_user_mock = Mock(User)
foo_user_mock.configure_mock(first_name='Foo', last_name='Oof', name='Foo Oof')
bar_user_mock = Mock(User)
bar_user_mock.configure_mock(first_name='Bar', last_name='Rab', name='Bar Rab')
existing_minute_id = 45
existing_task_id = 10604 # ABC
existing_task_id2 = 13775 # DEF
existing_group_id = 20
示例15: generate_mock_user
# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import id [as 别名]
def generate_mock_user():
user = Mock(spec=classes.User)
user.id = 1
user.screen_name = 'test_author'
user.profile_image_url = "http:\/\/a1.twimg.com\/profile_images\/101\/avatar_normal.png"
return user