示例#1
0
def test_generate_from_schema_using_path(tmp_path: Path) -> None:
    """Test providing a schema path as a str with the file not opened"""
    rendered = generate_from_schema(get_test_case_path("basic"))

    soup = BeautifulSoup(rendered, "html.parser")

    assert_basic_case(soup)

    assert_css_and_js_not_copied(tmp_path)
def test_generate_from_schema_using_file_object(tmp_path: Path) -> None:
    """Test providing a schema path as an opened file object"""
    with open(get_test_case_path("basic")) as test_case_fp:
        rendered = generate_from_schema(test_case_fp)

    soup = BeautifulSoup(rendered, "html.parser")

    assert_basic_case(soup)

    assert_css_and_js_not_copied(tmp_path)
示例#3
0
def test_generate_from_file_object(tmp_path: Path) -> None:
    """Test generating from open file objects for input and output"""
    result_file_path = tmp_path / "result_with_another_name.html"

    with open(get_test_case_path("basic")) as test_case_fp:
        with result_file_path.open("w", encoding="utf-8") as result_write_fp:
            generate_from_file_object(test_case_fp, result_write_fp, False,
                                      False, False, False)

    with result_file_path.open(encoding="utf-8") as result_fp:
        soup = BeautifulSoup(result_fp.read(), "html.parser")

    assert_basic_case(soup)

    assert (tmp_path / "result_with_another_name.html").exists()

    assert (tmp_path / "schema_doc.min.js").exists()
示例#4
0
def test_generate_from_schema_using_path_already_loaded(
        tmp_path: Path) -> None:
    """Test providing a schema path as a str with the file not opened but also the loaded schema in a dict.
    Ensure the schema is not loaded again
    """
    test_case_path = os.path.realpath(get_test_case_path("basic"))

    with open(test_case_path, encoding="utf-8") as test_case_fp:
        loaded = {test_case_path: yaml.safe_load(test_case_fp.read())}

    with patch("yaml.safe_load") as patched_yaml_load:
        rendered = generate_from_schema(test_case_path, loaded_schemas=loaded)

        patched_yaml_load.assert_not_called()

    soup = BeautifulSoup(rendered, "html.parser")

    assert_basic_case(soup)

    assert_css_and_js_not_copied(tmp_path)