コード例 #1
0
def check_strict_key(value, rule_obj, path):
    """Make sure the 'strict' key is either a bool or a list"""
    # pylint: disable=unused-argument

    if not isinstance(value, list) and not is_bool_like(value):
        raise BadSchemaError("'strict' has to be either a boolean or a list")
    elif isinstance(value, list):
        try:
            # Reuse validation here
            StrictLevel.from_options(value)
        except exceptions.InvalidConfigurationException as e:
            raise BadSchemaError from e

    # Might be a bool as well, in which case it's processed further down the line - no validation required

    return True
コード例 #2
0
ファイル: core.py プロジェクト: sohoffice/tavern
def _calculate_stage_strictness(stage, test_block_config, test_spec):
    """Figure out the strictness for this stage

    Can be overridden per stage, or per test

    Priority is global (see pytest util file) <= test <= stage
    """
    stage_options = None

    if test_spec.get("strict", None) is not None:
        stage_options = test_spec["strict"]

    if stage.get("response", {}).get("strict", None) is not None:
        stage_options = stage["response"]["strict"]
    elif stage.get("mqtt_response", {}).get("strict", None) is not None:
        stage_options = stage["mqtt_response"]["strict"]

    if stage_options is not None:
        logger.debug("Overriding global strictness")
        if stage_options is True:
            strict_level = StrictLevel.all_on()
        elif stage_options is False:
            strict_level = StrictLevel.all_off()
        else:
            strict_level = StrictLevel.from_options(stage_options)

        test_block_config["strict"] = strict_level
    else:
        logger.debug("Global default strictness used for this stage")

    logger.debug("Strict key checking for this stage is '%s'",
                 test_block_config["strict"])
コード例 #3
0
ファイル: test_helpers.py プロジェクト: taverntesting/tavern
    def test_unset(self, section):
        level = StrictLevel.from_options([section])

        assert level.setting_for(section).setting == StrictSetting.UNSET
コード例 #4
0
ファイル: test_helpers.py プロジェクト: taverntesting/tavern
    def test_set_off(self, section):
        level = StrictLevel.from_options([section + ":off"])

        assert level.setting_for(section).setting == StrictSetting.OFF
        assert not level.setting_for(section).is_on()
コード例 #5
0
    def test_set_on(self, section):
        level = StrictLevel.from_options([section + ":on"])

        assert level.setting_for(section).setting == _StrictSetting.ON
        assert level.setting_for(section).is_on()
コード例 #6
0
def _load_global_strictness(pytest_config):
    """Load the global 'strictness' setting"""

    options = get_option_generic(pytest_config, "tavern-strict", [])

    return StrictLevel.from_options(options)