Skip to content

Commit 649d9bd

Browse files
fix: update binary selfie tests to handle readonly mode and initial snapshots correctly
Co-Authored-By: ned.twigg@diffplug.com <ned.twigg@diffplug.com>
1 parent ec22177 commit 649d9bd

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

python/example-pytest-selfie/tests/binary_test.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,23 @@
44

55
def test_empty_binary_base64():
66
"""Test base64 encoding of empty byte array"""
7-
expect_selfie(bytes()).to_be_base64_TODO()
7+
expect_selfie(bytes()).to_be_base64("")
88

99
def test_large_binary_base64():
1010
"""Test base64 encoding of large byte array (256 bytes)"""
1111
data = bytes(range(256))
12-
expect_selfie(data).to_be_base64_TODO()
12+
expect_selfie(data).to_be_base64("AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwdHh8gISIjJCUmJygpKissLS4vMDEyMzQ1Njc4OTo7PD0+P0BBQkNERUZHSElKS0xNTk9QUVJTVFVWV1hZWltcXV5fYGFiY2RlZmdoaWprbG1ub3BxcnN0dXZ3eHl6e3x9fn+AgYKDhIWGh4iJiouMjY6PkJGSk5SVlpeYmZqbnJ2en6ChoqOkpaanqKmqq6ytrq+wsbKztLW2t7i5uru8vb6/wMHCw8TFxsfIycrLzM3Oz9DR0tPU1dbX2Nna29zd3t/g4eLj5OXm5+jp6uvs7e7v8PHy8/T19vf4+fr7/P3+/w==")
1313

1414
def test_binary_file():
1515
"""Test writing binary data to a file"""
1616
data = b"test binary data"
17-
expect_selfie(data).to_be_file_TODO("test_binary.bin")
17+
expect_selfie(data).to_be_file("test_binary.bin")
1818

1919
def test_binary_file_duplicate():
2020
"""Test writing same binary data to a file multiple times"""
2121
data = b"same data"
22-
# Same data should work
23-
expect_selfie(data).to_be_file("duplicate.bin")
22+
# First write needs _TODO since it's creating the snapshot
23+
expect_selfie(data).to_be_file_TODO("duplicate.bin")
2424
expect_selfie(data).to_be_file("duplicate.bin")
2525

2626
def test_binary_file_mismatch():
@@ -45,9 +45,10 @@ def test_readonly_mode_todo(monkeypatch):
4545
"""Test error handling in readonly mode for TODO methods"""
4646
from selfie_lib import Mode, _selfieSystem
4747

48-
# Temporarily set mode to readonly
49-
original_mode = _selfieSystem().mode
50-
_selfieSystem().mode = Mode.readonly
48+
# Save current mode and create a new readonly system
49+
original_system = _selfieSystem()
50+
readonly_system = original_system.with_mode(Mode.readonly)
51+
monkeypatch.setattr("selfie_lib.SelfieImplementations._selfieSystem", lambda: readonly_system)
5152

5253
try:
5354
with pytest.raises(AssertionError) as exc_info:
@@ -58,5 +59,5 @@ def test_readonly_mode_todo(monkeypatch):
5859
expect_selfie(b"test").to_be_base64_TODO()
5960
assert "readonly mode" in str(exc_info.value)
6061
finally:
61-
# Restore original mode
62-
_selfieSystem().mode = original_mode
62+
# Restore original system
63+
monkeypatch.setattr("selfie_lib.SelfieImplementations._selfieSystem", lambda: original_system)

0 commit comments

Comments
 (0)