| 1 |
# -*- coding: UTF-8 -*- |
| •2 |
# FILE: issue.features/environemnt.py |
| 3 |
# pylint: disable=unused-argument |
| 4 |
""" |
| 5 |
Functionality: |
| 6 |
|
| 7 |
* active tags |
| 8 |
""" |
| 9 |
|
| •10 |
|
| 11 |
from __future__ import absolute_import, print_function |
| 12 |
import sys |
| 13 |
import platform |
| 14 |
import os.path |
| 15 |
import six |
| 16 |
from behave.tag_matcher import ActiveTagMatcher |
| 17 |
from behave4cmd0.setup_command_shell import setup_command_shell_processors4behave |
| •18 |
# PREPARED: from behave.tag_matcher import setup_active_tag_values |
| 19 |
|
| 20 |
|
| •21 |
# --------------------------------------------------------------------------- |
| 22 |
# TEST SUPPORT: For Active Tags |
| 23 |
# --------------------------------------------------------------------------- |
| 24 |
def require_tool(tool_name): |
| 25 |
"""Check if a tool (an executable program) is provided on this platform. |
| 26 |
|
| 27 |
:params tool_name: Name of the tool to check if it is available. |
| 28 |
:return: True, if tool is found. |
| 29 |
:return: False, if tool is not available (or not in search path). |
| 30 |
""" |
| 31 |
# print("CHECK-TOOL: %s" % tool_name) |
| 32 |
path = os.environ.get("PATH") |
| 33 |
if not path: |
| 34 |
return False |
| 35 |
|
| 36 |
for searchdir in path.split(os.pathsep): |
| 37 |
executable1 = os.path.normpath(os.path.join(searchdir, tool_name)) |
| 38 |
executables = [executable1] |
| 39 |
if sys.platform.startswith("win"): |
| 40 |
executables.append(executable1 + ".exe") |
| 41 |
|
| 42 |
for executable in executables: |
| 43 |
# print("TOOL-CHECK: %s" % os.path.abspath(executable)) |
| 44 |
if os.path.isfile(executable): |
| 45 |
# print("TOOL-FOUND: %s" % os.path.abspath(executable)) |
| 46 |
return True |
| 47 |
# -- OTHERWISE: Tool not found |
| 48 |
# print("TOOL-NOT-FOUND: %s" % tool_name) |
| 49 |
return False |
| 50 |
|
| •51 |
|
| 52 |
def as_bool_string(value): |
| 53 |
if bool(value): |
| 54 |
return "yes" |
| 55 |
else: |
| 56 |
return "no" |
| 57 |
|
| •58 |
|
| 59 |
def discover_ci_server(): |
| 60 |
# pylint: disable=invalid-name |
| 61 |
ci_server = "none" |
| 62 |
CI = os.environ.get("CI", "false").lower() == "true" |
| 63 |
APPVEYOR = os.environ.get("APPVEYOR", "false").lower() == "true" |
| 64 |
TRAVIS = os.environ.get("TRAVIS", "false").lower() == "true" |
| 65 |
if CI: |
| 66 |
if APPVEYOR: |
| 67 |
ci_server = "appveyor" |
| 68 |
elif TRAVIS: |
| 69 |
ci_server = "travis" |
| 70 |
else: |
| 71 |
ci_server = "unknown" |
| 72 |
return ci_server |
| 73 |
|
| 74 |
|
| •75 |
# --------------------------------------------------------------------------- |
| 76 |
# BEHAVE SUPPORT: Active Tags |
| 77 |
# --------------------------------------------------------------------------- |
| 78 |
# -- MATCHES ANY TAGS: @use.with_{category}={value} |
| 79 |
# NOTE: active_tag_value_provider provides category values for active tags. |
| •80 |
python_version = "%s.%s" % sys.version_info[:2] |
| 81 |
active_tag_value_provider = { |
| 82 |
"python2": str(six.PY2).lower(), |
| 83 |
"python3": str(six.PY3).lower(), |
| •84 |
"python.version": python_version, |
| 85 |
# -- python.implementation: cpython, pypy, jython, ironpython |
| 86 |
"python.implementation": platform.python_implementation().lower(), |
| 87 |
"pypy": str("__pypy__" in sys.modules).lower(), |
| 88 |
"os": sys.platform, |
| 89 |
"xmllint": as_bool_string(require_tool("xmllint")), |
| 90 |
"ci": discover_ci_server() |
| 91 |
} |
| 92 |
active_tag_matcher = ActiveTagMatcher(active_tag_value_provider) |
| 93 |
|
| •94 |
|
| 95 |
def print_active_tags_summary(): |
| 96 |
active_tag_data = active_tag_value_provider |
| 97 |
print("ACTIVE-TAG SUMMARY:") |
| 98 |
print("use.with_python.version=%s" % active_tag_data.get("python.version")) |
| 99 |
# print("use.with_platform=%s" % active_tag_data.get("platform")) |
| 100 |
# print("use.with_os=%s" % active_tag_data.get("os")) |
| 101 |
print() |
| 102 |
|
| 103 |
|
| 104 |
# --------------------------------------------------------------------------- |
| 105 |
# BEHAVE HOOKS: |
| 106 |
# --------------------------------------------------------------------------- |
| 107 |
def before_all(context): |
| 108 |
# -- SETUP ACTIVE-TAG MATCHER (with userdata): |
| 109 |
# USE: behave -D browser=safari ... |
| •110 |
# NOT-NEEDED: |
| 111 |
# setup_active_tag_values(active_tag_value_provider, context.config.userdata) |
| 112 |
setup_command_shell_processors4behave() |
| •113 |
print_active_tags_summary() |
| 114 |
|
| 115 |
|
| 116 |
def before_feature(context, feature): |
| 117 |
if active_tag_matcher.should_exclude_with(feature.tags): |
| 118 |
feature.skip(reason=active_tag_matcher.exclude_reason) |
| 119 |
|
| •120 |
|
| 121 |
def before_scenario(context, scenario): |
| 122 |
if active_tag_matcher.should_exclude_with(scenario.effective_tags): |
| 123 |
scenario.skip(reason=active_tag_matcher.exclude_reason) |