-
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added migration testing for existing migrations
- Loading branch information
1 parent
5ca1c7a
commit 2ea86e8
Showing
7 changed files
with
680 additions
and
52 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
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,52 @@ | ||
import random | ||
import string | ||
from typing import Any, Callable, Mapping, Optional, Sequence, Tuple, TypeVar | ||
|
||
T = TypeVar("T") | ||
|
||
|
||
def one_of(xs: Sequence[T], predicate: Callable[[T], bool]) -> T: | ||
matches = [x for x in xs if predicate(x)] | ||
match len(matches): | ||
case 1: | ||
return matches[0] | ||
case 0: | ||
raise ValueError("No matches") | ||
case _: | ||
raise ValueError(f"Too many matches: {matches}") | ||
|
||
|
||
def random_bool() -> bool: | ||
return bool(random.getrandbits(1)) | ||
|
||
|
||
def random_optional_bool() -> Optional[bool]: | ||
if random_bool(): | ||
return None | ||
return random_bool() | ||
|
||
|
||
def random_string(length: int) -> str: | ||
return "".join(random.choice(string.ascii_lowercase) for _ in range(length)) | ||
|
||
|
||
def random_optional_string(length: int) -> Optional[str]: | ||
if random_bool(): | ||
return None | ||
return random_string(length) | ||
|
||
|
||
def format_param_dict(params: Mapping[str, Any]) -> Tuple[str, str]: | ||
return (", ".join(params.keys()), ", ".join(f":{x}" for x in params)) | ||
|
||
|
||
class Missing: | ||
def __eq__(self, other: object) -> bool: | ||
return False | ||
|
||
def __ne__(self, other: object) -> bool: | ||
return True | ||
|
||
|
||
assert Missing() != Missing() | ||
assert Missing() != Missing() |
Oops, something went wrong.