From daac5b1e5c5d1e7016c8b2e7b0b3bd949727e9dd Mon Sep 17 00:00:00 2001 From: Satoru SATOH Date: Tue, 21 May 2024 20:10:34 +0900 Subject: [PATCH] change: switch to new test data loader --- .../backend/loaders/toml/test_toml_tomllib.py | 61 ++++++++----------- 1 file changed, 24 insertions(+), 37 deletions(-) diff --git a/tests/backend/loaders/toml/test_toml_tomllib.py b/tests/backend/loaders/toml/test_toml_tomllib.py index 3a686f76..aa8f9657 100644 --- a/tests/backend/loaders/toml/test_toml_tomllib.py +++ b/tests/backend/loaders/toml/test_toml_tomllib.py @@ -2,57 +2,44 @@ # Copyright (C) 2012 - 2024 Satoru SATOH # SPDX-License-Identifier: MIT # -# pylint: disable=missing-docstring,invalid-name,too-few-public-methods -# pylint: disable=ungrouped-imports -"""Test cases for the loader. -""" +# pylint: disable=missing-docstring +"""Test cases for the loader.""" from __future__ import annotations -import pathlib -import typing - import pytest -import tests.common.tdi_base -import tests.common.loader - +from ... import common -class TDI(tests.common.tdi_base.TDI): - _cid = tests.common.tdi_base.name_from_path(__file__) +try: + DATA = common.load_data_for_testfile(__file__) +except FileNotFoundError: + pytest.skip( + f"Not found test data for: {__file__}", + allow_module_level=True + ) -(TT, DATA, DATA_IDS) = TDI().get_all() +DATA_IDS: list[str] = common.get_test_ids(DATA) +Parser = getattr(common.get_mod(__file__), "Parser", None) -if TT is None: +if Parser is None: pytest.skip( - f"skipping tests: {TDI().cid()} as it's not available.", + f"Skip test cases: {__file__}", allow_module_level=True ) -assert DATA +@pytest.mark.parametrize(common.NAMES, DATA, ids=DATA_IDS) +def test_loads(ipath: str, opts: dict, exp) -> None: + psr = Parser() + content = psr.ropen(ipath).read().decode("utf-8") -class TestCase(tests.common.loader.TestCase): - psr_cls = TT.Parser + assert psr.loads(content, **opts) == exp - def _assert_loads( - self, ipath: pathlib.Path, aux: dict[str, typing.Any] - ): - (exp, opts, psr, _ioi) = self._get_all(ipath, aux) - assert psr.loads(ipath.read_text(), **opts) == exp - @pytest.mark.parametrize( - ("ipath", "aux"), DATA, ids=DATA_IDS, - ) - def test_loads( - self, ipath: pathlib.Path, aux: dict[str, typing.Any] - ): - self._assert_loads(ipath, aux) +@pytest.mark.parametrize(common.NAMES, DATA, ids=DATA_IDS) +def test_load(ipath: str, opts: dict, exp) -> None: + psr = Parser() + ioi = common.ioinfo_from_path(ipath) - @pytest.mark.parametrize( - ("ipath", "aux"), DATA, ids=DATA_IDS, - ) - def test_load( - self, ipath: pathlib.Path, aux: dict[str, typing.Any] - ): - self._assert_load(ipath, aux) + assert psr.load(ioi, **opts) == exp