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


Python main.execute函数代码示例

本文整理汇总了Python中wakatime.main.execute函数的典型用法代码示例。如果您正苦于以下问题:Python execute函数的具体用法?Python execute怎么用?Python execute使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了execute函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_config_file_not_passed_in_command_line_args

    def test_config_file_not_passed_in_command_line_args(self):
        self.patched['wakatime.packages.requests.adapters.HTTPAdapter.send'].return_value = CustomResponse()

        with TemporaryDirectory() as tempdir:
            entity = 'tests/samples/codefiles/emptyfile.txt'
            shutil.copy(entity, os.path.join(tempdir, 'emptyfile.txt'))
            entity = os.path.realpath(os.path.join(tempdir, 'emptyfile.txt'))
            args = ['--file', entity, '--log-file', '~/.wakatime.log']

            with mock.patch('wakatime.configs.os.environ.get') as mock_env:
                mock_env.return_value = None

                with mock.patch('wakatime.configs.open') as mock_open:
                    mock_open.side_effect = IOError('')

                    with self.assertRaises(SystemExit) as e:
                        execute(args)

        self.assertEquals(int(str(e.exception)), AUTH_ERROR)
        expected_stdout = u('')
        expected_stderr = open('tests/samples/output/common_usage_header').read()
        expected_stderr += open('tests/samples/output/configs_test_config_file_not_passed_in_command_line_args').read()
        self.assertEquals(sys.stdout.getvalue(), expected_stdout)
        self.assertEquals(sys.stderr.getvalue(), expected_stderr)
        self.patched['wakatime.session_cache.SessionCache.get'].assert_not_called()
开发者ID:wakatime,项目名称:wakatime,代码行数:25,代码来源:test_configs.py

示例2: test_log_file_location_can_be_set_from_env_variable

    def test_log_file_location_can_be_set_from_env_variable(self, logs):
        logging.disable(logging.NOTSET)

        response = Response()
        response.status_code = 0
        self.patched['wakatime.packages.requests.adapters.HTTPAdapter.send'].return_value = response

        now = u(int(time.time()))

        with utils.TemporaryDirectory() as tempdir:
            entity = 'tests/samples/codefiles/python.py'
            shutil.copy(entity, os.path.join(tempdir, 'python.py'))
            entity = os.path.realpath(os.path.join(tempdir, 'python.py'))
            config = 'tests/samples/configs/good_config.cfg'
            shutil.copy(config, os.path.join(tempdir, '.wakatime.cfg'))
            config = os.path.realpath(os.path.join(tempdir, '.wakatime.cfg'))
            expected_logfile = os.path.realpath(os.path.join(tempdir, '.wakatime.log'))

            with utils.mock.patch('wakatime.main.os.environ.get') as mock_env:
                mock_env.return_value = tempdir

                args = ['--file', entity, '--config', config, '--time', now]

                execute(args)

                retval = execute(args)
                self.assertEquals(retval, 102)
                self.assertNothingPrinted()

                self.assertEquals(logging.WARNING, logging.getLogger('WakaTime').level)
                logfile = os.path.realpath(logging.getLogger('WakaTime').handlers[0].baseFilename)
                self.assertEquals(logfile, expected_logfile)
                logs.check()
开发者ID:wakatime,项目名称:wakatime,代码行数:33,代码来源:test_logging.py

示例3: test_unhandled_exception

    def test_unhandled_exception(self, logs):
        logging.disable(logging.NOTSET)

        with utils.mock.patch('wakatime.main.send_heartbeats') as mock_send:
            ex_msg = 'testing unhandled exception'
            mock_send.side_effect = RuntimeError(ex_msg)

            entity = 'tests/samples/codefiles/twolinefile.txt'
            config = 'tests/samples/configs/good_config.cfg'
            key = str(uuid.uuid4())

            args = ['--entity', entity, '--key', key, '--config', config]

            execute(args)

            self.assertIn(ex_msg, sys.stdout.getvalue())
            self.assertEquals(sys.stderr.getvalue(), '')

            log_output = u("\n").join([u(' ').join(x) for x in logs.actual()])
            self.assertIn(ex_msg, log_output)

            self.assertHeartbeatNotSent()

            self.assertHeartbeatNotSavedOffline()
            self.assertOfflineHeartbeatsNotSynced()
            self.assertSessionCacheUntouched()
