Skip to content

Commit 617c154

Browse files
committed
Merge branch 'main' into DiskStorage
2 parents 41d4615 + 2a485d0 commit 617c154

File tree

16 files changed

+424
-289
lines changed

16 files changed

+424
-289
lines changed

python/example-pytest-selfie/poetry.lock

Lines changed: 29 additions & 29 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from selfie_lib.Selfie import cache_selfie_string
2+
import random
3+
4+
5+
def test_cache_selfie():
6+
cache_selfie_string(lambda: str(random.random())).to_be("0.6623096709843852")

python/pytest-selfie/poetry.lock

Lines changed: 26 additions & 26 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

python/pytest-selfie/pytest_selfie/plugin.py

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,20 +35,29 @@ def assert_failed(self, message, expected=None, actual=None) -> Exception:
3535
if expected is None and actual is None:
3636
return AssertionError(message)
3737

38-
on_null = ""
39-
expected_str = self.__nullable_to_string(expected, on_null)
40-
actual_str = self.__nullable_to_string(actual, on_null)
41-
42-
if expected_str != actual_str:
38+
expected_str = self.__nullable_to_string(expected, "")
39+
actual_str = self.__nullable_to_string(actual, "")
40+
41+
if not expected_str and not actual_str and (expected is None or actual is None):
42+
on_null = "(null)"
43+
return self.__comparison_assertion(
44+
message,
45+
self.__nullable_to_string(expected, on_null),
46+
self.__nullable_to_string(actual, on_null),
47+
)
48+
else:
4349
return self.__comparison_assertion(message, expected_str, actual_str)
44-
return AssertionError(message)
4550

46-
def __nullable_to_string(self, value, on_null):
51+
def __nullable_to_string(self, value, on_null: str) -> str:
4752
return str(value) if value is not None else on_null
4853

49-
def __comparison_assertion(self, message, expected, actual) -> Exception:
50-
error_message = f"{message} - Expected: {expected}, Actual: {actual}"
51-
return AssertionError(error_message)
54+
def __comparison_assertion(
55+
self, message: str, expected: str, actual: str
56+
) -> Exception:
57+
# this *should* through an exception that a good pytest runner will show nicely
58+
assert expected == actual, message
59+
# but in case it doesn't, we'll create our own here
60+
return AssertionError(message)
5261

5362

5463
class PytestSnapshotFileLayout(SnapshotFileLayout):

0 commit comments

Comments
 (0)