Skip to content

Commit 44fe343

Browse files
committed
UPDATE TO: behave v1.2.7.dev6
* Adapt steps that need trailing colon now (use: ctx.table, ctx.text) * environment.py: Show enviroment contet from active_tag.values * USE: .envrc.use_venv for auto-setup a virtual environment
1 parent 06f4a74 commit 44fe343

23 files changed

+304
-52
lines changed

.envrc

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,31 @@
11
# ===========================================================================
2-
# PROJECT ENVIRONMENT SETUP: behave.example/.envrc
2+
# PROJECT ENVIRONMENT SETUP: .envrc
33
# ===========================================================================
44
# SHELL: bash (or similiar)
5-
# SEE ALSO: https://direnv.net/
5+
# REQUIRES: direnv >= 2.21.0 -- NEEDED FOR: path_add, venv support
66
# USAGE:
7-
# source .envrc
8-
#
9-
# # -- BETTER: Use direnv (requires: Setup in bash / HOME/.bashrc)
10-
# # eval "$(direnv hook bash)"
7+
# # -- BETTER: Use direnv (requires: Setup in bash -- $HOME/.bashrc)
8+
# # BASH PROFILE NEEDS: eval "$(direnv hook bash)"
119
# direnv allow .
10+
#
11+
# SEE ALSO:
12+
# * https://direnv.net/
13+
# * https://github.com/direnv/direnv
14+
# * https://peps.python.org/pep-0582/ Python local packages directory
1215
# ===========================================================================
16+
# MAYBE: HERE="${PWD}"
17+
18+
# -- USE OPTIONAL PARTS (if exist/enabled):
19+
# REQUIRES: direnv >= 2.26.0 -- NEEDED FOR: dotenv_if_exists
20+
# DISABLED: dotenv_if_exists .env
21+
source_env_if_exists .envrc.use_venv
1322

1423
export TOPDIR="$PWD"
15-
export PYTHONPATH=".:$TOPDIR:$TOPDIR/lib/python:${PYTHONPATH}"
16-
export PATH=".:$TOPDIR/bin:$PATH"
24+
25+
# -- SETUP-PYTHON: Prepend ${HERE} to PYTHONPATH (as PRIMARY search path)
26+
# SIMILAR TO: export PYTHONPATH="${HERE}:${PYTHONPATH}"
27+
path_add PYTHONPATH lib/python
28+
path_add PYTHONPATH .
29+
path_add PATH bin
30+
31+
source_env_if_exists .envrc.override

.envrc.use_venv

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# ===========================================================================
2+
# PROJECT ENVIRONMENT SETUP: .envrc.use_venv
3+
# ===========================================================================
4+
# REQUIRES: direnv >= 2.21.0 -- NEEDED FOR: venv support
5+
# DESCRIPTION:
6+
# Setup and use a Python virtual environment (venv).
7+
# On entering the directory: Creates and activates a venv for a python version.
8+
# On leaving the directory: Deactivates the venv (virtual environment).
9+
#
10+
# ENABLE/DISABLE THIS OPTIONAL PART:
11+
# * TO ENABLE: Rename ".envrc.use_venv.disabled" to ".envrc.use_venv"
12+
# * TO DISABLE: Rename ".envrc.use_venv" to ".envrc.use_venv.disabled"
13+
#
14+
# SEE ALSO:
15+
# * https://direnv.net/
16+
# * https://github.com/direnv/direnv/wiki/Python
17+
# * https://direnv.net/man/direnv-stdlib.1.html#codelayout-python-ltpythonexegtcode
18+
# ===========================================================================
19+
20+
# -- VIRTUAL ENVIRONMENT SUPPORT: layout python python3
21+
# VENV LOCATION: .direnv/python-$(PYTHON_VERSION)
22+
layout python python3

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
*.pyo
44
.DS_Store
55
.coverage
6+
.direnv/
67
.idea/
78
.tox/
89
.venv*/

datatype.features/environment.py

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,38 @@
1-
# -*- coding: utf--8 -*-
1+
# -*- coding: UTF-8 -*-
2+
3+
import behave.active_tag.python
4+
import behave.active_tag.python_feature
5+
from behave.fixture import use_fixture_by_tag
6+
from behave.tag_matcher import (
7+
ActiveTagMatcher, setup_active_tag_values, print_active_tags
8+
)
9+
10+
11+
# -----------------------------------------------------------------------------
12+
# ACTIVE TAGS:
13+
# -----------------------------------------------------------------------------
14+
# -- MATCHES ANY TAGS: @use.with_{category}={value}
15+
# NOTE: active_tag_value_provider provides category values for active tags.
16+
active_tag_value_provider = {}
17+
active_tag_value_provider.update(behave.active_tag.python.ACTIVE_TAG_VALUE_PROVIDER)
18+
active_tag_value_provider.update(behave.active_tag.python_feature.ACTIVE_TAG_VALUE_PROVIDER)
19+
active_tag_matcher = ActiveTagMatcher(active_tag_value_provider)
20+
21+
22+
def print_active_tags_summary():
23+
print_active_tags(active_tag_value_provider, ["python.version", "os"])
24+
25+
26+
# -----------------------------------------------------------------------------
227
# -- SETUP: Use cfparse as default matcher
28+
# -----------------------------------------------------------------------------
329
from behave import use_step_matcher
430
use_step_matcher("cfparse")
31+
32+
33+
# -----------------------------------------------------------------------------
34+
# HOOKS:
35+
# -----------------------------------------------------------------------------
36+
def before_all(context):
37+
context.config.setup_logging()
38+
print_active_tags_summary()

