本文整理汇总了Python中meresco.components.sru.SruHandler._timeNow方法的典型用法代码示例。如果您正苦于以下问题:Python SruHandler._timeNow方法的具体用法?Python SruHandler._timeNow怎么用?Python SruHandler._timeNow使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类meresco.components.sru.SruHandler
的用法示例。
在下文中一共展示了SruHandler._timeNow方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testCollectLog
# 需要导入模块: from meresco.components.sru import SruHandler [as 别名]
# 或者: from meresco.components.sru.SruHandler import _timeNow [as 别名]
def testCollectLog(self):
handler = SruHandler(enableCollectLog=True)
observer = CallTrace('observer', emptyGeneratorMethods=['echoedExtraRequestData', 'extraResponseData'])
__callstack_var_logCollector__ = dict()
times = [1, 2.5, 3.5]
def timeNow():
return times.pop(0)
handler._timeNow = timeNow
def executeQuery(**kwargs):
response = Response(total=0, hits=[])
response.queryTime=5
raise StopIteration(response)
yield
observer.methods['executeQuery'] = executeQuery
handler.addObserver(observer)
arguments = dict(startRecord=11, maximumRecords=15, query='query', recordPacking='string', recordSchema='schema')
consume(handler.searchRetrieve(sruArguments=arguments, **arguments))
self.assertEquals({
'sru': {
'handlingTime': [Decimal('2.500')],
'queryTime': [Decimal('1.500')],
'indexTime': [Decimal('0.005')],
'numberOfRecords': [0],
'arguments': [{
'startRecord': 11,
'query': 'query',
'recordPacking': 'string',
'maximumRecords': 15,
'recordSchema': 'schema',
}],
}
}, __callstack_var_logCollector__)
示例2: testCollectLogWhenIndexRaisesError
# 需要导入模块: from meresco.components.sru import SruHandler [as 别名]
# 或者: from meresco.components.sru.SruHandler import _timeNow [as 别名]
def testCollectLogWhenIndexRaisesError(self):
handler = SruHandler(enableCollectLog=True)
observer = CallTrace('observer', emptyGeneratorMethods=['echoedExtraRequestData', 'extraResponseData', 'additionalDiagnosticDetails'])
__callstack_var_logCollector__ = dict()
times = [1]
def timeNow():
return times.pop(0)
handler._timeNow = timeNow
def executeQuery(**kwargs):
raise Exception('Sorry')
yield
observer.methods['executeQuery'] = executeQuery
handler.addObserver(observer)
arguments = dict(startRecord=11, maximumRecords=15, query='query', recordPacking='string', recordSchema='schema')
consume(handler.searchRetrieve(sruArguments=arguments, **arguments))
self.assertEquals({
'sru': {
'arguments': [{
'startRecord': 11,
'query': 'query',
'recordPacking': 'string',
'maximumRecords': 15,
'recordSchema': 'schema',
}],
}
}, __callstack_var_logCollector__)
示例3: testQueryTimeInExtraResponse
# 需要导入模块: from meresco.components.sru import SruHandler [as 别名]
# 或者: from meresco.components.sru.SruHandler import _timeNow [as 别名]
def testQueryTimeInExtraResponse(self):
handler = SruHandler(includeQueryTimes=True)
observer = CallTrace('observer', emptyGeneratorMethods=['echoedExtraRequestData', 'extraResponseData'])
times = [1, 2.5, 3.5]
def timeNow():
return times.pop(0)
handler._timeNow = timeNow
def executeQuery(**kwargs):
response = Response(total=0, hits=[])
response.queryTime=5
raise StopIteration(response)
yield
observer.methods['executeQuery'] = executeQuery
handler.addObserver(observer)
arguments = dict(startRecord=11, maximumRecords=15, query='query', recordPacking='string', recordSchema='schema')
result = "".join(compose(handler.searchRetrieve(sruArguments=arguments, **arguments)))
sruResponse = parse(StringIO(result))
extraResponseData = sruResponse.xpath('/srw:searchRetrieveResponse/srw:extraResponseData', namespaces={'srw':"http://www.loc.gov/zing/srw/"})[0]
self.assertEqualsWS("""<srw:extraResponseData %(xmlns_srw)s %(xmlns_diag)s %(xmlns_xcql)s %(xmlns_dc)s %(xmlns_meresco_srw)s>
<querytimes xmlns="http://meresco.org/namespace/timing">
<sruHandling>PT2.500S</sruHandling>
<sruQueryTime>PT1.500S</sruQueryTime>
<index>PT0.005S</index>
</querytimes>
</srw:extraResponseData>""" % namespaces, lxmltostring(extraResponseData))
queryTimes = lxmltostring(extraResponseData.xpath('//ti:querytimes', namespaces={'ti':"http://meresco.org/namespace/timing"})[0])
assertValid(queryTimes, join(schemasPath, 'timing-20120827.xsd'))
self.assertEquals(['executeQuery', 'echoedExtraRequestData', 'extraResponseData', 'handleQueryTimes'], observer.calledMethodNames())
self.assertEquals({'sru': Decimal("2.500"), 'queryTime': Decimal("1.500"), 'index': Decimal("0.005")}, observer.calledMethods[3].kwargs)