Skip to content

Commit

Permalink
change: switch to new test data loader
Browse files Browse the repository at this point in the history
  • Loading branch information
ssato committed May 21, 2024
1 parent 69ccc2f commit daac5b1
Showing 1 changed file with 24 additions and 37 deletions.
61 changes: 24 additions & 37 deletions tests/backend/loaders/toml/test_toml_tomllib.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,57 +2,44 @@
# Copyright (C) 2012 - 2024 Satoru SATOH <satoru.satoh gmail.com>
# 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

0 comments on commit daac5b1

Please sign in to comment.