开发者ID:wakatime,项目名称:wakatime,代码行数:26,代码来源:test_main.py

示例4: test_heartbeat_saved_from_result_index_error

    def test_heartbeat_saved_from_result_index_error(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

                response = CustomResponse()
                response.response_text = '{"responses": [[{"id":1}]]}'
                self.patched['wakatime.packages.requests.adapters.HTTPAdapter.send'].return_value = response

                now = u(int(time.time()))
                entity = 'tests/samples/codefiles/twolinefile.txt'
                config = 'tests/samples/configs/good_config.cfg'

                args = ['--file', entity, '--config', config, '--time', now]
                execute(args)

                queue = Queue(None, None)
                saved_heartbeat = queue.pop()
                self.assertPathsEqual(os.path.realpath(entity), saved_heartbeat['entity'])

                self.assertNothingPrinted()
                expected = 'IndexError'
                actual = self.getLogOutput(logs)
                self.assertIn(expected, actual)
开发者ID:wakatime,项目名称:wakatime,代码行数:26,代码来源:test_offlinequeue.py

示例5: test_bad_config_file

    def test_bad_config_file(self, logs):
        logging.disable(logging.NOTSET)

        with TemporaryDirectory() as tempdir:
            entity = 'tests/samples/codefiles/emptyfile.txt'
            shutil.copy(entity, os.path.join(tempdir, 'emptyfile.txt'))
            entity = os.path.realpath(os.path.join(tempdir, 'emptyfile.txt'))

            config = 'tests/samples/configs/bad_config.cfg'
            args = ['--file', entity, '--config', config, '--log-file', '~/.wakatime.log']

            with self.assertRaises(SystemExit) as e:
                execute(args)

            self.assertEquals(int(str(e.exception)), CONFIG_FILE_PARSE_ERROR)
            self.assertIn('ParsingError', sys.stdout.getvalue())
            expected_stderr = ''
            self.assertEquals(sys.stderr.getvalue(), expected_stderr)

            log_output = u("\n").join([u(' ').join(x) for x in logs.actual()])
            expected = ''
            self.assertEquals(log_output, expected)

            self.patched['wakatime.offlinequeue.Queue.push'].assert_not_called()
            self.patched['wakatime.session_cache.SessionCache.get'].assert_not_called()
            self.patched['wakatime.session_cache.SessionCache.delete'].assert_not_called()
            self.patched['wakatime.session_cache.SessionCache.save'].assert_not_called()
开发者ID:wakatime,项目名称:wakatime,代码行数:27,代码来源:test_configs.py

示例6: test_push_handles_exception_on_close

    def test_push_handles_exception_on_close(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

                response = Response()
                response.status_code = 500
                self.patched['wakatime.packages.requests.adapters.HTTPAdapter.send'].return_value = response

                now = u(int(time.time()))
                entity = 'tests/samples/codefiles/twolinefile.txt'
                config = 'tests/samples/configs/good_config.cfg'

                mock_conn = mock.MagicMock()
                mock_conn.close.side_effect = sqlite3.Error('')

                mock_c = mock.MagicMock()
                mock_c.fetchone.return_value = None

                with mock.patch('wakatime.offlinequeue.Queue.connect') as mock_connect:
                    mock_connect.return_value = (mock_conn, mock_c)

                    args = ['--file', entity, '--config', config, '--time', now]
                    execute(args)

                    response.status_code = 201
                    execute(args)

                queue = Queue(None, None)
                saved_heartbeat = queue.pop()
                self.assertEquals(None, saved_heartbeat)

                self.assertNothingPrinted()
开发者ID:wakatime,项目名称:wakatime,代码行数:35,代码来源:test_offlinequeue.py

示例7: test_alternate_project_argument_used_when_project_not_detected

    def test_alternate_project_argument_used_when_project_not_detected(self):
        response = Response()
        response.status_code = 0
        self.patched['wakatime.packages.requests.adapters.HTTPAdapter.send'].return_value = response

        tempdir = tempfile.mkdtemp()
        entity = 'tests/samples/projects/git/emptyfile.txt'
        shutil.copy(entity, os.path.join(tempdir, 'emptyfile.txt'))

        now = u(int(time.time()))
        entity = os.path.join(tempdir, 'emptyfile.txt')
        config = 'tests/samples/configs/good_config.cfg'

        args = ['--file', entity, '--config', config, '--time', now]
        execute(args)

        args = ['--file', entity, '--config', config, '--time', now, '--alternate-project', 'alt-project']
        execute(args)

        calls = self.patched['wakatime.packages.requests.adapters.HTTPAdapter.send'].call_args_list

        body = calls[0][0][0].body
        data = json.loads(body)[0]
        self.assertEquals(None, data.get('project'))

        body = calls[1][0][0].body
        data = json.loads(body)[0]
        self.assertEquals('alt-project', data['project'])
开发者ID:wakatime,项目名称:wakatime,代码行数:28,代码来源:test_project.py

示例8: test_invalid_proxy

    def test_invalid_proxy(self, logs):
        logging.disable(logging.NOTSET)

        response = CustomResponse()
        self.patched['wakatime.packages.requests.adapters.HTTPAdapter.send'].return_value = response

        with utils.TemporaryDirectory() as tempdir:
            entity = 'tests/samples/codefiles/emptyfile.txt'
            shutil.copy(entity, os.path.join(tempdir, 'emptyfile.txt'))
            entity = os.path.realpath(os.path.join(tempdir, 'emptyfile.txt'))
            proxy = 'invaliddd:proxyarg'
            config = 'tests/samples/configs/good_config.cfg'
            args = ['--file', entity, '--config', config, '--proxy', proxy]

            with self.assertRaises(SystemExit) as e:
                execute(args)

            self.assertEquals(int(str(e.exception)), 2)
            self.assertEquals(sys.stdout.getvalue(), '')
            expected = 'error: Invalid proxy. Must be in format https://user:[email protected]:port or socks5://user:[email protected]:port or domain\\user:pass.'
            self.assertIn(expected, sys.stderr.getvalue())

            log_output = u("\n").join([u(' ').join(x) for x in logs.actual()])
            expected = ''
            self.assertEquals(log_output, expected)

            self.patched['wakatime.session_cache.SessionCache.get'].assert_not_called()
            self.patched['wakatime.session_cache.SessionCache.delete'].assert_not_called()
            self.patched['wakatime.session_cache.SessionCache.save'].assert_not_called()

            self.patched['wakatime.offlinequeue.Queue.push'].assert_not_called()
            self.patched['wakatime.offlinequeue.Queue.pop'].assert_not_called()

            self.patched['wakatime.packages.requests.adapters.HTTPAdapter.send'].assert_not_called()
开发者ID:wakatime,项目名称:wakatime,代码行数:34,代码来源:test_proxy.py

示例9: test_get_project_not_used_when_project_names_hidden

    def test_get_project_not_used_when_project_names_hidden(self):
        response = Response()
        response.status_code = 0
        self.patched['wakatime.packages.requests.adapters.HTTPAdapter.send'].return_value = response

        tempdir = tempfile.mkdtemp()
        shutil.copytree('tests/samples/projects/git', os.path.join(tempdir, 'git'))
        shutil.move(os.path.join(tempdir, 'git', 'dot_git'), os.path.join(tempdir, 'git', '.git'))

        now = u(int(time.time()))
        entity = os.path.join(tempdir, 'git', 'emptyfile.txt')
        config = 'tests/samples/configs/good_config.cfg'

        args = ['--hide-project-names', '--file', entity, '--config', config, '--time', now]

        execute(args)
        self.assertHeartbeatSavedOffline()

        self.assertNotEquals('git', self.patched['wakatime.offlinequeue.Queue.push'].call_args[0][0]['project'])
        self.assertEquals(None, self.patched['wakatime.offlinequeue.Queue.push'].call_args[0][0]['branch'])
        proj = open(os.path.join(tempdir, 'git', '.wakatime-project')).read()
        self.assertEquals(proj, self.patched['wakatime.offlinequeue.Queue.push'].call_args[0][0]['project'])

        execute(args)

        self.assertEquals(proj, self.patched['wakatime.offlinequeue.Queue.push'].call_args[0][0]['project'])
开发者ID:wakatime,项目名称:wakatime,代码行数:26,代码来源:test_project.py

示例10: test_ioerror_when_reading_mercurial_branch

    def test_ioerror_when_reading_mercurial_branch(self, logs):
        logging.disable(logging.NOTSET)

        response = Response()
        response.status_code = 0
        self.patched['wakatime.packages.requests.adapters.HTTPAdapter.send'].return_value = response

        with mock.patch('wakatime.projects.git.Git.process') as mock_git:
            mock_git.return_value = False

            now = u(int(time.time()))
            entity = 'tests/samples/projects/hg/emptyfile.txt'
            config = 'tests/samples/configs/good_config.cfg'

            args = ['--file', entity, '--config', config, '--time', now]

            with mock.patch('wakatime.projects.mercurial.open') as mock_open:
                mock_open.side_effect = IOError('')
                execute(args)

            self.assertEquals('hg', self.patched['wakatime.offlinequeue.Queue.push'].call_args[0][0]['project'])
            self.assertEquals('default', self.patched['wakatime.offlinequeue.Queue.push'].call_args[0][0]['branch'])

            self.assertNothingPrinted()
            actual = self.getLogOutput(logs)
            expected = 'OSError' if self.isPy33OrNewer else 'IOError'
            self.assertIn(expected, actual)
开发者ID:wakatime,项目名称:wakatime,代码行数:27,代码来源:test_project.py

示例11: test_push_handles_connection_exception

    def test_push_handles_connection_exception(self):
        with tempfile.NamedTemporaryFile() as fh:
            with utils.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

                now = u(int(time.time()))
                entity = 'tests/samples/codefiles/twolinefile.txt'
                config = 'tests/samples/configs/sample.cfg'

                with utils.mock.patch('wakatime.offlinequeue.Queue.connect') as mock_connect:
                    mock_connect.side_effect = sqlite3.Error('')

                    args = ['--file', entity, '--config', config, '--time', now]
                    execute(args)

                    response.status_code = 201
                    execute(args)

                queue = Queue()
                saved_heartbeat = queue.pop()
                self.assertEquals(None, saved_heartbeat)
开发者ID:Thamaraiselvam,项目名称:wakatime,代码行数:25,代码来源:test_offlinequeue.py

示例12: test_heartbeat_saved_when_requests_raises_exception

    def test_heartbeat_saved_when_requests_raises_exception(self, logs):
        logging.disable(logging.NOTSET)

        with tempfile.NamedTemporaryFile() as fh:
            with utils.mock.patch('wakatime.offlinequeue.Queue.get_db_file') as mock_db_file:
                mock_db_file.return_value = fh.name

                exception_msg = u("Oops, requests raised an exception. You're move.")
                self.patched['wakatime.packages.requests.adapters.HTTPAdapter.send'].side_effect = AttributeError(exception_msg)

                now = u(int(time.time()))
                entity = 'tests/samples/codefiles/twolinefile.txt'
                config = 'tests/samples/configs/good_config.cfg'

                args = ['--file', entity, '--config', config, '--time', now]
                execute(args)

                queue = Queue()
                saved_heartbeat = queue.pop()
                self.assertEquals(os.path.realpath(entity), saved_heartbeat['entity'])

                self.assertEquals(sys.stdout.getvalue(), '')
                self.assertEquals(sys.stderr.getvalue(), '')

                output = [u(' ').join(x) for x in logs.actual()]
                self.assertIn(exception_msg, output[0])

                self.patched['wakatime.session_cache.SessionCache.get'].assert_called_once_with()
                self.patched['wakatime.session_cache.SessionCache.delete'].assert_has_calls([call(), call()])
                self.patched['wakatime.session_cache.SessionCache.save'].assert_not_called()
开发者ID:awesome-archive,项目名称:wakatime,代码行数:30,代码来源:test_offlinequeue.py

示例13: test_nonascii_heartbeat_saved

    def test_nonascii_heartbeat_saved(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

                response = Response()
                response.status_code = 500
                self.patched['wakatime.packages.requests.adapters.HTTPAdapter.send'].return_value = response

                with TemporaryDirectory() as tempdir:
                    filename = list(filter(lambda x: x.endswith('.txt'), os.listdir(u('tests/samples/codefiles/unicode'))))[0]
                    entity = os.path.join('tests/samples/codefiles/unicode', filename)
                    shutil.copy(entity, os.path.join(tempdir, filename))
                    entity = os.path.realpath(os.path.join(tempdir, filename))
                    now = u(int(time.time()))
                    config = 'tests/samples/configs/good_config.cfg'
                    key = str(uuid.uuid4())
                    language = 'lang汉语' if self.isPy35OrNewer else 'lang\xe6\xb1\x89\xe8\xaf\xad'
                    project = 'proj汉语' if self.isPy35OrNewer else 'proj\xe6\xb1\x89\xe8\xaf\xad'
                    branch = 'branch汉语' if self.isPy35OrNewer else 'branch\xe6\xb1\x89\xe8\xaf\xad'
                    heartbeat = {
                        'language': u(language),
                        'lines': 0,
                        'entity': os.path.realpath(entity),
                        'project': u(project),
                        'branch': u(branch),
                        'time': float(now),
                        'type': 'file',
                        'is_write': False,
                        'user_agent': ANY,
                        'dependencies': [],
                    }

                    args = ['--file', entity, '--key', key, '--config', config, '--time', now]

                    with mock.patch('wakatime.stats.standardize_language') as mock_language:
                        mock_language.return_value = language

                        with mock.patch('wakatime.heartbeat.get_project_info') as mock_project:
                            mock_project.return_value = (project, branch)

                            execute(args)

                    self.assertNothingPrinted()
                    self.assertNothingLogged(logs)

                    self.assertHeartbeatSent(heartbeat)

                    queue = Queue(None, None)
                    saved_heartbeat = queue.pop()
                    self.assertPathsEqual(os.path.realpath(entity), saved_heartbeat['entity'])
                    self.assertEquals(u(language), saved_heartbeat['language'])
                    self.assertEquals(u(project), saved_heartbeat['project'])
                    self.assertEquals(u(branch), saved_heartbeat['branch'])
开发者ID:wakatime,项目名称:wakatime,代码行数:56,代码来源:test_offlinequeue.py

示例14: test_help_contents

    def test_help_contents(self):
        args = ['--help']
        with self.assertRaises(SystemExit):
            execute(args)
        expected_stdout = open('tests/samples/output/test_help_contents').read()
        self.assertEquals(sys.stdout.getvalue(), expected_stdout)
        self.assertEquals(sys.stderr.getvalue(), '')

        self.patched['wakatime.offlinequeue.Queue.push'].assert_not_called()
        self.patched['wakatime.offlinequeue.Queue.pop'].assert_not_called()
开发者ID:Thamaraiselvam,项目名称:wakatime,代码行数:10,代码来源:test_main.py

示例15: test_missing_config_file

    def test_missing_config_file(self):
        config = 'foo'
        entity = 'tests/samples/codefiles/emptyfile.txt'
        args = ['--file', entity, '--config', config]
        with self.assertRaises(SystemExit):
            execute(args)
        expected_stdout = u("Error: Could not read from config file foo\n")
        expected_stderr = open('tests/samples/output/test_missing_config_file').read()
        self.assertEquals(sys.stdout.getvalue(), expected_stdout)
        self.assertEquals(sys.stderr.getvalue(), expected_stderr)

        self.patched['wakatime.session_cache.SessionCache.get'].assert_not_called()
开发者ID:Thamaraiselvam,项目名称:wakatime,代码行数:12,代码来源:test_main.py


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