当前位置: 首页>>代码示例>>Python>>正文


Python Queue.pop_many方法代码示例

本文整理汇总了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)
开发者ID:wakatime,项目名称:wakatime,代码行数:55,代码来源:test_offlinequeue.py

示例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)
开发者ID:wakatime,项目名称:wakatime,代码行数:47,代码来源:test_offlinequeue.py

示例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])))
开发者ID:wakatime,项目名称:wakatime,代码行数:83,代码来源:test_offlinequeue.py


注:本文中的wakatime.offlinequeue.Queue.pop_many方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。