-
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #183 from 15r10nk/refactor
refactor
- Loading branch information
Showing
44 changed files
with
868 additions
and
701 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
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
### Fixed | ||
|
||
- fixed some issues with dataclass arguments |
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
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
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
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
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
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
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
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 |
---|---|---|
|
@@ -4,7 +4,6 @@ | |
from functools import singledispatch | ||
from unittest import mock | ||
|
||
|
||
real_repr = repr | ||
|
||
|
||
|
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
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
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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
from typing import Set | ||
|
||
from ._types import Category | ||
|
||
|
||
class Flags: | ||
""" | ||
fix: the value needs to be changed to pass the tests | ||
update: the value should be updated because the token-stream has changed | ||
create: the snapshot is empty `snapshot()` | ||
trim: the snapshot contains more values than neccessary. 1 could be trimmed in `5 in snapshot([1,5])`. | ||
""" | ||
|
||
def __init__(self, flags: Set[Category] = set()): | ||
self.fix = "fix" in flags | ||
self.update = "update" in flags | ||
self.create = "create" in flags | ||
self.trim = "trim" in flags | ||
|
||
def to_set(self): | ||
return {k for k, v in self.__dict__.items() if v} | ||
|
||
def __repr__(self): | ||
return f"Flags({self.to_set()})" |
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 |
---|---|---|
@@ -0,0 +1,45 @@ | ||
from __future__ import annotations | ||
|
||
import contextlib | ||
from dataclasses import dataclass | ||
from dataclasses import field | ||
from typing import Generator | ||
|
||
from ._flags import Flags | ||
|
||
|
||
@dataclass | ||
class State: | ||
# snapshot | ||
missing_values: int = 0 | ||
incorrect_values: int = 0 | ||
|
||
snapshots: dict = field(default_factory=dict) | ||
update_flags: Flags = field(default_factory=Flags) | ||
active: bool = True | ||
files_with_snapshots: set[str] = field(default_factory=set) | ||
|
||
# external | ||
storage = None | ||
|
||
|
||
_current = State() | ||
_current.active = False | ||
|
||
|
||
def state() -> State: | ||
global _current | ||
return _current | ||
|
||
|
||
@contextlib.contextmanager | ||
def snapshot_env() -> Generator[State]: | ||
|
||
global _current | ||
old = _current | ||
_current = State() | ||
|
||
try: | ||
yield _current | ||
finally: | ||
_current = old |
Oops, something went wrong.