| 1 |
# -*- coding: UTF-8 -*- |
| 2 |
# -- FILE: features/steps/fixture_steps.py |
| 3 |
|
| 4 |
from __future__ import print_function |
| 5 |
from behave import when |
| 6 |
import os |
| 7 |
import sys |
| 8 |
|
| 9 |
# XXX |
| 10 |
# # -- VARIANT 1: |
| 11 |
# @when(u'I click on ${environment_variable:w}') |
| 12 |
# def step_impl(context, environment_variable): |
| 13 |
# env_value = os.environ.get(environment_variable, None) |
| 14 |
# if env_value is None: |
| 15 |
# raise LookupError("Environment variable '%s' is undefined" % environment_variable) |
| 16 |
# print("USE ENVIRONMENT-VAR: %s = %s (variant 1)" % (environment_variable, env_value)) |
| 17 |
# |
| 18 |
# |
| 19 |
# # -- VARIANT 2: Use type converter |
| 20 |
# from behave import register_type |
| 21 |
# import parse |
| 22 |
# |
| 23 |
# @parse.with_pattern(r"\$\w+") # -- ONLY FOR: $WORD |
| 24 |
# def parse_environment_var(text): |
| 25 |
# assert text.startswith("$") |
| 26 |
# env_name = text[1:] |
| 27 |
# env_value = os.environ.get(env_name, None) |
| 28 |
# return (env_name, env_value) |
| 29 |
# |
| 30 |
# register_type(EnvironmentVar=parse_environment_var) |
| 31 |
# |
| 32 |
# @when(u'I use the environment variable {environment_variable:EnvironmentVar}') |
| 33 |
# def step_impl(context, environment_variable): |
| 34 |
# env_name, env_value = environment_variable |
| 35 |
# if env_value is None: |
| 36 |
# raise LookupError("Environment variable '%s' is undefined" % env_name) |
| 37 |
# print("USE ENVIRONMENT-VAR: %s = %s (variant 2)" \ |
| 38 |
# % (env_name, env_value)) |
| 39 |
# |