本文整理匯總了Python中wakatime.offlinequeue.Queue.pop_many方法的典型用法代碼示例。如果您正苦於以下問題:Python Queue.pop_many方法的具體用法?Python Queue.pop_many怎麽用?Python Queue.pop_many使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類wakatime.offlinequeue.Queue
的用法示例。
在下文中一共展示了Queue.pop_many方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_leftover_heartbeats_saved_when_bulk_response_not_matching_length
# 需要導入模塊: from wakatime.offlinequeue import Queue [as 別名]
# 或者: from wakatime.offlinequeue.Queue import pop_many [as 別名]
def test_leftover_heartbeats_saved_when_bulk_response_not_matching_length(self, logs):
logging.disable(logging.NOTSET)
with NamedTemporaryFile() as fh:
with mock.patch('wakatime.offlinequeue.Queue._get_db_file') as mock_db_file:
mock_db_file.return_value = fh.name
entities = [
'emptyfile.txt',
'twolinefile.txt',
'python.py',
'go.go',
'java.java',
'php.php',
]
with TemporaryDirectory() as tempdir:
for entity in entities:
shutil.copy(os.path.join('tests/samples/codefiles', entity), os.path.join(tempdir, entity))
now = u(int(time.time()))
key = str(uuid.uuid4())
args = ['--file', os.path.join(tempdir, entities[0]), '--key', key, '--config', 'tests/samples/configs/good_config.cfg', '--time', now, '--extra-heartbeats']
response = CustomResponse()
response.response_code = 202
response.response_text = '{"responses": [[null,201], [null,201]]}'
self.patched['wakatime.packages.requests.adapters.HTTPAdapter.send'].return_value = response
with mock.patch('wakatime.main.sys.stdin') as mock_stdin:
heartbeats = json.dumps([{
'timestamp': now,
'entity': os.path.join(tempdir, entity),
'entity_type': 'file',
'is_write': False,
} for entity in entities[1:]])
mock_stdin.readline.return_value = heartbeats
retval = execute(args)
self.assertEquals(retval, SUCCESS)
self.assertNothingPrinted()
queue = Queue(None, None)
self.assertEquals(queue._get_db_file(), fh.name)
saved_heartbeats = next(queue.pop_many())
self.assertNothingPrinted()
expected = "WakaTime WARNING Missing 4 results from api.\nWakaTime WARNING Missing 2 results from api."
actual = self.getLogOutput(logs)
self.assertEquals(actual, expected)
# make sure extra heartbeats not matching server response were saved
self.assertEquals(len(saved_heartbeats), 2)
示例2: test_500_error_when_sending_offline_heartbeats
# 需要導入模塊: from wakatime.offlinequeue import Queue [as 別名]
# 或者: from wakatime.offlinequeue.Queue import pop_many [as 別名]
def test_500_error_when_sending_offline_heartbeats(self):
with NamedTemporaryFile() as fh:
with mock.patch('wakatime.offlinequeue.Queue._get_db_file') as mock_db_file:
mock_db_file.return_value = fh.name
response = Response()
response.status_code = 500
self.patched['wakatime.packages.requests.adapters.HTTPAdapter.send'].return_value = response
config = 'tests/samples/configs/good_config.cfg'
now1 = u(int(time.time()))
entity1 = 'tests/samples/codefiles/emptyfile.txt'
project1 = 'proj1'
args = ['--file', entity1, '--config', config, '--time', now1, '--project', project1]
execute(args)
now2 = u(int(time.time()))
entity2 = 'tests/samples/codefiles/twolinefile.txt'
project2 = 'proj2'
args = ['--file', entity2, '--config', config, '--time', now2, '--project', project2]
execute(args)
# send heartbeats from offline queue after 201 response
now3 = u(int(time.time()))
entity3 = 'tests/samples/codefiles/python.py'
project3 = 'proj3'
args = ['--file', entity3, '--config', config, '--time', now3, '--project', project3]
response = CustomResponse()
response.second_response_code = 500
response.limit = 2
response.response_text = '{"responses": [[null,201], [null,201], [null,201]]}'
self.patched['wakatime.packages.requests.adapters.HTTPAdapter.send'].return_value = response
retval = execute(args)
self.assertEquals(retval, API_ERROR)
# offline queue should still have saved heartbeats
queue = Queue(None, None)
saved_heartbeats = next(queue.pop_many())
self.assertNothingPrinted()
self.assertEquals(len(saved_heartbeats), 2)
示例3: test_heartbeats_sent_not_saved_from_bulk_response
# 需要導入模塊: from wakatime.offlinequeue import Queue [as 別名]
# 或者: from wakatime.offlinequeue.Queue import pop_many [as 別名]
def test_heartbeats_sent_not_saved_from_bulk_response(self, logs):
logging.disable(logging.NOTSET)
with NamedTemporaryFile() as fh:
with mock.patch('wakatime.offlinequeue.Queue._get_db_file') as mock_db_file:
mock_db_file.return_value = fh.name
entities = [
'emptyfile.txt',
'twolinefile.txt',
'python.py',
'go.go',
]
with TemporaryDirectory() as tempdir:
for entity in entities:
shutil.copy(os.path.join('tests/samples/codefiles', entity), os.path.join(tempdir, entity))
now = u(int(time.time()))
key = str(uuid.uuid4())
args = ['--file', os.path.join(tempdir, entities[0]), '--key', key, '--config', 'tests/samples/configs/good_config.cfg', '--time', now, '--extra-heartbeats']
response = CustomResponse()
response.response_code = 202
response.response_text = '{"responses": [[null,201], [null,500], [null,201], [null, 500]]}'
self.patched['wakatime.packages.requests.adapters.HTTPAdapter.send'].return_value = response
with mock.patch('wakatime.main.sys.stdin') as mock_stdin:
heartbeats = json.dumps([{
'timestamp': now,
'entity': os.path.join(tempdir, entity),
'entity_type': 'file',
'is_write': False,
} for entity in entities[1:]])
mock_stdin.readline.return_value = heartbeats
with mock.patch('wakatime.offlinequeue.Queue.pop') as mock_pop:
mock_pop.return_value = None
retval = execute(args)
self.assertEquals(retval, SUCCESS)
self.assertNothingPrinted()
heartbeat = {
'entity': os.path.realpath(os.path.join(tempdir, entities[0])),
'language': ANY,
'lines': ANY,
'project': ANY,
'time': ANY,
'type': 'file',
'is_write': ANY,
'user_agent': ANY,
'dependencies': ANY,
}
extra_heartbeats = [{
'entity': os.path.realpath(os.path.join(tempdir, entity)),
'language': ANY,
'lines': ANY,
'project': ANY,
'branch': ANY,
'time': ANY,
'is_write': ANY,
'type': 'file',
'dependencies': ANY,
'user_agent': ANY,
} for entity in entities[1:]]
self.assertHeartbeatSent(heartbeat, extra_heartbeats=extra_heartbeats)
self.assertSessionCacheSaved()
queue = Queue(None, None)
self.assertPathsEqual(queue._get_db_file(), fh.name)
saved_heartbeats = next(queue.pop_many())
self.assertNothingPrinted()
self.assertNothingLogged(logs)
# make sure only heartbeats with error code responses were saved
self.assertEquals(sum(1 for x in saved_heartbeats), 2)
self.assertPathsEqual(saved_heartbeats[0].entity, os.path.realpath(os.path.join(tempdir, entities[1])))
self.assertPathsEqual(saved_heartbeats[1].entity, os.path.realpath(os.path.join(tempdir, entities[3])))