From 8c5b1b34219bb53a317cbce1581acd8297fd3de5 Mon Sep 17 00:00:00 2001 From: Rambaud Pierrick <12rambau@users.noreply.github.com> Date: Tue, 17 Dec 2024 12:39:34 +0000 Subject: [PATCH] test: regenerate regression file --- src/pytest_regressions/common.py | 11 +++++++---- src/pytest_regressions/data_regression.py | 8 ++++---- tests/test_data_regression.py | 1 + tests/test_data_regression/test_round_digits.yml | 3 +++ 4 files changed, 15 insertions(+), 8 deletions(-) diff --git a/src/pytest_regressions/common.py b/src/pytest_regressions/common.py index db2b6b7..0655652 100644 --- a/src/pytest_regressions/common.py +++ b/src/pytest_regressions/common.py @@ -3,7 +3,10 @@ from pathlib import Path from typing import Callable from typing import List +from typing import MutableMapping +from typing import MutableSequence from typing import Optional +from typing import TypeVar from typing import Union import pytest @@ -199,17 +202,17 @@ def round_digits(data: T, precision: int) -> T: Recursively Round the values of any float value in a collection to the given precision. :param data: The collection to round. - :param prescision: The number of decimal places to round to. - :return: The collection with all float values rounded to the given prescision. + :param precision: The number of decimal places to round to. + :return: The collection with all float values rounded to the given precision. """ # change the generator depending on the collection type generator = enumerate(data) if isinstance(data, MutableSequence) else data.items() for k, v in generator: if isinstance(v, (MutableSequence, MutableMapping)): - data[k] = round_digits(v, prescision) + data[k] = round_digits(v, precision) elif isinstance(v, float): - data[k] = round(v, prescision) + data[k] = round(v, precision) else: data[k] = v return data diff --git a/src/pytest_regressions/data_regression.py b/src/pytest_regressions/data_regression.py index b549727..e9c40c6 100644 --- a/src/pytest_regressions/data_regression.py +++ b/src/pytest_regressions/data_regression.py @@ -33,7 +33,7 @@ def check( data_dict: Dict[str, Any], basename: Optional[str] = None, fullpath: Optional["os.PathLike[str]"] = None, - prescision: Optional[int] = None, + precision: Optional[int] = None, ) -> None: """ Checks the given dict against a previously recorded version, or generate a new file. @@ -48,14 +48,14 @@ def check( will ignore ``datadir`` fixture when reading *expected* files but will still use it to write *obtained* files. Useful if a reference file is located in the session data dir for example. - :param prescision: if given, round all floats in the dict to the given number of digits. + :param precision: if given, round all floats in the dict to the given number of digits. ``basename`` and ``fullpath`` are exclusive. """ __tracebackhide__ = True - if prescision is not None: - round_digits(data_dict, prescision) + if precision is not None: + round_digits(data_dict, precision) def dump(filename: Path) -> None: """Dump dict contents to the given filename""" diff --git a/tests/test_data_regression.py b/tests/test_data_regression.py index 3fea887..3cd9acd 100644 --- a/tests/test_data_regression.py +++ b/tests/test_data_regression.py @@ -1,6 +1,7 @@ import sys from textwrap import dedent +import pytest import yaml from pytest_regressions.testing import check_regression_fixture_workflow diff --git a/tests/test_data_regression/test_round_digits.yml b/tests/test_data_regression/test_round_digits.yml index ea5f70a..54cc585 100644 --- a/tests/test_data_regression/test_round_digits.yml +++ b/tests/test_data_regression/test_round_digits.yml @@ -2,3 +2,6 @@ content: value: 1.12 value1: toto value: 1.23 +values: +- 1.12 +- 2.35