added content/source root checkboxes to all run configurations

This commit is contained in:
Ekaterina Tuzova
2013-03-04 16:32:41 +04:00
parent f44b5bbd97
commit 952fa4dffb
24 changed files with 589 additions and 406 deletions
+118 -109
View File
@@ -1,8 +1,17 @@
import sys, os, imp, re, inspect
from utrunner import debug
from nose_helper.util import func_lineno
import traceback
import sys, os
import imp
from tcunittest import TeamcityTestResult
from pycharm_run_utils import import_system_module
from pycharm_run_utils import adjust_sys_path
from pycharm_run_utils import debug, getModuleName
adjust_sys_path()
re = import_system_module("re")
inspect = import_system_module("inspect")
try:
from attest.reporters import AbstractReporter
from attest.collectors import Tests
@@ -11,113 +20,113 @@ except:
raise NameError("Please, install attests")
class TeamCityReporter(AbstractReporter, TeamcityTestResult):
"""Teamcity reporter for attests."""
"""Teamcity reporter for attests."""
def __init__(self, prefix):
TeamcityTestResult.__init__(self)
self.prefix = prefix
def begin(self, tests):
"""initialize suite stack and count tests"""
self.total = len(tests)
self.suite_stack = []
self.messages.testCount(self.total)
def __init__(self, prefix):
TeamcityTestResult.__init__(self)
self.prefix = prefix
def success(self, result):
"""called when test finished successfully"""
suite = self.get_suite_name(result.test)
self.start_suite(suite)
name = self.get_test_name(result)
self.start_test(result, name)
self.messages.testFinished(name)
def begin(self, tests):
"""initialize suite stack and count tests"""
self.total = len(tests)
self.suite_stack = []
self.messages.testCount(self.total)
def failure(self, result):
"""called when test failed"""
suite = self.get_suite_name(result.test)
self.start_suite(suite)
name = self.get_test_name(result)
self.start_test(result, name)
exctype, value, tb = result.exc_info
error_value = self.find_error_value(tb)
if (error_value.startswith("'") or error_value.startswith('"')) and \
(error_value.endswith("'") or error_value.endswith('"')):
first = self._unescape(self.find_first(error_value))
second = self._unescape(self.find_second(error_value))
else:
first = second = ""
def success(self, result):
"""called when test finished successfully"""
suite = self.get_suite_name(result.test)
self.start_suite(suite)
name = self.get_test_name(result)
self.start_test(result, name)
self.messages.testFinished(name)
err = self.formatErr(result.exc_info)
if isinstance(result.error, AssertionError):
self.messages.testFailed(name, message='Failure',
details=err,
expected=first, actual=second)
else:
self.messages.testError(name, message='Error',
details=err)
def failure(self, result):
"""called when test failed"""
suite = self.get_suite_name(result.test)
self.start_suite(suite)
name = self.get_test_name(result)
self.start_test(result, name)
exctype, value, tb = result.exc_info
error_value = self.find_error_value(tb)
if (error_value.startswith("'") or error_value.startswith('"')) and\
(error_value.endswith("'") or error_value.endswith('"')):
first = self._unescape(self.find_first(error_value))
second = self._unescape(self.find_second(error_value))
else:
first = second = ""
def finished(self):
"""called when all tests finished"""
self.end_last_suite()
for suite in self.suite_stack[::-1]:
self.messages.testSuiteFinished(suite)
err = self.formatErr(result.exc_info)
if isinstance(result.error, AssertionError):
self.messages.testFailed(name, message='Failure',
details=err,
expected=first, actual=second)
else:
self.messages.testError(name, message='Error',
details=err)
def get_test_name(self, result):
name = result.test_name
ind = name.find("%") #remove unique module prefix
if ind != -1:
name = name[:ind]+name[name.find(".", ind):]
return name
def end_last_suite(self):
def finished(self):
"""called when all tests finished"""
self.end_last_suite()
for suite in self.suite_stack[::-1]:
self.messages.testSuiteFinished(suite)
def get_test_name(self, result):
name = result.test_name
ind = name.find("%") #remove unique module prefix
if ind != -1:
name = name[:ind]+name[name.find(".", ind):]
return name
def end_last_suite(self):
if self.current_suite:
self.messages.testSuiteFinished(self.current_suite)
self.current_suite = None
def get_suite_name(self, test):
module = inspect.getmodule(test)
klass = getattr(test, "im_class", None)
file = module.__file__
if file.endswith("pyc"):
file = file[:-1]
suite = module.__name__
if self.prefix:
tmp = file[:-3]
ind = tmp.split(self.prefix)[1]
suite = ind.replace("/", ".")
if klass:
suite += "." + klass.__name__
lineno = inspect.getsourcelines(klass)
else:
lineno = ("", 1)
return (suite, file+":"+str(lineno[1]))
def start_suite(self, suite_info):
"""finish previous suite and put current suite
to stack"""
suite, file = suite_info
if suite != self.current_suite:
if self.current_suite:
self.messages.testSuiteFinished(self.current_suite)
self.current_suite = None
if suite.startswith(self.current_suite+"."):
self.suite_stack.append(self.current_suite)
else:
self.messages.testSuiteFinished(self.current_suite)
for s in self.suite_stack:
if not suite.startswith(s+"."):
self.current_suite = s
self.messages.testSuiteFinished(self.current_suite)
else:
break
self.current_suite = suite
self.messages.testSuiteStarted(self.current_suite, location="file://" + file)
def get_suite_name(self, test):
module = inspect.getmodule(test)
klass = getattr(test, "im_class", None)
file = module.__file__
if file.endswith("pyc"):
file = file[:-1]
suite = module.__name__
if self.prefix:
tmp = file[:-3]
ind = tmp.split(self.prefix)[1]
suite = ind.replace("/", ".")
if klass:
suite += "." + klass.__name__
lineno = inspect.getsourcelines(klass)
else:
lineno = ("", 1)
return (suite, file+":"+str(lineno[1]))
def start_suite(self, suite_info):
"""finish previous suite and put current suite
to stack"""
suite, file = suite_info
if suite != self.current_suite:
if self.current_suite:
if suite.startswith(self.current_suite+"."):
self.suite_stack.append(self.current_suite)
else:
self.messages.testSuiteFinished(self.current_suite)
for s in self.suite_stack:
if not suite.startswith(s+"."):
self.current_suite = s
self.messages.testSuiteFinished(self.current_suite)
else:
break
self.current_suite = suite
self.messages.testSuiteStarted(self.current_suite, location="file://" + file)
def start_test(self, result, name):
"""trying to find test location """
real_func = result.test.func_closure[0].cell_contents
lineno = inspect.getsourcelines(real_func)
file = inspect.getsourcefile(real_func)
self.messages.testStarted(name, "file://"+file+":"+str(lineno[1]))
def start_test(self, result, name):
"""trying to find test location """
real_func = result.test.func_closure[0].cell_contents
lineno = inspect.getsourcelines(real_func)
file = inspect.getsourcefile(real_func)
self.messages.testStarted(name, "file://"+file+":"+str(lineno[1]))
def get_subclasses(module, base_class=TestBase):
test_classes = []
@@ -238,13 +247,13 @@ def process_args():
# From method in class or from function
module = get_module(argument_list[0])
if argument_list[1] == "":
debug("/ from function " + argument_list[2] + " in " + argument_list[0])
# test function, not method
test = getattr(module, argument_list[2])
debug("/ from function " + argument_list[2] + " in " + argument_list[0])
# test function, not method
test = getattr(module, argument_list[2])
else:
debug("/ from method " + argument_list[2] + " in class " + argument_list[1] + " in " + argument_list[0])
klass = getattr(module, argument_list[1])
test = getattr(klass(), argument_list[2])
debug("/ from method " + argument_list[2] + " in class " + argument_list[1] + " in " + argument_list[0])
klass = getattr(module, argument_list[1])
test = getattr(klass(), argument_list[2])
tests.register([test])
tests.run(reporter=TeamCityReporter(prefix))
+8 -6
View File
@@ -1,10 +1,12 @@
#!/usr/bin/env python
import sys
base_path = sys.argv.pop()
sys.path.insert(0, base_path)
from fix_getpass import fixGetpass
import os
from django.core.management import execute_manager
from pycharm_run_utils import adjust_django_sys_path
from fix_getpass import fixGetpass
adjust_django_sys_path()
base_path = sys.argv.pop()
try:
from runpy import run_module
@@ -17,6 +19,6 @@ if not manage_file:
if __name__ == "__main__":
fixGetpass()
run_module(manage_file, None, '__main__', True)
fixGetpass()
run_module(manage_file, None, '__main__', True)
+16 -11
View File
@@ -1,11 +1,19 @@
#!/usr/bin/env python
from django.core.management import ManagementUtility
import inspect
import os
import sys
import os, sys
from django.core.management import ManagementUtility
from pycharm_run_utils import import_system_module
inspect = import_system_module("inspect")
import django_test_runner
project_directory = sys.argv.pop()
sys.path.insert(0, project_directory)
from django.core import management
from django.core.management.commands.test import Command
from django.conf import settings
try:
# setup environment
@@ -13,12 +21,11 @@ try:
sys.path.append(os.path.join(project_directory, os.pardir))
project_name = os.path.basename(project_directory)
__import__(project_name)
sys.path.pop()
except ImportError:
# project has custom structure (project directory is not importable)
pass
os.chdir(project_directory)
finally:
sys.path.pop()
manage_file = os.getenv('PYCHARM_DJANGO_MANAGE_MODULE')
if not manage_file:
@@ -33,9 +40,6 @@ settings_file = os.getenv('DJANGO_SETTINGS_MODULE')
if not settings_file:
settings_file = 'settings'
from django.core import management
from django.core.management.commands.test import Command
from django.conf import settings
class PycharmTestCommand(Command):
def get_runner(self):
@@ -110,4 +114,5 @@ if __name__ == "__main__":
utility = PycharmTestManagementUtility(sys.argv)
else:
utility = ManagementUtility()
utility.execute()
+18 -9
View File
@@ -1,11 +1,20 @@
from tcunittest import TeamcityTestRunner
from django.test.simple import build_suite, build_test, settings, get_app, get_apps, setup_test_environment, teardown_test_environment
import unittest
from django.test.testcases import TestCase
from tcmessages import TeamcityServiceMessages
import django
import sys
from tcunittest import TeamcityTestRunner
from tcmessages import TeamcityServiceMessages
from pycharm_run_utils import adjust_django_sys_path
from pycharm_run_utils import import_system_module
adjust_django_sys_path()
unittest = import_system_module("unittest")
from django.test.simple import build_suite, build_test, settings, get_app, get_apps, setup_test_environment, teardown_test_environment
from django.test.testcases import TestCase
from django.utils import unittest
from django import VERSION
def get_test_suite_runner():
if hasattr(settings, "TEST_RUNNER"):
from django.test.utils import get_runner
@@ -83,9 +92,9 @@ class DjangoTeamcityTestRunner(BaseRunner):
def run_tests(self, test_labels, extra_tests=None, **kwargs):
if hasattr(settings, "TEST_RUNNER") and "NoseTestSuiteRunner" in settings.TEST_RUNNER:
return super(DjangoTeamcityTestRunner, self).run_tests(test_labels,
extra_tests)
extra_tests)
return super(DjangoTeamcityTestRunner, self).run_tests(test_labels,
extra_tests, **kwargs)
extra_tests, **kwargs)
def partition_suite(suite, classes, bins):
@@ -148,7 +157,7 @@ def run_tests(test_labels, verbosity=1, interactive=False, extra_tests=[],
Returns the number of tests that failed.
"""
TeamcityServiceMessages(sys.stdout).testMatrixEntered()
if django.VERSION[1] > 1:
if VERSION[1] > 1:
return DjangoTeamcityTestRunner().run_tests(test_labels,
extra_tests=extra_tests, **kwargs)
+161 -155
View File
@@ -1,181 +1,187 @@
import os
import imp
import sys
import re
import doctest
import traceback
import datetime
from tcunittest import TeamcityTestResult
from tcmessages import TeamcityServiceMessages
from pycharm_run_utils import import_system_module
from pycharm_run_utils import adjust_sys_path, debug, getModuleName, PYTHON_VERSION_MAJOR
adjust_sys_path()
os = import_system_module("os")
re = import_system_module("re")
doctest = import_system_module("doctest")
traceback = import_system_module("traceback")
class TeamcityDocTestResult(TeamcityTestResult):
"""
DocTests Result extends TeamcityTestResult,
overrides some methods, specific for doc tests,
such as getTestName, getTestId.
"""
def getTestName(self, test):
"""
DocTests Result extends TeamcityTestResult,
overrides some methods, specific for doc tests,
such as getTestName, getTestId.
"""
def getTestName(self, test):
name = self.current_suite.name + test.source
return name
def getSuiteName(self, suite):
if test.source.rfind(".") == -1:
name = self.current_suite.name + test.source
return name
else:
name = test.source
return name
def getSuiteName(self, suite):
if test.source.rfind(".") == -1:
name = self.current_suite.name + test.source
else:
name = test.source
return name
def getTestId(self, test):
file = os.path.realpath(self.current_suite.filename)
return "file://" + file + ":" + str( self.current_suite.lineno + test.lineno)
def getTestId(self, test):
file = os.path.realpath(self.current_suite.filename)
return "file://" + file + ":" + str( self.current_suite.lineno + test.lineno)
def getSuiteLocation(self):
file = os.path.realpath(self.current_suite.filename)
location = "file://" + file
if self.current_suite.lineno:
location += ":" + str(self.current_suite.lineno)
return location
def getSuiteLocation(self):
file = os.path.realpath(self.current_suite.filename)
location = "file://" + file
if self.current_suite.lineno:
location += ":" + str(self.current_suite.lineno)
return location
def startTest(self, test):
setattr(test, "startTime", datetime.datetime.now())
id = self.getTestId(test)
self.messages.testStarted(self.getTestName(test), location=id)
def startTest(self, test):
setattr(test, "startTime", datetime.datetime.now())
id = self.getTestId(test)
self.messages.testStarted(self.getTestName(test), location=id)
def startSuite(self, suite):
self.current_suite = suite
self.messages.testSuiteStarted(suite.name, location=self.getSuiteLocation())
def startSuite(self, suite):
self.current_suite = suite
self.messages.testSuiteStarted(suite.name, location=self.getSuiteLocation())
def stopSuite(self, suite):
self.messages.testSuiteFinished(suite.name)
def stopSuite(self, suite):
self.messages.testSuiteFinished(suite.name)
def addFailure(self, test, err = ''):
self.messages.testFailed(self.getTestName(test),
message='Failure', details=err)
def addFailure(self, test, err = ''):
self.messages.testFailed(self.getTestName(test),
message='Failure', details=err)
def addError(self, test, err = ''):
self.messages.testError(self.getTestName(test),
message='Error', details=err)
def addError(self, test, err = ''):
self.messages.testError(self.getTestName(test),
message='Error', details=err)
class DocTestRunner(doctest.DocTestRunner):
"""
Special runner for doctests,
overrides __run method to report results using TeamcityDocTestResult
"""
def __init__(self, verbose=None, optionflags=0):
doctest.DocTestRunner.__init__(self, verbose, optionflags)
self.stream = sys.stdout
self.result = TeamcityDocTestResult(self.stream)
#self.result.messages.testMatrixEntered()
self._tests = []
"""
Special runner for doctests,
overrides __run method to report results using TeamcityDocTestResult
"""
def __init__(self, verbose=None, optionflags=0):
doctest.DocTestRunner.__init__(self, verbose, optionflags)
self.stream = sys.stdout
self.result = TeamcityDocTestResult(self.stream)
#self.result.messages.testMatrixEntered()
self._tests = []
def addTests(self, tests):
self._tests.extend(tests)
def addTests(self, tests):
self._tests.extend(tests)
def addTest(self, test):
self._tests.append(test)
def addTest(self, test):
self._tests.append(test)
def countTests(self):
return len(self._tests)
def countTests(self):
return len(self._tests)
def start(self):
for test in self._tests:
self.run(test)
def start(self):
for test in self._tests:
self.run(test)
def __run(self, test, compileflags, out):
failures = tries = 0
def __run(self, test, compileflags, out):
failures = tries = 0
original_optionflags = self.optionflags
SUCCESS, FAILURE, BOOM = range(3) # `outcome` state
check = self._checker.check_output
self.result.startSuite(test)
for examplenum, example in enumerate(test.examples):
original_optionflags = self.optionflags
SUCCESS, FAILURE, BOOM = range(3) # `outcome` state
check = self._checker.check_output
self.result.startSuite(test)
for examplenum, example in enumerate(test.examples):
quiet = (self.optionflags & doctest.REPORT_ONLY_FIRST_FAILURE and
failures > 0)
quiet = (self.optionflags & doctest.REPORT_ONLY_FIRST_FAILURE and
failures > 0)
self.optionflags = original_optionflags
if example.options:
for (optionflag, val) in example.options.items():
if val:
self.optionflags |= optionflag
else:
self.optionflags &= ~optionflag
self.optionflags = original_optionflags
if example.options:
for (optionflag, val) in example.options.items():
if val:
self.optionflags |= optionflag
else:
self.optionflags &= ~optionflag
if hasattr(doctest, 'SKIP'):
if self.optionflags & doctest.SKIP:
continue
if hasattr(doctest, 'SKIP'):
if self.optionflags & doctest.SKIP:
continue
tries += 1
if not quiet:
self.report_start(out, test, example)
tries += 1
if not quiet:
self.report_start(out, test, example)
filename = '<doctest %s[%d]>' % (test.name, examplenum)
filename = '<doctest %s[%d]>' % (test.name, examplenum)
try:
exec(compile(example.source, filename, "single",
compileflags, 1), test.globs)
self.debugger.set_continue() # ==== Example Finished ====
exception = None
except KeyboardInterrupt:
raise
except:
exception = sys.exc_info()
self.debugger.set_continue() # ==== Example Finished ====
try:
exec(compile(example.source, filename, "single",
compileflags, 1), test.globs)
self.debugger.set_continue() # ==== Example Finished ====
exception = None
except KeyboardInterrupt:
raise
except:
exception = sys.exc_info()
self.debugger.set_continue() # ==== Example Finished ====
got = self._fakeout.getvalue() # the actual output
self._fakeout.truncate(0)
outcome = FAILURE # guilty until proved innocent or insane
got = self._fakeout.getvalue() # the actual output
self._fakeout.truncate(0)
outcome = FAILURE # guilty until proved innocent or insane
if exception is None:
if check(example.want, got, self.optionflags):
outcome = SUCCESS
if exception is None:
if check(example.want, got, self.optionflags):
outcome = SUCCESS
else:
exc_msg = traceback.format_exception_only(*exception[:2])[-1]
if not quiet:
got += doctest._exception_traceback(exception)
else:
exc_msg = traceback.format_exception_only(*exception[:2])[-1]
if not quiet:
got += doctest._exception_traceback(exception)
if example.exc_msg is None:
outcome = BOOM
if example.exc_msg is None:
outcome = BOOM
elif check(example.exc_msg, exc_msg, self.optionflags):
outcome = SUCCESS
elif check(example.exc_msg, exc_msg, self.optionflags):
outcome = SUCCESS
elif self.optionflags & doctest.IGNORE_EXCEPTION_DETAIL:
m1 = re.match(r'[^:]*:', example.exc_msg)
m2 = re.match(r'[^:]*:', exc_msg)
if m1 and m2 and check(m1.group(0), m2.group(0),
self.optionflags):
outcome = SUCCESS
elif self.optionflags & doctest.IGNORE_EXCEPTION_DETAIL:
m1 = re.match(r'[^:]*:', example.exc_msg)
m2 = re.match(r'[^:]*:', exc_msg)
if m1 and m2 and check(m1.group(0), m2.group(0),
self.optionflags):
outcome = SUCCESS
# Report the outcome.
if outcome is SUCCESS:
self.result.startTest(example)
self.result.stopTest(example)
elif outcome is FAILURE:
self.result.startTest(example)
err = self._failure_header(test, example) +\
self._checker.output_difference(example, got, self.optionflags)
self.result.addFailure(example, err)
# Report the outcome.
if outcome is SUCCESS:
self.result.startTest(example)
self.result.stopTest(example)
elif outcome is FAILURE:
self.result.startTest(example)
err = self._failure_header(test, example) +\
self._checker.output_difference(example, got, self.optionflags)
self.result.addFailure(example, err)
elif outcome is BOOM:
self.result.startTest(example)
err=self._failure_header(test, example) + \
'Exception raised:\n' + doctest._indent(doctest._exception_traceback(exception))
self.result.addError(example, err)
elif outcome is BOOM:
self.result.startTest(example)
err=self._failure_header(test, example) +\
'Exception raised:\n' + doctest._indent(doctest._exception_traceback(exception))
self.result.addError(example, err)
else:
assert False, ("unknown outcome", outcome)
else:
assert False, ("unknown outcome", outcome)
self.optionflags = original_optionflags
self.optionflags = original_optionflags
self.result.stopSuite(test)
self.result.stopSuite(test)
modules = {}
from utrunner import debug, getModuleName, PYTHON_VERSION_MAJOR
runner = DocTestRunner()
@@ -238,7 +244,7 @@ def testFilesInFolderUsingPattern(folder, pattern = ".*"):
if name.endswith(".py"):
modules.append(loadSource(path))
elif not name.endswith(".pyc") and not name.endswith("$py.class")\
and os.path.isfile(path):
and os.path.isfile(path):
testfile(path)
for module in modules:
@@ -246,7 +252,7 @@ def testFilesInFolderUsingPattern(folder, pattern = ".*"):
result.append(module)
return result
if __name__ == "__main__":
if __name__ == "__main__":
finder = doctest.DocTestFinder()
for arg in sys.argv[1:]:
@@ -272,10 +278,10 @@ if __name__ == "__main__":
debug("/ from module " + a[0])
# for doctests from non-python file
if a[0].rfind(".py") == -1:
testfile(a[0])
modules = []
testfile(a[0])
modules = []
else:
modules = [loadSource(a[0])]
modules = [loadSource(a[0])]
# for doctests
for module in modules:
@@ -304,26 +310,26 @@ if __name__ == "__main__":
except SyntaxError:
raise NameError('File "%s" is not python file' % (a[0], ))
if a[1] == "":
# test function, not method
debug("/ from method " + a[2] + " in " + a[0])
if hasattr(module, a[2]):
testcase = getattr(module, a[2])
# test function, not method
debug("/ from method " + a[2] + " in " + a[0])
if hasattr(module, a[2]):
testcase = getattr(module, a[2])
tests = finder.find(testcase, testcase.__name__)
runner.addTests(tests)
else:
raise NameError('Module "%s" has no method "%s"' % (a[0], a[2]))
else:
debug("/ from method " + a[2] + " in class " + a[1] + " in " + a[0])
if hasattr(module, a[1]):
testCaseClass = getattr(module, a[1])
if hasattr(testCaseClass, a[2]):
testcase = getattr(testCaseClass, a[2])
tests = finder.find(testcase, testcase.__name__)
runner.addTests(tests)
else:
raise NameError('Module "%s" has no method "%s"' % (a[0], a[2]))
else:
debug("/ from method " + a[2] + " in class " + a[1] + " in " + a[0])
if hasattr(module, a[1]):
testCaseClass = getattr(module, a[1])
if hasattr(testCaseClass, a[2]):
testcase = getattr(testCaseClass, a[2])
tests = finder.find(testcase, testcase.__name__)
runner.addTests(tests)
else:
raise NameError('Class "%s" has no function "%s"' % (testCaseClass, a[2]))
else:
raise NameError('Module "%s" has no class "%s"' % (module, a[1]))
raise NameError('Class "%s" has no function "%s"' % (testCaseClass, a[2]))
else:
raise NameError('Module "%s" has no class "%s"' % (module, a[1]))
debug("/ Loaded " + str(runner.countTests()) + " tests")
TeamcityServiceMessages(sys.stdout).testCount(runner.countTests())
+9 -2
View File
@@ -1,7 +1,14 @@
import sys, shlex
from utrunner import debug
import sys
from nose_utils import TeamcityPlugin
from pycharm_run_utils import debug, import_system_module
from pycharm_run_utils import adjust_sys_path
adjust_sys_path(False)
shlex = import_system_module("shlex")
try:
from nose.core import TestProgram
from nose.config import Config
@@ -0,0 +1,42 @@
__author__ = 'ktisha'
import os, sys
import imp
PYTHON_VERSION_MAJOR = sys.version_info[0]
PYTHON_VERSION_MINOR = sys.version_info[1]
ENABLE_DEBUG_LOGGING = False
if os.getenv("UTRUNNER_ENABLE_DEBUG_LOGGING"):
ENABLE_DEBUG_LOGGING = True
def debug(what):
if ENABLE_DEBUG_LOGGING:
sys.stdout.writelines(str(what) + '\n')
def adjust_sys_path(add_script_parent=True, script_index=1):
sys.path.pop(0)
if add_script_parent:
script_path = os.path.dirname(sys.argv[script_index])
sys.path.insert(0, script_path)
def adjust_django_sys_path():
sys.path.pop(0)
script_path = sys.argv[-1]
sys.path.insert(0, script_path)
def import_system_module(name):
lib_path = os.path.dirname(sys.modules['sitecustomize'].__file__)
module_path = os.path.join(lib_path, name + '.py')
if not os.path.exists(module_path):
module_path = os.path.join(lib_path, name + '/')
if os.path.exists(module_path):
return imp.load_source('pycharm_' + name, module_path)
return None
def getModuleName(prefix, cnt):
return prefix + "%" + str(cnt)
+7 -4
View File
@@ -1,6 +1,9 @@
from tcmessages import TeamcityServiceMessages
import os
import sys
from pycharm_run_utils import adjust_sys_path
adjust_sys_path(False)
messages = TeamcityServiceMessages(prepend_linebreak=True)
messages.testMatrixEntered()
@@ -15,7 +18,7 @@ def get_name(nodeid):
return nodeid.split("::")[-1]
def fspath_to_url(fspath):
return "file:///" + str(fspath).replace("\\", "/")
return "file:///" + str(fspath).replace("\\", "/")
if PYVERSION > [1, 4, 0]:
items = {}
@@ -74,7 +77,7 @@ if PYVERSION > [1, 4, 0]:
elif report.failed:
messages.testFailed(name, details=report.longrepr)
elif report.when == "call":
messages.testFinished(name)
messages.testFinished(name)
def pytest_sessionfinish(session, exitstatus):
if current_suite:
@@ -113,7 +116,7 @@ else:
fspath, lineno, msg = item.reportinfo()
url = fspath_to_url(fspath)
if lineno: url += ":" + str(lineno)
# messages.testStarted(item.name, location=url)
# messages.testStarted(item.name, location=url)
def pytest_runtest_logreport(report):
if report.item._args:
+24 -31
View File
@@ -1,27 +1,17 @@
import os
import imp
import sys
import types
import re
from tcmessages import TeamcityServiceMessages
import imp
from tcunittest import TeamcityTestRunner
from nose_helper import TestLoader, ContextSuite
from pycharm_run_utils import import_system_module
from pycharm_run_utils import adjust_sys_path
from pycharm_run_utils import debug, getModuleName, PYTHON_VERSION_MAJOR
PYTHON_VERSION_MAJOR = sys.version_info[0]
PYTHON_VERSION_MINOR = sys.version_info[1]
adjust_sys_path()
ENABLE_DEBUG_LOGGING = False
if os.getenv("UTRUNNER_ENABLE_DEBUG_LOGGING"):
ENABLE_DEBUG_LOGGING = True
def debug(what):
if ENABLE_DEBUG_LOGGING:
sys.stdout.writelines(str(what) + '\n')
os = import_system_module("os")
re = import_system_module("re")
modules = {}
def getModuleName(prefix, cnt):
return prefix + "%" + str(cnt)
def loadSource(fileName):
baseName = os.path.basename(fileName)
@@ -30,7 +20,7 @@ def loadSource(fileName):
# for users wanted to run unittests under django
#because of django took advantage of module name
settings_file = os.getenv('DJANGO_SETTINGS_MODULE')
if settings_file and moduleName=="models":
if settings_file and moduleName == "models":
baseName = os.path.realpath(fileName)
moduleName = ".".join((baseName.split(os.sep)[-2], "models"))
@@ -54,7 +44,7 @@ def walkModules(modulesAndPattern, dirname, names):
if name.endswith(".py") and prog.match(name):
modules.append(loadSource(os.path.join(dirname, name)))
def loadModulesFromFolderRec(folder, pattern="test.*"):
def loadModulesFromFolderRec(folder, pattern = "test.*"):
modules = []
if PYTHON_VERSION_MAJOR == 3:
prog_list = [re.compile(pat.strip()) for pat in pattern.split(',')]
@@ -77,6 +67,7 @@ def setLoader(module):
try:
module.__getattribute__('unittest2')
import unittest2
testLoader = unittest2.TestLoader()
all = unittest2.TestSuite()
except:
@@ -86,6 +77,7 @@ if __name__ == "__main__":
arg = sys.argv[-1]
if arg == "true":
import unittest
testLoader = unittest.TestLoader()
all = unittest.TestSuite()
pure_unittest = True
@@ -129,24 +121,25 @@ if __name__ == "__main__":
if pure_unittest:
all.addTests(testLoader.loadTestsFromTestCase(getattr(module, a[1])))
else:
all.addTests(testLoader.loadTestsFromTestClass(getattr(module, a[1])), getattr(module, a[1]))
all.addTests(testLoader.loadTestsFromTestClass(getattr(module, a[1])),
getattr(module, a[1]))
else:
# From method in class or from function
debug("/ from method " + a[2] + " in testcase " + a[1] + " in " + a[0])
debug("/ from method " + a[2] + " in testcase " + a[1] + " in " + a[0])
module = loadSource(a[0])
setLoader(module)
if a[1] == "":
# test function, not method
all.addTest(testLoader.makeTest(getattr(module, a[2])))
# test function, not method
all.addTest(testLoader.makeTest(getattr(module, a[2])))
else:
testCaseClass = getattr(module, a[1])
try:
all.addTest(testCaseClass(a[2]))
except:
# class is not a testcase inheritor
all.addTest(testLoader.makeTest(getattr(testCaseClass, a[2]), testCaseClass))
testCaseClass = getattr(module, a[1])
try:
all.addTest(testCaseClass(a[2]))
except:
# class is not a testcase inheritor
all.addTest(
testLoader.makeTest(getattr(testCaseClass, a[2]), testCaseClass))
debug("/ Loaded " + str(all.countTestCases()) + " tests")
TeamcityTestRunner().run(all, **options)
TeamcityTestRunner().run(all, **options)
@@ -44,4 +44,9 @@ public interface AbstractPythonRunConfigurationParams {
PathMappingSettings getMappingSettings();
void setMappingSettings(@Nullable PathMappingSettings mappingSettings);
boolean addContentRoots();
boolean addSourceRoots();
void addContentRoots(boolean add);
void addSourceRoots(boolean add);
}
@@ -2,12 +2,12 @@
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="com.jetbrains.python.run.PyPluginCommonOptionsForm">
<grid id="42d7b" binding="myHideablePanel" layout-manager="BorderLayout" hgap="0" vgap="0">
<constraints>
<xy x="20" y="20" width="457" height="262"/>
<xy x="20" y="20" width="457" height="297"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<grid id="27dc6" binding="myMainPanel" layout-manager="GridLayoutManager" row-count="7" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<grid id="27dc6" binding="myMainPanel" layout-manager="GridLayoutManager" row-count="9" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints border-constraint="Center"/>
<properties/>
@@ -113,6 +113,22 @@
<text value="Path mappings"/>
</properties>
</component>
<component id="d919b" class="com.intellij.ui.components.JBCheckBox" binding="myAddContentRootsCheckbox">
<constraints>
<grid row="7" column="0" row-span="1" col-span="2" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Add content roots to PYTHONPATH"/>
</properties>
</component>
<component id="1c6cd" class="com.intellij.ui.components.JBCheckBox" binding="myAddSourceRootsCheckbox">
<constraints>
<grid row="8" column="0" row-span="1" col-span="2" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Add source roots to PYTHONPATH"/>
</properties>
</component>
</children>
</grid>
</children>
@@ -1,8 +1,8 @@
package com.jetbrains.python.run;
import com.intellij.execution.configuration.EnvironmentVariablesComponent;
import com.intellij.ide.util.PropertiesComponent;
import com.intellij.execution.util.PathMappingsComponent;
import com.intellij.ide.util.PropertiesComponent;
import com.intellij.openapi.fileChooser.FileChooserDescriptorFactory;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.project.Project;
@@ -16,12 +16,12 @@ import com.intellij.openapi.util.io.FileUtil;
import com.intellij.ui.CollectionComboBoxModel;
import com.intellij.ui.HideableDecorator;
import com.intellij.ui.RawCommandLineEditor;
import com.intellij.ui.components.JBCheckBox;
import com.intellij.ui.components.JBLabel;
import com.intellij.util.PathMappingSettings;
import com.jetbrains.python.sdk.PreferredSdkComparator;
import com.jetbrains.python.sdk.PySdkUtil;
import com.jetbrains.python.sdk.PythonSdkType;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.Nullable;
import javax.swing.*;
@@ -50,6 +50,8 @@ public class PyPluginCommonOptionsForm implements AbstractPyCommonOptionsForm {
private JBLabel myWorkingDirectoryJBLabel;
private JPanel myHideablePanel;
private PathMappingsComponent myPathMappingsComponent;
private JBCheckBox myAddContentRootsCheckbox;
private JBCheckBox myAddSourceRootsCheckbox;
private JComponent labelAnchor;
private final HideableDecorator myDecorator;
@@ -235,4 +237,25 @@ public class PyPluginCommonOptionsForm implements AbstractPyCommonOptionsForm {
myWorkingDirectoryJBLabel.setAnchor(anchor);
myEnvsComponent.setAnchor(anchor);
}
@Override
public boolean addContentRoots() {
return myAddContentRootsCheckbox.isSelected();
}
@Override
public boolean addSourceRoots() {
return myAddSourceRootsCheckbox.isSelected();
}
@Override
public void addContentRoots(boolean add) {
myAddContentRootsCheckbox.setSelected(add);
}
@Override
public void addSourceRoots(boolean add) {
myAddSourceRootsCheckbox.setSelected(add);
}
}
@@ -1,16 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="com.jetbrains.rest.run.RestConfigurationEditor">
<grid id="27dc6" binding="myMainPanel" layout-manager="GridLayoutManager" row-count="8" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<grid id="27dc6" binding="myMainPanel" layout-manager="GridLayoutManager" row-count="7" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<xy x="20" y="214" width="495" height="228"/>
<xy x="20" y="214" width="495" height="217"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<grid id="f4532" binding="myCommonOptionsPlaceholder" layout-manager="BorderLayout" hgap="0" vgap="0">
<constraints>
<grid row="7" column="1" row-span="1" col-span="2" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
<grid row="6" column="1" row-span="1" col-span="2" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>
@@ -83,12 +83,6 @@
<text resource-bundle="com/jetbrains/rest/RestBundle" key="runcfg.docutils.command"/>
</properties>
</component>
<component id="693f8" class="javax.swing.JSeparator">
<constraints>
<grid row="6" column="1" row-span="1" col-span="2" vsize-policy="7" hsize-policy="0" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
</component>
<hspacer id="93e6">
<constraints>
<grid row="4" column="0" row-span="1" col-span="1" vsize-policy="1" hsize-policy="0" anchor="0" fill="1" indent="0" use-parent-layout="false">
@@ -96,6 +96,9 @@ public class PyConsoleOptionsProvider implements PersistentStateComponent<PyCons
public String myModuleName = null;
public Map<String, String> myEnvs = Maps.newHashMap();
public String myWorkingDirectory = "";
public boolean myAddContentRoots = true;
public boolean myAddSourceRoots;
@Transient
private Project myProject;
@@ -114,13 +117,18 @@ public class PyConsoleOptionsProvider implements PersistentStateComponent<PyCons
myUseModuleSdk = form.isUseModuleSdk();
myModuleName = form.getModule() == null ? null : form.getModule().getName();
myWorkingDirectory = form.getWorkingDirectory();
myAddContentRoots = form.addContentRoots();
myAddSourceRoots = form.addSourceRoots();
}
public boolean isModified(AbstractPyCommonOptionsForm form) {
return !ComparatorUtil.equalsNullable(mySdkHome, form.getSdkHome()) ||
!myInterpreterOptions.equals(form.getInterpreterOptions()) ||
!myEnvs.equals(form.getEnvs()) ||
myUseModuleSdk != form.isUseModuleSdk()
myUseModuleSdk != form.isUseModuleSdk() ||
myAddContentRoots != form.addContentRoots() ||
myAddSourceRoots != form.addSourceRoots()
|| !ComparatorUtil.equalsNullable(myModuleName, form.getModule() == null ? null : form.getModule().getName())
|| !myWorkingDirectory.equals(form.getWorkingDirectory());
}
@@ -130,6 +138,8 @@ public class PyConsoleOptionsProvider implements PersistentStateComponent<PyCons
form.setInterpreterOptions(myInterpreterOptions);
form.setSdkHome(mySdkHome);
form.setUseModuleSdk(myUseModuleSdk);
form.addContentRoots(myAddContentRoots);
form.addSourceRoots(myAddSourceRoots);
boolean moduleWasAutoselected = false;
if (form.isUseModuleSdk() != myUseModuleSdk) {
myUseModuleSdk = form.isUseModuleSdk();
@@ -162,6 +172,15 @@ public class PyConsoleOptionsProvider implements PersistentStateComponent<PyCons
public Map<String, String> getEnvs() {
return myEnvs;
}
public boolean addContentRoots() {
return myAddContentRoots;
}
public boolean addSourceRoots() {
return myAddSourceRoots;
}
}
}
@@ -65,12 +65,12 @@ public class RunPythonConsoleAction extends AnAction implements DumbAware {
String[] setup_fragment;
Collection<String> pythonPath = PythonCommandLineState.collectPythonPath(module);
PyConsoleOptionsProvider.PyConsoleSettings settingsProvider = PyConsoleOptionsProvider.getInstance(project).getPythonConsoleSettings();
Collection<String> pythonPath = PythonCommandLineState.collectPythonPath(module, settingsProvider.addContentRoots(),
settingsProvider.addSourceRoots());
String self_path_append = constructPythonPathCommand(pythonPath);
PyConsoleOptionsProvider.PyConsoleSettings settingsProvider = PyConsoleOptionsProvider.getInstance(project).getPythonConsoleSettings();
String customStartScript = settingsProvider.getCustomStartScript();
if (customStartScript.trim().length() > 0) {
@@ -39,6 +39,8 @@ public abstract class AbstractPythonRunConfiguration<T extends AbstractRunConfig
private String myWorkingDirectory = "";
private String mySdkHome = "";
private boolean myUseModuleSdk;
private boolean myAddContentRoots;
private boolean myAddSourceRoots;
protected PathMappingSettings myMappingSettings;
public AbstractPythonRunConfiguration(final String name, final RunConfigurationModule module, final ConfigurationFactory factory) {
@@ -190,6 +192,8 @@ public abstract class AbstractPythonRunConfiguration<T extends AbstractRunConfig
mySdkHome = JDOMExternalizerUtil.readField(element, "SDK_HOME");
myWorkingDirectory = JDOMExternalizerUtil.readField(element, "WORKING_DIRECTORY");
myUseModuleSdk = Boolean.parseBoolean(JDOMExternalizerUtil.readField(element, "IS_MODULE_SDK"));
myAddContentRoots = Boolean.parseBoolean(JDOMExternalizerUtil.readField(element, "ADD_CONTENT_ROOTS"));
myAddSourceRoots = Boolean.parseBoolean(JDOMExternalizerUtil.readField(element, "ADD_SOURCE_ROOTS"));
getConfigurationModule().readExternal(element);
setMappingSettings(PathMappingSettings.readExternal(element));
@@ -212,6 +216,8 @@ public abstract class AbstractPythonRunConfiguration<T extends AbstractRunConfig
JDOMExternalizerUtil.writeField(element, "SDK_HOME", mySdkHome);
JDOMExternalizerUtil.writeField(element, "WORKING_DIRECTORY", myWorkingDirectory);
JDOMExternalizerUtil.writeField(element, "IS_MODULE_SDK", Boolean.toString(myUseModuleSdk));
JDOMExternalizerUtil.writeField(element, "ADD_CONTENT_ROOTS", Boolean.toString(myAddContentRoots));
JDOMExternalizerUtil.writeField(element, "ADD_SOURCE_ROOTS", Boolean.toString(myAddSourceRoots));
getConfigurationModule().writeExternal(element);
// extension settings:
@@ -257,6 +263,26 @@ public abstract class AbstractPythonRunConfiguration<T extends AbstractRunConfig
myUseModuleSdk = useModuleSdk;
}
@Override
public boolean addContentRoots() {
return myAddContentRoots;
}
@Override
public boolean addSourceRoots() {
return myAddSourceRoots;
}
@Override
public void addSourceRoots(boolean add) {
myAddSourceRoots = add;
}
@Override
public void addContentRoots(boolean add) {
myAddContentRoots = add;
}
public static void copyParams(AbstractPythonRunConfigurationParams source, AbstractPythonRunConfigurationParams target) {
target.setEnvs(new HashMap<String, String>(source.getEnvs()));
target.setInterpreterOptions(source.getInterpreterOptions());
@@ -266,6 +292,8 @@ public abstract class AbstractPythonRunConfiguration<T extends AbstractRunConfig
target.setModule(source.getModule());
target.setUseModuleSdk(source.isUseModuleSdk());
target.setMappingSettings(source.getMappingSettings());
target.addContentRoots(source.addContentRoots());
target.addSourceRoots(source.addSourceRoots());
}
/**
@@ -37,7 +37,10 @@ import com.jetbrains.python.facet.LibraryContributingFacet;
import com.jetbrains.python.facet.PythonPathContributingFacet;
import com.jetbrains.python.remote.PyRemoteSdkAdditionalData;
import com.jetbrains.python.remote.PythonRemoteInterpreterManager;
import com.jetbrains.python.sdk.*;
import com.jetbrains.python.sdk.PySdkUtil;
import com.jetbrains.python.sdk.PythonEnvUtil;
import com.jetbrains.python.sdk.PythonSdkAdditionalData;
import com.jetbrains.python.sdk.PythonSdkType;
import com.jetbrains.python.sdk.flavors.JythonSdkFlavor;
import com.jetbrains.python.sdk.flavors.PythonSdkFlavor;
import org.jetbrains.annotations.NotNull;
@@ -331,7 +334,7 @@ public abstract class PythonCommandLineState extends CommandLineState {
protected Collection<String> collectPythonPath() {
final Module module = myConfig.getModule();
Set<String> pythonPath = Sets.newHashSet(collectPythonPath(module));
Set<String> pythonPath = Sets.newHashSet(collectPythonPath(module, myConfig.addContentRoots(), myConfig.addSourceRoots()));
if (isDebug() && getSdkFlavor() instanceof JythonSdkFlavor) { //that fixes Jython problem changing sys.argv on execfile, see PY-8164
pythonPath.add(PythonHelpersLocator.getHelperPath("pycharm"));
@@ -343,18 +346,34 @@ public abstract class PythonCommandLineState extends CommandLineState {
@NotNull
public static Collection<String> collectPythonPath(@Nullable Module module) {
return collectPythonPath(module, true);
return collectPythonPath(module, true, true);
}
@NotNull
public static Collection<String> collectPythonPath(@Nullable Module module, final boolean addProjectRoots) {
public static Collection<String> collectPythonPath(@Nullable Module module, boolean addContentRoots,
boolean addSourceRoots) {
Collection<String> pythonPathList = Sets.newLinkedHashSet();
if (module != null && addProjectRoots) {
addLibrariesFromModule(module, pythonPathList);
if (module != null) {
Set<Module> dependencies = new HashSet<Module>();
ModuleUtil.getDependencies(module, dependencies);
if (addContentRoots) {
addRoots(pythonPathList, ModuleRootManager.getInstance(module).getContentRoots());
for (Module dependency : dependencies) {
addRoots(pythonPathList, ModuleRootManager.getInstance(dependency).getContentRoots());
}
}
if (addSourceRoots) {
addRoots(pythonPathList, ModuleRootManager.getInstance(module).getSourceRoots());
for (Module dependency : dependencies) {
addRoots(pythonPathList, ModuleRootManager.getInstance(dependency).getSourceRoots());
}
}
addLibrariesFromModule(module, pythonPathList);
addRootsFromModule(module, pythonPathList);
for (Module dependency : dependencies) {
addLibrariesFromModule(module, pythonPathList);
addLibrariesFromModule(dependency, pythonPathList);
addRootsFromModule(dependency, pythonPathList);
}
}
@@ -378,10 +397,8 @@ public abstract class PythonCommandLineState extends CommandLineState {
}
private static void addRootsFromModule(Module module, Collection<String> pythonPathList) {
final ModuleRootManager moduleRootManager = ModuleRootManager.getInstance(module);
addRoots(pythonPathList, moduleRootManager.getContentRoots());
addRoots(pythonPathList, moduleRootManager.getSourceRoots());
// for Jython
final CompilerModuleExtension extension = CompilerModuleExtension.getInstance(module);
if (extension != null) {
final VirtualFile path = extension.getCompilerOutputPath();
@@ -394,6 +411,7 @@ public abstract class PythonCommandLineState extends CommandLineState {
}
}
//additional paths from facets (f.e. buildout)
final Facet[] facets = FacetManager.getInstance(module).getAllFacets();
for (Facet facet : facets) {
if (facet instanceof PythonPathContributingFacet) {
@@ -148,14 +148,12 @@ public class PythonTask {
}
protected List<String> setupPythonPath() {
return setupPythonPath(true);
return setupPythonPath(true, true);
}
protected List<String> setupPythonPath(final boolean addProjectRoot) {
protected List<String> setupPythonPath(final boolean addContent, final boolean addSource) {
final List<String> pythonPath = Lists.newArrayList(PythonCommandLineState.getAddedPaths(mySdk));
if (addProjectRoot) {
pythonPath.addAll(PythonCommandLineState.collectPythonPath(myModule));
}
pythonPath.addAll(PythonCommandLineState.collectPythonPath(myModule, addContent, addSource));
return pythonPath;
}
@@ -41,6 +41,8 @@ public abstract class AbstractPythonTestRunConfiguration extends AbstractPythonR
private String myPattern = ""; // pattern for modules in folder to match against
private boolean usePattern = false;
protected boolean myAddContentRoots = false;
protected boolean myAddSourceRoots = false;
protected AbstractPythonTestRunConfiguration(RunConfigurationModule module, ConfigurationFactory configurationFactory, String name) {
super(name, module, configurationFactory);
@@ -56,6 +58,8 @@ public abstract class AbstractPythonTestRunConfiguration extends AbstractPythonR
myPattern = JDOMExternalizerUtil.readField(element, "PATTERN");
usePattern = Boolean.parseBoolean(JDOMExternalizerUtil.readField(element, "USE_PATTERN"));
myAddContentRoots = Boolean.parseBoolean(JDOMExternalizerUtil.readField(element, "ADD_CONTENT_ROOTS"));
myAddSourceRoots = Boolean.parseBoolean(JDOMExternalizerUtil.readField(element, "ADD_SOURCE_ROOTS"));
try {
final String testType = JDOMExternalizerUtil.readField(element, "TEST_TYPE");
@@ -77,6 +81,8 @@ public abstract class AbstractPythonTestRunConfiguration extends AbstractPythonR
JDOMExternalizerUtil.writeField(element, "TEST_TYPE", myTestType.toString());
JDOMExternalizerUtil.writeField(element, "PATTERN", myPattern);
JDOMExternalizerUtil.writeField(element, "USE_PATTERN", String.valueOf(usePattern));
JDOMExternalizerUtil.writeField(element, "ADD_CONTENT_ROOTS", String.valueOf(myAddContentRoots));
JDOMExternalizerUtil.writeField(element, "ADD_SOURCE_ROOTS", String.valueOf(myAddSourceRoots));
}
public AbstractPythonRunConfigurationParams getBaseParams() {
@@ -204,6 +210,8 @@ public abstract class AbstractPythonTestRunConfiguration extends AbstractPythonR
target.setTestType(source.getTestType());
target.setPattern(source.getPattern());
target.usePattern(source.usePattern());
target.addContentRoots(source.addContentRoots());
target.addSourceRoots(source.addSourceRoots());
}
public AbstractPythonTestRunConfigurationParams getTestRunConfigurationParams() {
@@ -339,4 +347,24 @@ public abstract class AbstractPythonTestRunConfiguration extends AbstractPythonR
private static boolean pathsEqual(VirtualFile vFile, final String folderName) {
return Comparing.equal(new File(vFile.getPath()).getAbsolutePath(), new File(folderName).getAbsolutePath());
}
@Override
public boolean addSourceRoots() {
return myAddSourceRoots;
}
@Override
public boolean addContentRoots() {
return myAddContentRoots;
}
@Override
public void addSourceRoots(boolean addSourceRoots) {
myAddSourceRoots = addSourceRoots;
}
@Override
public void addContentRoots(boolean addContentRoots) {
myAddContentRoots = addContentRoots;
}
}
@@ -28,4 +28,9 @@ public interface AbstractPythonTestRunConfigurationParams {
String getPattern();
void setPattern(String pattern);
boolean addContentRoots();
boolean addSourceRoots();
void addContentRoots(boolean addContentRoots);
void addSourceRoots(boolean addSourceRoots);
}
@@ -123,6 +123,26 @@ public class PythonTestRunConfigurationForm implements AbstractPythonTestRunConf
myPatternTextField.setText(pattern);
}
@Override
public boolean addContentRoots() {
return myCommonOptionsForm.addContentRoots();
}
@Override
public boolean addSourceRoots() {
return myCommonOptionsForm.addSourceRoots();
}
@Override
public void addContentRoots(boolean addContentRoots) {
myCommonOptionsForm.addContentRoots(addContentRoots);
}
@Override
public void addSourceRoots(boolean addSourceRoots) {
myCommonOptionsForm.addSourceRoots(addSourceRoots);
}
public String getFolderName() {
return toSystemIndependentName(myTestFolderTextField.getText().trim());
}
@@ -3,9 +3,7 @@ package com.jetbrains.python.testing.attest;
import com.intellij.execution.runners.ExecutionEnvironment;
import com.jetbrains.python.testing.PythonTestCommandLineStateBase;
import java.io.File;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
/**
@@ -25,19 +23,6 @@ public class PythonAtTestCommandLineState extends PythonTestCommandLineStateBase
return UTRUNNER_PY;
}
@Override
protected Collection<String> collectPythonPath() {
List<String> pythonPath = new ArrayList<String>(super.collectPythonPath());
// the first entry is the helpers path; add script directory as second entry
if (myConfig.getTestType() == PythonAtTestRunConfiguration.TestType.TEST_FOLDER) {
pythonPath.add(1, myConfig.getFolderName());
}
else {
pythonPath.add(1, new File(myConfig.getScriptName()).getParent());
}
return pythonPath;
}
protected List<String> getTestSpecs() {
List<String> specs = new ArrayList<String>();
@@ -3,9 +3,7 @@ package com.jetbrains.python.testing.doctest;
import com.intellij.execution.runners.ExecutionEnvironment;
import com.jetbrains.python.testing.PythonTestCommandLineStateBase;
import java.io.File;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
/**
@@ -25,19 +23,6 @@ public class PythonDocTestCommandLineState extends PythonTestCommandLineStateBas
return UTRUNNER_PY;
}
@Override
protected Collection<String> collectPythonPath() {
List<String> pythonPath = new ArrayList<String>(super.collectPythonPath());
// the first entry is the helpers path; add script directory as second entry
if (myConfig.getTestType() == PythonDocTestRunConfiguration.TestType.TEST_FOLDER) {
pythonPath.add(1, myConfig.getFolderName());
}
else {
pythonPath.add(1, new File(myConfig.getScriptName()).getParent());
}
return pythonPath;
}
protected List<String> getTestSpecs() {
List<String> specs = new ArrayList<String>();
@@ -7,13 +7,9 @@ import com.intellij.execution.runners.ExecutionEnvironment;
import com.intellij.openapi.util.text.StringUtil;
import com.jetbrains.python.testing.PythonTestCommandLineStateBase;
import java.io.File;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import static com.jetbrains.python.testing.AbstractPythonTestRunConfiguration.TestType.TEST_FOLDER;
/**
* @author Leonid Shalupov
*/
@@ -32,19 +28,6 @@ public class PythonUnitTestCommandLineState extends
return UTRUNNER_PY;
}
@Override
protected Collection<String> collectPythonPath() {
List<String> pythonPath = new ArrayList<String>(super.collectPythonPath());
// the first entry is the helpers path; add script directory as second entry
if (myConfig.getTestType() == TEST_FOLDER) {
pythonPath.add(1, myConfig.getFolderName());
}
else {
pythonPath.add(1, new File(myConfig.getScriptName()).getParent());
}
return pythonPath;
}
protected List<String> getTestSpecs() {
List<String> specs = new ArrayList<String>();