File: _is_normalized.py

package info (click to toggle)
python-inline-snapshot 0.23.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,116 kB
  • sloc: python: 6,888; makefile: 34; sh: 28
file content (23 lines) | stat: -rw-r--r-- 562 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
from inline_snapshot._unmanaged import declare_unmanaged


@declare_unmanaged
class IsNormalized:
    def __init__(self, func, value) -> None:
        self._func = func
        self._value = value
        self._last_value = None

    def __eq__(self, other) -> bool:
        self._last_value = self._func(other)
        return self._last_value == self._value

    def __repr__(self):
        return f"IsNormalized({self._value}, should_be={self._last_value!r})"


def normalization(func):
    def f(value):
        return IsNormalized(func, value)

    return f