Esempio n. 1
0
def test_convert_description_to_alfacase_with_empty_dict(
        datadir: Path) -> None:
    """
    Ensure that the conversion from a description into a Alfacase it's not generating empty dict.
    Since it's not a valid syntax for strictyaml resulting in an InconsistentIndentationDisallowed error
    """

    simple_case = case_description.CaseDescription(
        name="Simple Case",
        pipes=[
            case_description.PipeDescription(
                name="pipe",
                source="mass_source_inlet",
                target="pressure_outlet",
                segments=build_simple_segment(),
                profile=case_description.ProfileDescription(
                    x_and_y=case_description.XAndYDescription(
                        x=Array([0], "m"), y=Array([0], "m"))),
            )
        ],
    )
    simple_case_alfacase_content = convert_description_to_alfacase(simple_case)
    assert "wall_description: {}" not in simple_case_alfacase_content
    assert "tables: {}" not in simple_case_alfacase_content
    # Smoke check, ensures that the alfacase is loaded correctly without errors
    simple_case_alfacase_file = datadir / "simple_case.alfacase"
    simple_case_alfacase_file.write_text(data=simple_case_alfacase_content,
                                         encoding="UTF-8")
    loaded_alfacase = DescriptionDocument.from_file(simple_case_alfacase_file)

    assert loaded_alfacase.content["name"].data == simple_case.name
Esempio n. 2
0
def convert_alfacase_to_description(
    file_alfacase: Path, ) -> case_description.CaseDescription:
    """
    Return a alfasim_sdk.alfacase.case_description.Case with all information provided on file_yaml.
    """
    from alfasim_sdk._internal.alfacase.alfacase_to_case import load_case_description
    from alfasim_sdk._internal.alfacase.alfacase_to_case import DescriptionDocument

    return load_case_description(DescriptionDocument.from_file(file_alfacase))
Esempio n. 3
0
def test_invalid_yaml_contents_parsing(tmp_path):
    """
    Errors while parsing YAML should be detected and raised as our custom exception.
    """
    import re

    alfacase_content = "Invalid YAML contents"
    alfacase_file = tmp_path / "invalid-yaml.alfacase"
    alfacase_file.write_text(data=alfacase_content, encoding="UTF-8")

    expected_msg = ("when expecting a mapping\n"
                    '  in "<unicode string>", line 1, column 1:\n'
                    "    Invalid YAML contents\n"
                    "     ^ (line: 1)\n"
                    "found arbitrary text\n"
                    '  in "<unicode string>", line 2, column 1:\n'
                    "    ...\n"
                    "    ^ (line: 2)")

    with pytest.raises(DescriptionError, match=re.escape(expected_msg)):
        DescriptionDocument.from_file(alfacase_file)