Skip to content

test_parser_depth_average_rule

Tests for ParserDepthAverageRule class

test_parse_dict_to_rule_data_logic()

Test if a correct dictionary is parsed into a RuleData object

Source code in tests/data/parsers/test_parser_depth_average_rule.py
def test_parse_dict_to_rule_data_logic():
    """Test if a correct dictionary is parsed into a RuleData object"""
    # Arrange
    contents = {
        "name": "testname",
        "input_variable": "input",
        "bed_level_variable": "bedlevel",
        "water_level_variable": "waterlevel",
        "interfaces_variable": "interfaces",
        "output_variable": "output",
    }
    logger = Mock(ILogger)
    # Act
    data = ParserDepthAverageRule()
    parsed_dict = data.parse_dict(contents, logger)

    assert isinstance(parsed_dict, IRuleData)

test_parse_wrong_dict_to_rule_data_logic()

Test if an incorrect dictionary is not parsed

Source code in tests/data/parsers/test_parser_depth_average_rule.py
def test_parse_wrong_dict_to_rule_data_logic():
    """Test if an incorrect dictionary is not parsed"""
    # Arrange
    contents = {
        "name": "testname",
        "output_variable": "output",
        "bed_level_variable": "bedlevel",
        "water_level_variable": "waterlevel",
        "interfaces_variable": "interfaces_z",
    }
    logger = Mock(ILogger)

    # Act
    data = ParserDepthAverageRule()

    with pytest.raises(AttributeError) as exc_info:
        data.parse_dict(contents, logger)

    exception_raised = exc_info.value

    # Assert
    expected_message = "Missing element input_variable"
    assert exception_raised.args[0] == expected_message

test_parser_depth_average_rule_creation_logic()

The ParserDepthAverageRule should parse the provided dictionary to correctly initialize itself during creation

Source code in tests/data/parsers/test_parser_depth_average_rule.py
def test_parser_depth_average_rule_creation_logic():
    """The ParserDepthAverageRule should parse the provided dictionary
    to correctly initialize itself during creation"""

    # Act
    data = ParserDepthAverageRule()

    # Assert

    assert isinstance(data, IParserRuleBase)
    assert data.rule_type_name == "depth_average_rule"