Debian Codegraph @

features/environment.py

raw ◀ ▶
1 Debian patch touch this file
1 # -*- coding: UTF-8 -*-
•2 # FILE: features/environemnt.py
3
•4 from __future__ import absolute_import, print_function
5 from behave.tag_matcher import ActiveTagMatcher, setup_active_tag_values
6 from behave4cmd0.setup_command_shell import setup_command_shell_processors4behave
7 import platform
8 import sys
9 import six
10
11 # -- MATCHES ANY TAGS: @use.with_{category}={value}
12 # NOTE: active_tag_value_provider provides category values for active tags.
13 python_version = "%s.%s" % sys.version_info[:2]
14 active_tag_value_provider = {
15 "python2": str(six.PY2).lower(),
16 "python3": str(six.PY3).lower(),
17 "python.version": python_version,
18 # -- python.implementation: cpython, pypy, jython, ironpython
19 "python.implementation": platform.python_implementation().lower(),
20 "pypy": str("__pypy__" in sys.modules).lower(),
21 "os": sys.platform,
22 }
23 active_tag_matcher = ActiveTagMatcher(active_tag_value_provider)
24
•25
26 def print_active_tags_summary():
27 active_tag_data = active_tag_value_provider
28 print("ACTIVE-TAG SUMMARY:")
29 print("use.with_python.version=%s" % active_tag_data.get("python.version"))
30 # print("use.with_os=%s" % active_tag_data.get("os"))
31 print()
32
33
34 # -----------------------------------------------------------------------------
35 # HOOKS:
36 # -----------------------------------------------------------------------------
37 def before_all(context):
38 # -- SETUP ACTIVE-TAG MATCHER (with userdata):
39 # USE: behave -D browser=safari ...
40 setup_active_tag_values(active_tag_value_provider, context.config.userdata)
41 setup_python_path()
42 setup_context_with_global_params_test(context)
43 setup_command_shell_processors4behave()
•44 print_active_tags_summary()
45
46
47 def before_feature(context, feature):
48 if active_tag_matcher.should_exclude_with(feature.tags):
49 feature.skip(reason=active_tag_matcher.exclude_reason)
50
•51
52 def before_scenario(context, scenario):
53 if active_tag_matcher.should_exclude_with(scenario.effective_tags):
54 scenario.skip(reason=active_tag_matcher.exclude_reason)
55
56 # -----------------------------------------------------------------------------
57 # SPECIFIC FUNCTIONALITY:
58 # -----------------------------------------------------------------------------
59 def setup_context_with_global_params_test(context):
60 context.global_name = "env:Alice"
61 context.global_age = 12
62
63 def setup_python_path():
64 # -- NEEDED-FOR: formatter.user_defined.feature
65 import os
66 PYTHONPATH = os.environ.get("PYTHONPATH", "")
67 os.environ["PYTHONPATH"] = "."+ os.pathsep + PYTHONPATH