-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix/change: migrate test cases for anyconfig.query.query from unittes…
…t to pytest
- Loading branch information
Showing
1 changed file
with
25 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,31 @@ | ||
# | ||
# Copyright (C) 2017 - 2021 Satoru SATOH <satoru.satoh@gmail.com> | ||
# Copyright (C) 2017 - 2024 Satoru SATOH <satoru.satoh gmail.com> | ||
# SPDX-License-Identifier: MIT | ||
# | ||
# pylint: disable=missing-docstring, invalid-name | ||
"""test cases for anyconfig.query.query. | ||
""" | ||
import os | ||
import unittest | ||
# pylint: disable=missing-docstring | ||
"""test cases for anyconfig.query.query.""" | ||
from __future__ import annotations | ||
|
||
import pytest | ||
|
||
try: | ||
import anyconfig.query.query as TT | ||
except ImportError: | ||
raise unittest.SkipTest('Needed library to query was not found') | ||
|
||
|
||
class Test_00_Functions(unittest.TestCase): | ||
|
||
def _assert_dicts_equal(self, dic, ref): | ||
self.assertEqual(dic, ref, | ||
"%r%s vs.%s%r" % (dic, os.linesep, os.linesep, ref)) | ||
|
||
def _assert_query(self, data_exp_ref_list, dicts=False): | ||
_assert = self._assert_dicts_equal if dicts else self.assertEqual | ||
for data, exp, ref in data_exp_ref_list: | ||
try: | ||
_assert(TT.query(data, exp)[0], ref) | ||
except ValueError: | ||
pass | ||
|
||
def test_10_query(self): | ||
self._assert_query([({"a": 1}, "a", 1), | ||
({"a": {"b": 2}}, "a.b", 2)]) | ||
|
||
def test_12_invalid_query(self): | ||
data = {"a": 1} | ||
self._assert_query([(data, "b.", data)]) | ||
|
||
def test_14_empty_query(self): | ||
data = {"a": 1} | ||
self._assert_query([(data, None, data), | ||
(data, '', data)]) | ||
|
||
# vim:sw=4:ts=4:et: | ||
except ImportError as exc: | ||
raise pytest.skip( | ||
"Needed library to query was not found", | ||
allow_module_leve=True | ||
) from exc | ||
|
||
|
||
@pytest.mark.parametrize( | ||
("data", "query", "exp"), | ||
(({"a": 1}, "a", 1), | ||
({"a": {"b": 2}}, "a.b", 2), | ||
({"a": 1}, "b.", {"a": 1}), | ||
({"a": 1}, None, {"a": 1}), | ||
({"a": 1}, "", {"a": 1}), | ||
), | ||
) | ||
def test_query(data, query: str, exp): | ||
(res, _exc) = TT.query(data, query) | ||
assert res == exp |