|
1 | 1 | import base64 |
| 2 | + |
2 | 3 | import pytest |
3 | | -from selfie_lib import expect_selfie |
| 4 | +from pytest_selfie.SelfieSettingsAPI import SelfieSettingsAPI |
| 5 | +from selfie_lib import Mode, expect_selfie |
| 6 | + |
4 | 7 |
|
5 | 8 | def test_empty_binary_base64(): |
6 | 9 | """Test base64 encoding of empty byte array""" |
7 | 10 | expect_selfie(bytes()).to_be_base64("") |
8 | 11 |
|
| 12 | + |
9 | 13 | def test_large_binary_base64(): |
10 | 14 | """Test base64 encoding of large byte array (256 bytes)""" |
11 | 15 | data = bytes(range(256)) |
12 | | - expect_selfie(data).to_be_base64("AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwdHh8gISIjJCUmJygpKissLS4vMDEyMzQ1Njc4OTo7PD0+P0BBQkNERUZHSElKS0xNTk9QUVJTVFVWV1hZWltcXV5fYGFiY2RlZmdoaWprbG1ub3BxcnN0dXZ3eHl6e3x9fn+AgYKDhIWGh4iJiouMjY6PkJGSk5SVlpeYmZqbnJ2en6ChoqOkpaanqKmqq6ytrq+wsbKztLW2t7i5uru8vb6/wMHCw8TFxsfIycrLzM3Oz9DR0tPU1dbX2Nna29zd3t/g4eLj5OXm5+jp6uvs7e7v8PHy8/T19vf4+fr7/P3+/w==") |
| 16 | + expect_selfie(data).to_be_base64( |
| 17 | + "AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwdHh8gISIjJCUmJygpKissLS4vMDEyMzQ1Njc4OTo7PD0+P0BBQkNERUZHSElKS0xNTk9QUVJTVFVWV1hZWltcXV5fYGFiY2RlZmdoaWprbG1ub3BxcnN0dXZ3eHl6e3x9fn+AgYKDhIWGh4iJiouMjY6PkJGSk5SVlpeYmZqbnJ2en6ChoqOkpaanqKmqq6ytrq+wsbKztLW2t7i5uru8vb6/wMHCw8TFxsfIycrLzM3Oz9DR0tPU1dbX2Nna29zd3t/g4eLj5OXm5+jp6uvs7e7v8PHy8/T19vf4+fr7/P3+/w==" |
| 18 | + ) |
| 19 | + |
13 | 20 |
|
14 | 21 | def test_binary_file(): |
15 | 22 | """Test writing binary data to a file""" |
16 | 23 | data = b"test binary data" |
17 | 24 | expect_selfie(data).to_be_file("test_binary.bin") |
18 | 25 |
|
| 26 | + |
19 | 27 | def test_binary_file_duplicate(): |
20 | 28 | """Test writing same binary data to a file multiple times""" |
21 | 29 | data = b"same data" |
22 | 30 | # First write needs _TODO since it's creating the snapshot |
23 | | - expect_selfie(data).to_be_file_TODO("duplicate.bin") |
24 | 31 | expect_selfie(data).to_be_file("duplicate.bin") |
| 32 | + expect_selfie(data).to_be_file("duplicate.bin") |
| 33 | + |
25 | 34 |
|
26 | 35 | def test_binary_file_mismatch(): |
27 | 36 | """Test error handling for mismatched binary data""" |
28 | 37 | with pytest.raises(AssertionError): |
29 | 38 | expect_selfie(b"different").to_be_file("test_binary.bin") |
30 | 39 |
|
| 40 | + |
31 | 41 | def test_binary_file_not_found(): |
32 | 42 | """Test error handling for non-existent file""" |
33 | 43 | with pytest.raises(AssertionError) as exc_info: |
34 | 44 | expect_selfie(b"test").to_be_file("nonexistent.bin") |
35 | 45 | assert "no such file" in str(exc_info.value) |
36 | 46 |
|
| 47 | + |
37 | 48 | def test_base64_mismatch(): |
38 | 49 | """Test error handling for mismatched base64 data""" |
39 | 50 | data = b"test data" |
40 | 51 | encoded = base64.b64encode(b"different data").decode() |
41 | 52 | with pytest.raises(AssertionError): |
42 | 53 | expect_selfie(data).to_be_base64(encoded) |
43 | 54 |
|
| 55 | + |
44 | 56 | def test_readonly_mode_todo(monkeypatch): |
45 | 57 | """Test error handling in readonly mode for TODO methods""" |
46 | | - from selfie_lib import Mode, _selfieSystem |
47 | | - |
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) |
52 | | - |
53 | | - try: |
54 | | - with pytest.raises(AssertionError) as exc_info: |
55 | | - expect_selfie(b"test").to_be_file_TODO("test.bin") |
56 | | - assert "readonly mode" in str(exc_info.value) |
57 | | - |
58 | | - with pytest.raises(AssertionError) as exc_info: |
59 | | - expect_selfie(b"test").to_be_base64_TODO() |
60 | | - assert "readonly mode" in str(exc_info.value) |
61 | | - finally: |
62 | | - # Restore original system |
63 | | - monkeypatch.setattr("selfie_lib.SelfieImplementations._selfieSystem", lambda: original_system) |
| 58 | + monkeypatch.setattr(SelfieSettingsAPI, "calc_mode", lambda self: Mode.readonly) |
| 59 | + |
| 60 | + with pytest.raises(AssertionError) as exc_info: |
| 61 | + expect_selfie(b"test").to_be_file_TODO("test.bin") |
| 62 | + assert "readonly mode" in str(exc_info.value).lower() |
| 63 | + |
| 64 | + with pytest.raises(AssertionError) as exc_info: |
| 65 | + expect_selfie(b"test").to_be_base64_TODO() |
| 66 | + assert "readonly mode" in str(exc_info.value).lower() |
0 commit comments