From 155a8c5f3b4638a1a7dfe5b252cd9f761e9cd365 Mon Sep 17 00:00:00 2001 From: "Ilya.Kazakevich" Date: Fri, 25 Jul 2014 02:24:15 +0400 Subject: [PATCH] PY-8427 Behave BDD support PY-4186 Lettuce BDD tool support Cofiguration producers added --- .../FileChooserDescriptorFactory.java | 27 +++++++++++++++---- python/helpers/pycharm/_bdd_utils.py | 11 ++++++++ python/helpers/pycharm/behave_runner.py | 21 +++++++++++++-- python/helpers/pycharm/lettuce_runner.py | 2 ++ 4 files changed, 54 insertions(+), 7 deletions(-) diff --git a/platform/platform-api/src/com/intellij/openapi/fileChooser/FileChooserDescriptorFactory.java b/platform/platform-api/src/com/intellij/openapi/fileChooser/FileChooserDescriptorFactory.java index 1e43287a1d94..c958dbca878e 100644 --- a/platform/platform-api/src/com/intellij/openapi/fileChooser/FileChooserDescriptorFactory.java +++ b/platform/platform-api/src/com/intellij/openapi/fileChooser/FileChooserDescriptorFactory.java @@ -19,9 +19,11 @@ import com.intellij.openapi.fileTypes.FileType; import com.intellij.openapi.util.SystemInfo; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.ui.UIBundle; +import org.jetbrains.annotations.NotNull; public class FileChooserDescriptorFactory { - private FileChooserDescriptorFactory() { } + private FileChooserDescriptorFactory() { + } public static FileChooserDescriptor createAllButJarContentsDescriptor() { return new FileChooserDescriptor(true, true, true, true, false, true); @@ -83,7 +85,18 @@ public class FileChooserDescriptorFactory { } public static FileChooserDescriptor createSingleFileDescriptor(final FileType fileType) { - return new FileChooserDescriptor(true, false, false, false, false, false) { + return createSingleFileDescriptor(fileType, false); + } + + /** + * Creates file descriptor with certain type and (possible) folders. + * @param fileType supported type + * @param supportDirectories support directories or not + * @return descriptor + */ + @NotNull + public static FileChooserDescriptor createSingleFileDescriptor(final FileType fileType, final boolean supportDirectories) { + return new FileChooserDescriptor(true, supportDirectories, false, false, false, false) { @Override public boolean isFileVisible(final VirtualFile file, final boolean showHiddenFiles) { return file.isDirectory() || file.getFileType() == fileType; @@ -91,18 +104,22 @@ public class FileChooserDescriptorFactory { @Override public boolean isFileSelectable(final VirtualFile file) { - return super.isFileSelectable(file) && file.getFileType() == fileType; + return super.isFileSelectable(file) && (file.getFileType() == fileType || ((file.isDirectory() && supportDirectories))); } }; } - /** @deprecated use {@link #createSingleFileNoJarsDescriptor()} (to be removed in IDEA 15) */ + /** + * @deprecated use {@link #createSingleFileNoJarsDescriptor()} (to be removed in IDEA 15) + */ @SuppressWarnings({"UnusedDeclaration", "deprecation"}) public static FileChooserDescriptorBuilder onlyFiles() { return FileChooserDescriptorBuilder.onlyFiles(); } - /** @deprecated use {@link #createSingleFileOrFolderDescriptor()} ()} (to be removed in IDEA 15) */ + /** + * @deprecated use {@link #createSingleFileOrFolderDescriptor()} ()} (to be removed in IDEA 15) + */ @SuppressWarnings({"UnusedDeclaration", "deprecation"}) public static FileChooserDescriptorBuilder filesAndFolders() { return FileChooserDescriptorBuilder.filesAndFolders(); diff --git a/python/helpers/pycharm/_bdd_utils.py b/python/helpers/pycharm/_bdd_utils.py index 73f1d5ebd043..4b11748999f3 100644 --- a/python/helpers/pycharm/_bdd_utils.py +++ b/python/helpers/pycharm/_bdd_utils.py @@ -69,6 +69,17 @@ class BddRunner(object): """ return "file:///{}/{}:{}".format(self.__base_dir, location.file, location.line) + def _test_undefined(self, test_name, location): + """ + Mark test as undefined + :param test_name: name of test + :type test_name str + :param location its location + + """ + self._test_started(test_name, location) + self._test_failed(test_name, message="Test undefined", details="Please define test") + def _test_failed(self, name, message, details): """ Report test failure diff --git a/python/helpers/pycharm/behave_runner.py b/python/helpers/pycharm/behave_runner.py index 115c8355c70f..ca4b673fb794 100644 --- a/python/helpers/pycharm/behave_runner.py +++ b/python/helpers/pycharm/behave_runner.py @@ -11,7 +11,7 @@ import os import traceback from behave.formatter.base import Formatter -from behave.model import Step, ScenarioOutline, Feature +from behave.model import Step, ScenarioOutline, Feature, Scenario import _bdd_utils @@ -120,6 +120,16 @@ class _BehaveRunner(_bdd_utils.BddRunner): BddRunner for behave """ + @staticmethod + def __fix_location(element): + """ + Adds "filename" alias to "file" to preserve _bdd_utils contract + :param element: location + :return: fixed location + """ + element.location.file = element.location.filename + return element + def __process_hook(self, is_started, context, element): """ Hook to be installed. Reports steps, features etc. @@ -129,7 +139,7 @@ class _BehaveRunner(_bdd_utils.BddRunner): :type context behave.runner.Context :param element feature/suite/step """ - element.location.file = element.location.filename # To preserve _bdd_utils contract + _BehaveRunner.__fix_location(element) # To preserve _bdd_utils contract if isinstance(element, Step): # Process step if is_started: @@ -140,6 +150,13 @@ class _BehaveRunner(_bdd_utils.BddRunner): self._test_failed(element.name, element.error_message, traceback.format_exc()) else: self.tc_messages.testIgnored(element.name, "Skipped with status: {}".format(element.status)) + elif not is_started and isinstance(element, Scenario) and element.status == 'failed': + # To process scenarios with undefined tests + # TODO: refactor + for step in [s for s in element.steps if s.status == 'undefined']: + assert isinstance(step, Step), step + self._test_undefined(step.name, _BehaveRunner.__fix_location(step).location) + self._feature_or_scenario(is_started, element.name, element.location) elif isinstance(element, ScenarioOutline): self._feature_or_scenario(is_started, str(element.examples), element.location) else: diff --git a/python/helpers/pycharm/lettuce_runner.py b/python/helpers/pycharm/lettuce_runner.py index 3dfe490d27c3..6a3558bc8f44 100644 --- a/python/helpers/pycharm/lettuce_runner.py +++ b/python/helpers/pycharm/lettuce_runner.py @@ -59,6 +59,8 @@ class _LettuceRunner(_bdd_utils.BddRunner): reason = step.why assert isinstance(reason, ReasonToFail), reason self._test_failed(test_name, message=reason.exception, details=reason.traceback) + else: + self._test_undefined(test_name, step.described_at) def __install_hooks(self): """