Skip to content

Commit

Permalink
test: regenerate regression file
Browse files Browse the repository at this point in the history
  • Loading branch information
12rambau committed Dec 17, 2024
1 parent 4f6bfe7 commit 8c5b1b3
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 8 deletions.
11 changes: 7 additions & 4 deletions src/pytest_regressions/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
8 changes: 4 additions & 4 deletions src/pytest_regressions/data_regression.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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"""
Expand Down
1 change: 1 addition & 0 deletions tests/test_data_regression.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import sys
from textwrap import dedent

import pytest
import yaml

from pytest_regressions.testing import check_regression_fixture_workflow
Expand Down
3 changes: 3 additions & 0 deletions tests/test_data_regression/test_round_digits.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@ content:
value: 1.12
value1: toto
value: 1.23
values:
- 1.12
- 2.35

0 comments on commit 8c5b1b3

Please sign in to comment.