datatype.features/steps/step_cardinality_one_or_more.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ def step_when_I_meet_person_and_more(context, persons):
8080
def step_given_I_go_to_meeting(context):
8181
context.meeting = Meeting()
8282

83-
@then('the following persons are present')
83+
@then('the following persons are present:')
8484
def step_following_persons_are_present(context):
8585
assert context.table, "table<Person> is required"
8686
actual_persons = sorted(context.meeting.persons)

datatype.features/steps/step_cardinality_zero_or_more.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def step_given_I_am_a_painter(context):
7878
def step_then_no_colors_are_used(context):
7979
assert_that(context.used_colors, has_length(0))
8080

81-
@then('the following colors are used')
81+
@then('the following colors are used:')
8282
def step_then_following_colors_are_used(context):
8383
assert context.table, "table<color> is required"
8484
used_colors = sorted(context.used_colors)

features/environment.py

Lines changed: 45 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,58 @@
11
# -*- coding: UTF-8 -*-
22
"""
3-
before_step(context, step), after_step(context, step)
4-
These run before and after every step.
5-
The step passed in is an instance of Step.
3+
.. code::
64
7-
before_scenario(context, scenario), after_scenario(context, scenario)
8-
These run before and after each scenario is run.
9-
The scenario passed in is an instance of Scenario.
5+
# -- HOOKS:
6+
before_step(context, step), after_step(context, step)
7+
These run before and after every step.
8+
The step passed in is an instance of Step.
109
11-
before_feature(context, feature), after_feature(context, feature)
12-
These run before and after each feature file is exercised.
13-
The feature passed in is an instance of Feature.
10+
before_scenario(context, scenario), after_scenario(context, scenario)
11+
These run before and after each scenario is run.
12+
The scenario passed in is an instance of Scenario.
1413
15-
before_tag(context, tag), after_tag(context, tag)
14+
before_feature(context, feature), after_feature(context, feature)
15+
These run before and after each feature file is exercised.
16+
The feature passed in is an instance of Feature.
1617
18+
before_tag(context, tag), after_tag(context, tag)
19+
These run before and after any new tag of a model-element.
1720
"""
1821

22+
23+
import behave.active_tag.python
24+
import behave.active_tag.python_feature
25+
from behave.fixture import use_fixture_by_tag
26+
from behave.tag_matcher import (
27+
ActiveTagMatcher, setup_active_tag_values, print_active_tags
28+
)
29+
30+
31+
# -----------------------------------------------------------------------------
32+
# ACTIVE TAGS:
33+
# -----------------------------------------------------------------------------
34+
# -- MATCHES ANY TAGS: @use.with_{category}={value}
35+
# NOTE: active_tag_value_provider provides category values for active tags.
36+
active_tag_value_provider = {}
37+
active_tag_value_provider.update(behave.active_tag.python.ACTIVE_TAG_VALUE_PROVIDER)
38+
active_tag_value_provider.update(behave.active_tag.python_feature.ACTIVE_TAG_VALUE_PROVIDER)
39+
active_tag_matcher = ActiveTagMatcher(active_tag_value_provider)
40+
41+
42+
def print_active_tags_summary():
43+
print_active_tags(active_tag_value_provider, ["python.version", "os"])
44+
45+
46+
# -----------------------------------------------------------------------------
1947
# -- SETUP: Use cfparse as default matcher
48+
# -----------------------------------------------------------------------------
2049
# from behave import use_step_matcher
21-
# step_matcher("cfparse")
50+
# use_step_matcher("cfparse")
51+
2252

53+
# -----------------------------------------------------------------------------
54+
# HOOKS:
55+
# -----------------------------------------------------------------------------
2356
def before_all(context):
2457
context.config.setup_logging()
58+
print_active_tags_summary()

features/steps/step_tutorial05.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def seems_like_language(self):
4444
from behave import given, when, then
4545
from hamcrest import assert_that, equal_to
4646

47-
@given('a sample text loaded into the frobulator')
47+
@given('a sample text loaded into the frobulator:')
4848
def step_impl(context):
4949
frobulator = getattr(context, "frobulator", None)
5050
if not frobulator:

features/steps/step_tutorial06.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
from testutil import NamedNumber
2626
from company_model import CompanyModel
2727

28-
@given('a set of specific users')
28+
@given('a set of specific users:')
2929
def step_impl(context):
3030
model = getattr(context, "model", None)
3131
if not model:

features/steps/step_tutorial07.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
from hamcrest.library.collection.issequence_containinginanyorder \
4444
import contains_inanyorder
4545

46-
@then('we will have the following people in "{department}"')
46+
@then('we will have the following people in "{department}":')
4747
def step_impl(context, department):
4848
"""
4949
Compares expected with actual persons in a department.
@@ -59,7 +59,7 @@ def step_impl(context, department):
5959
# -- UNORDERED TABLE-COMPARISON (using: pyhamcrest)
6060
assert_that(contains_inanyorder(*expected_persons), actual_persons)
6161

62-
@then('we will have at least the following people in "{department}"')
62+
@then('we will have at least the following people in "{department}":')
6363
def step_impl(context, department):
6464
"""
6565
Compares subset of persons with actual persons in a department.

0 commit comments

Comments
 (0)