Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions tests/main/test_parsed_source_cache_parity.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import pytest

from datamodel_code_generator import InputFileType, _clear_parser_source_data_cache
from datamodel_code_generator import InputFileType, _clear_parser_source_data_cache, _parser_source_data_cache
from tests.conftest import assert_output
from tests.main.conftest import JSON_SCHEMA_DATA_PATH, OPEN_API_DATA_PATH, run_main_with_args

Expand Down Expand Up @@ -55,13 +55,14 @@ def _run_generate_with_parsed_source_cache(
*,
use_cache: bool,
extra_args: Sequence[str] | None,
) -> None:
) -> int:
_clear_parser_source_data_cache()
run_main_with_args(
_build_generate_args(input_path, output_path, input_file_type, extra_args),
use_parsed_source_cache=use_cache,
use_builtin_default_formatter=False,
)
return len(_parser_source_data_cache)


@pytest.mark.parametrize(
Expand Down Expand Up @@ -93,6 +94,7 @@ def _run_generate_with_parsed_source_cache(
),
],
)
@pytest.mark.allow_direct_assert
def test_generate_output_matches_with_and_without_parsed_source_cache(
input_path: Path,
input_file_type: InputFileType,
Expand All @@ -103,19 +105,21 @@ def test_generate_output_matches_with_and_without_parsed_source_cache(
cached_output = tmp_path / "cached.py"
uncached_output = tmp_path / "uncached.py"

_run_generate_with_parsed_source_cache(
cached_entry_count = _run_generate_with_parsed_source_cache(
input_path,
cached_output,
input_file_type,
use_cache=True,
extra_args=extra_args,
)
_run_generate_with_parsed_source_cache(
uncached_entry_count = _run_generate_with_parsed_source_cache(
input_path,
uncached_output,
input_file_type,
use_cache=False,
extra_args=extra_args,
)

assert cached_entry_count > 0
assert uncached_entry_count == 0
assert_output(uncached_output.read_text(encoding="utf-8"), cached_output)
Loading