mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 06:05:01 +07:00
PY-22857: Rewritten to support 2.6
* argparse is used only in 3 now (2 uses optparse) * no set literals
This commit is contained in:
@@ -2,8 +2,8 @@
|
||||
"""
|
||||
Tools to implement runners (https://confluence.jetbrains.com/display/~link/PyCharm+test+runners+protocol)
|
||||
"""
|
||||
import argparse
|
||||
import atexit
|
||||
import _jb_utils
|
||||
import imp
|
||||
import os
|
||||
import re
|
||||
@@ -159,7 +159,7 @@ class NewTeamcityServiceMessages(_old_service_messages):
|
||||
# Intellij may fail to process message if it has char just before it.
|
||||
# Space before message has no visible affect, but saves from such cases
|
||||
print(" ")
|
||||
if messageName in {"enteredTheMatrix", "testCount"}:
|
||||
if messageName in set(["enteredTheMatrix", "testCount"]):
|
||||
_old_service_messages.message(self, messageName, **properties)
|
||||
return
|
||||
|
||||
@@ -237,7 +237,7 @@ class NewTeamcityServiceMessages(_old_service_messages):
|
||||
"details": details}
|
||||
self.message("testFailed", **args)
|
||||
|
||||
def testFinished(self, testName, testDuration=None, flowId=None, is_suite=False):
|
||||
def testFinished(self, testName, testDuration=None, flowId=None, is_suite=False):
|
||||
testName = ".".join(self._test_to_list(testName))
|
||||
|
||||
def _write_finished_message():
|
||||
@@ -342,10 +342,11 @@ def jb_start_tests():
|
||||
del sys.argv[index:]
|
||||
except ValueError:
|
||||
pass
|
||||
parser = argparse.ArgumentParser(description='PyCharm test runner')
|
||||
parser.add_argument('--path', help='Path to file or folder to run')
|
||||
parser.add_argument('--target', help='Python target to run', action="append")
|
||||
namespace = parser.parse_args()
|
||||
utils = _jb_utils.VersionAgnosticUtils()
|
||||
|
||||
namespace = utils.get_options(
|
||||
_jb_utils.OptionDescription('--path', 'Path to file or folder to run'),
|
||||
_jb_utils.OptionDescription('--target', 'Python target to run', "append"))
|
||||
del sys.argv[1:] # Remove all args
|
||||
NewTeamcityServiceMessages().message('enteredTheMatrix')
|
||||
return namespace.path, namespace.target, additional_args
|
||||
|
||||
@@ -37,6 +37,15 @@ def jb_escape_output(output):
|
||||
return "##[jetbrains{0}".format(output)
|
||||
|
||||
|
||||
class OptionDescription(object):
|
||||
"""
|
||||
Wrapper for argparse/optparse option (see VersionAgnosticUtils#get_options)
|
||||
"""
|
||||
def __init__(self, name, description, action=None):
|
||||
self.name = name
|
||||
self.description = description
|
||||
self.action = action
|
||||
|
||||
class VersionAgnosticUtils(object):
|
||||
"""
|
||||
"six" emulator: this class fabrics appropriate tool to use regardless python version.
|
||||
@@ -60,6 +69,15 @@ class VersionAgnosticUtils(object):
|
||||
|
||||
raise NotImplementedError()
|
||||
|
||||
def get_options(self, *args):
|
||||
"""
|
||||
Hides agrparse/optparse difference
|
||||
|
||||
:param args: OptionDescription
|
||||
:return: options namespace
|
||||
"""
|
||||
raise NotImplementedError()
|
||||
|
||||
|
||||
class _Py2Utils(VersionAgnosticUtils):
|
||||
"""
|
||||
@@ -75,6 +93,17 @@ class _Py2Utils(VersionAgnosticUtils):
|
||||
return unicode(str(obj).decode("utf-8")) # or it may have __str__
|
||||
|
||||
|
||||
def get_options(self, *args):
|
||||
import optparse
|
||||
|
||||
parser = optparse.OptionParser()
|
||||
for option in args:
|
||||
assert isinstance(option, OptionDescription)
|
||||
parser.add_option(option.name, help=option.description, action=option.action)
|
||||
(options, _) = parser.parse_args()
|
||||
return options
|
||||
|
||||
|
||||
class _Py3KUtils(VersionAgnosticUtils):
|
||||
"""
|
||||
Util for Py3
|
||||
@@ -82,3 +111,12 @@ class _Py3KUtils(VersionAgnosticUtils):
|
||||
|
||||
def to_unicode(self, obj):
|
||||
return str(obj)
|
||||
|
||||
def get_options(self, *args):
|
||||
import argparse
|
||||
|
||||
parser = argparse.ArgumentParser()
|
||||
for option in args:
|
||||
assert isinstance(option, OptionDescription)
|
||||
parser.add_argument(option.name, help=option.description, action=option.action)
|
||||
return parser.parse_args()
|
||||
Reference in New Issue
Block a user