本文整理汇总了Python中behave.userdata.UserData类的典型用法代码示例。如果您正苦于以下问题:Python UserData类的具体用法?Python UserData怎么用?Python UserData使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了UserData类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_getas__with_known_param_and_preconverted_value
def test_getas__with_known_param_and_preconverted_value(self):
userdata = UserData(param=42)
assert "param" in userdata, "ENSURE: known param"
value = userdata.getas(int, "param")
assert isinstance(value, int)
self.assertEqual(value, 42)
示例2: test_getas__with_unknown_param_returns_default_value
def test_getas__with_unknown_param_returns_default_value(self):
userdata = UserData()
assert "param" not in userdata, "ENSURE: unknown param"
value = userdata.getas(int, "param", 123)
assert isinstance(value, int)
self.assertEqual(value, 123)
示例3: test_getas__with_known_param_and_valid_text
def test_getas__with_known_param_and_valid_text(self):
userdata = UserData(param="42")
assert "param" in userdata, "ENSURE: known param"
value = userdata.getas(int, "param")
assert isinstance(value, int)
assert value == 42
示例4: test_userdata_is_dictlike
def test_userdata_is_dictlike(self):
userdata = UserData(name="Foo", number=42)
value1 = userdata["name"]
value2 = userdata.get("number")
value3 = userdata.get("unknown", Unknown)
assert isinstance(userdata, dict)
self.assertEqual(value1, "Foo")
self.assertEqual(value2, 42)
assert value3 is Unknown
示例5: test_getas__with_known_param_and_preconverted_value_and_valuetype
def test_getas__with_known_param_and_preconverted_value_and_valuetype(self):
userdata = UserData(param=42)
assert "param" in userdata, "ENSURE: known param"
def parse_int(text):
return int(text)
value = userdata.getas(parse_int, "param", valuetype=int)
assert isinstance(value, int)
self.assertEqual(value, 42)
示例6: test_getbool__with_known_param_and_valid_text
def test_getbool__with_known_param_and_valid_text(self):
for true_text in ["true", "TRUE", "True", "yes", "on", "1"]:
userdata = UserData(param=true_text)
value = userdata.getbool("param")
assert isinstance(value, bool), "text=%s" % true_text
self.assertEqual(value, True)
for false_text in ["false", "FALSE", "False", "no", "off", "0"]:
userdata = UserData(param=false_text)
value = userdata.getbool("param")
assert isinstance(value, bool), "text=%s" % false_text
self.assertEqual(value, False)
示例7: test_getbool__with_unknown_param_returns_default_value
def test_getbool__with_unknown_param_returns_default_value(self):
userdata = UserData()
value = userdata.getint("param", 1.2)
assert isinstance(value, float)
self.assertEqual(value, 1.2)
示例8: test_getbool__with_unknown_param_without_default_returns_false
def test_getbool__with_unknown_param_without_default_returns_false(self):
userdata = UserData()
value = userdata.getfloat("param")
self.assertEqual(value, False)
示例9: test_getint__with_unknown_param_returns_default_value
def test_getint__with_unknown_param_returns_default_value(self):
userdata = UserData()
value = userdata.getint("param", 123)
assert isinstance(value, int)
assert value == 123
示例10: Configuration
#.........这里部分代码省略.........
"""
# -- NOTE: re.LOCALE is removed in Python 3.6 (deprecated in Python 3.5)
# flags = (re.UNICODE | re.LOCALE)
pattern = u"|".join(names)
return re.compile(pattern, flags=re.UNICODE)
def exclude(self, filename):
if isinstance(filename, FileLocation):
filename = six.text_type(filename)
if self.include_re and self.include_re.search(filename) is None:
return True
if self.exclude_re and self.exclude_re.search(filename) is not None:
return True
return False
def setup_logging(self, level=None, configfile=None, **kwargs):
"""
Support simple setup of logging subsystem.
Ensures that the logging level is set.
But note that the logging setup can only occur once.
SETUP MODES:
* :func:`logging.config.fileConfig()`, if ``configfile`` is provided.
* :func:`logging.basicConfig()`, otherwise.
.. code-block: python
# -- FILE: features/environment.py
def before_all(context):
context.config.setup_logging()
:param level: Logging level of root logger.
If None, use :attr:`logging_level` value.
:param configfile: Configuration filename for fileConfig() setup.
:param kwargs: Passed to :func:`logging.basicConfig()`
"""
if level is None:
level = self.logging_level # pylint: disable=no-member
if configfile:
from logging.config import fileConfig
fileConfig(configfile)
else:
# pylint: disable=no-member
format_ = kwargs.pop("format", self.logging_format)
datefmt = kwargs.pop("datefmt", self.logging_datefmt)
logging.basicConfig(format=format_, datefmt=datefmt, **kwargs)
# -- ENSURE: Default log level is set
# (even if logging subsystem is already configured).
logging.getLogger().setLevel(level)
def setup_model(self):
if self.scenario_outline_annotation_schema:
name_schema = six.text_type(self.scenario_outline_annotation_schema)
ScenarioOutline.annotation_schema = name_schema.strip()
def setup_stage(self, stage=None):
"""Setup the test stage that selects a different set of
steps and environment implementations.
:param stage: Name of current test stage (as string or None).
EXAMPLE::
# -- SETUP DEFAULT TEST STAGE (unnamed):
config = Configuration()
config.setup_stage()
assert config.steps_dir == "steps"
assert config.environment_file == "environment.py"
# -- SETUP PRODUCT TEST STAGE:
config.setup_stage("product")
assert config.steps_dir == "product_steps"
assert config.environment_file == "product_environment.py"
"""
steps_dir = "steps"
environment_file = "environment.py"
if stage:
# -- USE A TEST STAGE: Select different set of implementations.
prefix = stage + "_"
steps_dir = prefix + steps_dir
environment_file = prefix + environment_file
self.steps_dir = steps_dir
self.environment_file = environment_file
def setup_userdata(self):
if not isinstance(self.userdata, UserData):
self.userdata = UserData(self.userdata)
if self.userdata_defines:
# -- ENSURE: Cmd-line overrides configuration file parameters.
self.userdata.update(self.userdata_defines)
def update_userdata(self, data):
"""Update userdata with data and reapply userdata defines (cmdline).
:param data: Provides (partial) userdata (as dict)
"""
self.userdata.update(data)
if self.userdata_defines:
# -- REAPPLY: Cmd-line defines (override configuration file data).
self.userdata.update(self.userdata_defines)
示例11: test_getint__with_known_param_and_valid_text
def test_getint__with_known_param_and_valid_text(self):
userdata = UserData(param="42")
value = userdata.getint("param")
assert isinstance(value, int)
self.assertEqual(value, 42)
示例12: test_getas__with_known_param_and_invalid_text_raises_ValueError
def test_getas__with_known_param_and_invalid_text_raises_ValueError(self):
userdata = UserData(param="__BAD_NUMBER__")
assert "param" in userdata, "ENSURE: known param"
with pytest.raises(ValueError):
userdata.getas(int, "param")
示例13: test_getbool__with_known_param_and_invalid_text_raises_ValueError
def test_getbool__with_known_param_and_invalid_text_raises_ValueError(self):
userdata = UserData(param="__BAD_VALUE__")
with pytest.raises(ValueError):
userdata.getbool("param")
示例14: test_getbool__with_known_param_and_valid_false_text
def test_getbool__with_known_param_and_valid_false_text(self, text):
false_text = text
userdata = UserData(param=false_text)
value = userdata.getbool("param")
assert isinstance(value, bool), "text=%s" % false_text
assert value is False
示例15: test_getfloat__with_known_param_and_invalid_text_raises_ValueError
def test_getfloat__with_known_param_and_invalid_text_raises_ValueError(self):
userdata = UserData(param="__BAD_NUMBER__")
with pytest.raises(ValueError):
userdata.getfloat("param")