本文整理汇总了Python中mocker.Mocker.replay方法的典型用法代码示例。如果您正苦于以下问题:Python Mocker.replay方法的具体用法?Python Mocker.replay怎么用?Python Mocker.replay使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mocker.Mocker
的用法示例。
在下文中一共展示了Mocker.replay方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_write
# 需要导入模块: from mocker import Mocker [as 别名]
# 或者: from mocker.Mocker import replay [as 别名]
def test_write(self):
mocker = Mocker()
db = mocker.mock()
insert_book ='''
insert into book (title, isbn, publisher, list_price,
publish_date, class, sheet_numbers, folio, print_type,
author, barcode, comments) values
('a', '1234', 'aph', '30', '2012', 'I.',
18, '4', 'mono', 'sb', 'a', 'blahblahblah')
'''
db.query(insert_book)
insert_tags = '''
'''
db.query(insert_tags)
db.commit()
mocker.replay()
writer = CatalogMySQLWriter(db)
item = CatalogItem(
'a', '1234', 'aph', '30', '2012', 'I.', 18, '4', 'mono', 'sb',
'a', 'blahblahblah', { 'audience': 'ms', 'awards': 'annual' })
writer.write(item)
mocker.restore()
mocker.verify()
示例2: test_required_field_missing
# 需要导入模块: from mocker import Mocker [as 别名]
# 或者: from mocker.Mocker import replay [as 别名]
def test_required_field_missing(self):
mocker = Mocker()
csv_reader = mocker.mock()
headers = [
'title', 'isbn', 'publisher', 'list_price', 'publish_date',
'class_', 'sheet_numbers', 'folio', 'print_type', 'author',
'barcode']
first_line = [
'a', '1234', 'aph', '30', '2012', 'I.', 18, '4', 'mono', 'sb', 'a']
field_map = {
'title': 0, 'isbn': 1, 'publisher': 2, 'list_price': 3,
'publish_date': 4, 'class_': 5, 'sheet_numbers': 6, 'folio': 7,
'print_type': 8, 'author': 9, 'barcode': 10, 'comments': 11 }
csv_reader.next() # read headers
mocker.result(headers)
csv_reader.next() # read first line
mocker.result(first_line)
mocker.replay()
reader = CatalogReader(csv_reader, field_map)
item = reader.read()
self.assertIsNone(item.comments)
mocker.restore()
mocker.verify()
示例3: test_result_is_cached
# 需要导入模块: from mocker import Mocker [as 别名]
# 或者: from mocker.Mocker import replay [as 别名]
def test_result_is_cached(self):
viewlet = self.get_viewlet()
viewlet.update()
self.assertNotIn('purple', viewlet.generate_css(),
'Unexpectedly found "purple" in the CSS')
# Setting a custom style automatically invalidates the cache.
# For testing that things are cached, we stub the cache invalidation,
# so that the cache persists.
mocker = Mocker()
invalidate_cache_mock = mocker.replace(invalidate_cache)
expect(invalidate_cache_mock()).count(1, None)
mocker.replay()
ICustomStyles(self.layer['portal']).set('css.body-background', 'purple')
self.assertNotIn('purple', viewlet.generate_css(),
'The result was not cached.')
# Removing the stub and invalidating the cache should update the result.
mocker.restore()
mocker.verify()
invalidate_cache()
self.assertIn('purple', viewlet.generate_css(),
'Expected "purple" in CSS - does the style'
' css.body-background no longer work?')
示例4: test_read_tags
# 需要导入模块: from mocker import Mocker [as 别名]
# 或者: from mocker.Mocker import replay [as 别名]
def test_read_tags(self):
mocker = Mocker()
csv_reader = mocker.mock()
headers = [
'title', 'isbn', 'publisher', 'list_price', 'publish_date',
'class_', 'sheet_numbers', 'folio', 'print_type', 'author',
'barcode', 'comments', 'audience', 'awards']
first_line = [
'a', '1234', 'aph', '30', '2012', 'I.', 18, '4', 'mono', 'sb', 'a',
'blahblahblah', 'ms', 'annual']
field_map = {'title': 0, 'isbn': 1, 'publisher': 2, 'list_price': 3,
'publish_date': 4, 'class_': 5, 'sheet_numbers': 6, 'folio': 7,
'print_type': 8, 'author': 9, 'barcode': 10, 'comments': 11 }
csv_reader.next() # read headers
mocker.result(headers)
csv_reader.next() # read first line
mocker.result(first_line)
mocker.replay()
reader = CatalogReader(csv_reader, field_map)
item = reader.read()
self.assertIsInstance(item, CatalogItem)
self.assertEquals(2, len(item.tags))
self.assertEquals('ms', item.tags['audience'])
self.assertEquals('annual', item.tags['awards'])
mocker.restore()
mocker.verify()
示例5: setUpZope
# 需要导入模块: from mocker import Mocker [as 别名]
# 或者: from mocker.Mocker import replay [as 别名]
def setUpZope(self, app, configurationContext):
# Mock postmonkey
mocker = Mocker()
postmonkey = mocker.replace("postmonkey")
mailchimp = postmonkey.PostMonkey(ANY)
mocker.count(0, 1000)
# Lists
mailchimp.lists()
mocker.count(0, 1000)
mocker.result({
u'total': 2,
u'data': [{
u'id': 625,
u'web_id': 625,
u'name': u'ACME Newsletter',
u'default_from_name': u'[email protected]',
},
{
u'id': 626,
u'web_id': 626,
u'name': u'ACME Newsletter 2',
u'default_from_name': u'[email protected]',
},
]})
mocker.replay()
# Load ZCML
import example.tdd
xmlconfig.file(
'configure.zcml',
example.tdd,
context=configurationContext
)
示例6: test_offset
# 需要导入模块: from mocker import Mocker [as 别名]
# 或者: from mocker.Mocker import replay [as 别名]
def test_offset(self):
"""
Test that, if the server's BEGIN_CONTENT message specifies an offset,
the file to be uploaded is seek'ed to the right position.
"""
offset = 23
mocker = Mocker()
transport = mocker.mock()
transport.registerProducer(ANY, streaming=True)
transport.write(ANY)
mocker.count(1, None) # I don't really care how many times
fd = mocker.mock()
fd.seek(offset) # this is really all I care about
fd.read(ANY)
mocker.result('')
mocker.replay()
protocol = StorageClient()
protocol.transport = transport
pc = PutContent(protocol, 'share', 'node', '', '', 0, 0, 0, fd)
message = protocol_pb2.Message()
message.type = protocol_pb2.Message.BEGIN_CONTENT
message.begin_content.offset = offset
pc.start()
pc.processMessage(message)
示例7: test_read_basic_fields
# 需要导入模块: from mocker import Mocker [as 别名]
# 或者: from mocker.Mocker import replay [as 别名]
def test_read_basic_fields(self):
mocker = Mocker()
csv_reader = mocker.mock()
csv_reader.next()
header_line = [
'title', 'isbn', 'publisher', 'list_price', 'publish_date',
'class_', 'sheet_numbers', 'folio', 'print_type', 'author',
'barcode', 'comments']
mocker.result(header_line)
csv_reader.next()
first_line = [
'a', '1234', 'aph', '30', '2012', 'I.', 18, '4', 'mono', 'sb', 'a',
'blahblahblah' ]
mocker.result(first_line)
mocker.replay()
field_map = {'title': 0, 'isbn': 1, 'publisher': 2, 'list_price': 3,
'publish_date': 4, 'class_': 5, 'sheet_numbers': 6, 'folio': 7,
'print_type': 8, 'author': 9, 'barcode': 10, 'comments': 11 }
reader = CatalogReader(csv_reader, field_map)
item = reader.read()
self.assertIsInstance(item, CatalogItem)
mocker.restore()
mocker.verify()
示例8: test_historylogs_without_filters
# 需要导入模块: from mocker import Mocker [as 别名]
# 或者: from mocker.Mocker import replay [as 别名]
def test_historylogs_without_filters(self):
for document_type in ['article', 'journal']:
historylogs = json.loads(
open(os.path.dirname(__file__) +
'/fixtures/historylogs_%s.json' % document_type).read()
)
mocker = Mocker()
databroker = mocker.mock()
databroker['historychanges_%s' % document_type].find(ANY).count()
mocker.result(historylogs['meta']['total'])
databroker['historychanges_%s' % document_type].find(ANY).skip(ANY).limit(ANY).sort("date")
mocker.result(historylogs['objects'])
mocker.replay()
db = DataBroker(databroker)
result = db.historychanges(document_type)
# assert date filters are correct in meta
self.assertIn('meta', result.keys())
self.assertIn('filter', result['meta'].keys())
self.assertIn('date', result['meta']['filter'].keys())
self.assertEqual(['$lte', '$gt'], result['meta']['filter']['date'].keys())
self.assertEqual(
historylogs['meta']['total'],
result['meta']['total']
)
self.assertIn('objects', result.keys())
self.assertEqual(historylogs['objects'], result['objects'])
self.assertEqual(
result['objects'][0].keys(),
['date', 'code', 'event', 'collection']
)
示例9: test_log_changes_with_valid_params
# 需要导入模块: from mocker import Mocker [as 别名]
# 或者: from mocker.Mocker import replay [as 别名]
def test_log_changes_with_valid_params(self):
mocker = Mocker()
databroker = mocker.mock()
document_types = ['article', 'journal']
events = ['add', 'update', 'delete']
# db "insert" must be called len(document_types) * len(events) times
for document_type in document_types:
for event in events:
databroker['historychanges_%s' % document_type].insert(ANY)
mocker.result(123457890)
mocker.replay()
db = DataBroker(databroker)
for document_type in document_types:
for event in events:
log_data = {
'document_type': document_type,
'code': '123',
'collection': 'test_collection',
'event': event,
'date': datetime.now().isoformat(),
}
log_id = db._log_changes(**log_data)
self.assertEqual(log_id, 123457890)
示例10: test_find_match_matched
# 需要导入模块: from mocker import Mocker [as 别名]
# 或者: from mocker.Mocker import replay [as 别名]
def test_find_match_matched(self):
key = "chr1:154000-230000"
mocker = Mocker()
junction = mocker.mock()
junction.coverage
mocker.result(40)
mocker.count(1, None)
container = mocker.mock()
container.keys()
mocker.result([key])
container[key]
mocker.result(junction)
mocker.count(1, None)
mocker.replay()
self.common, self.diff = jc.findMatch(container, container)
self.assertEqual(self.common.keys(), ["chr1:154000-230000"])
self.assertEqual(self.diff.keys(), [])
mocker.restore()
mocker.verify()
示例11: test_find_match_not_matched
# 需要导入模块: from mocker import Mocker [as 别名]
# 或者: from mocker.Mocker import replay [as 别名]
def test_find_match_not_matched(self):
key1 = "chr1:154000-230000"
mocker = Mocker()
junction = mocker.mock()
junction.coverage
mocker.result(40)
container1 = mocker.mock()
container2 = mocker.mock()
container1.keys()
mocker.result([key1])
container1[key1]
mocker.result(junction)
container2[key1]
mocker.throw(KeyError)
mocker.count(1)
mocker.replay()
self.common, self.diff = jc.findMatch(container1, container2)
self.assertEqual(self.common.keys(), [])
self.assertEqual(self.diff.keys(), [key1])
mocker.restore()
mocker.verify()
示例12: test_without_when
# 需要导入模块: from mocker import Mocker [as 别名]
# 或者: from mocker.Mocker import replay [as 别名]
def test_without_when(self):
mocker = Mocker()
mock_time = mocker.replace('time.time')
mock_time()
mocker.result(1.0)
mock_time()
mocker.result(2.0)
mock_time()
mocker.result(3.0)
mock_time()
mocker.result(4.0)
mock_time()
mocker.result(5.0)
mocker.replay()
controller = pid.PID(P = 0.5, I = 0.5, D = 0.5,
setpoint = 0, initial = 12)
self.assertEqual(controller.calculate_response(6), -3)
self.assertEqual(controller.calculate_response(3), -4.5)
self.assertEqual(controller.calculate_response(-1.5), -0.75)
self.assertEqual(controller.calculate_response(-2.25), -1.125)
mocker.restore()
mocker.verify()
示例13: test_str
# 需要导入模块: from mocker import Mocker [as 别名]
# 或者: from mocker.Mocker import replay [as 别名]
def test_str(self):
mocker = Mocker()
junc = mocker.mock()
junc.getCoord()
mocker.result("chr1:154000-230000")
junc.name
mocker.result("JUNC00001")
mocker.replay()
self.assertEqual(jc.Junction.__str__.im_func(junc), "chr1:154000-230000, JUNC00001")
示例14: test_default_variant_label_empty
# 需要导入模块: from mocker import Mocker [as 别名]
# 或者: from mocker.Mocker import replay [as 别名]
def test_default_variant_label_empty(self):
mocker = Mocker()
data = mocker.mock()
data.context.objectValues()
mocker.result(())
mocker.replay()
self.assertEquals(shopitem.default_variant_label(data), '')
示例15: test_is_up_shold_return_true_when_instance_is_running_and_db_is_up
# 需要导入模块: from mocker import Mocker [as 别名]
# 或者: from mocker.Mocker import replay [as 别名]
def test_is_up_shold_return_true_when_instance_is_running_and_db_is_up(self):
mocker = Mocker()
obj = mocker.replace("mysqlapi.api.models.DatabaseManager.is_up")
obj()
mocker.result(True)
mocker.replay()
instance = Instance(name="foo", state="running")
manager = DatabaseManager("foo", "127.0.0.1")
self.assertTrue(instance.is_up(manager))