-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Martin Møldrup
committed
Jan 6, 2025
1 parent
fbddf62
commit ad7f48a
Showing
2 changed files
with
137 additions
and
49 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 |
---|---|---|
@@ -1,46 +1,111 @@ | ||
import pathlib | ||
from snappylapy import Expect | ||
import json | ||
import pytest | ||
from pytest import Pytester | ||
|
||
def test_snapshot_string(expect: Expect): | ||
def test_snapshot_string(pytester: Pytester): | ||
"""Test snapshot with string data.""" | ||
expect.string("Hello World").to_match_snapshot() | ||
test_code = """ | ||
from snappylapy import Expect | ||
def test_snapshot_bytes(expect: Expect): | ||
def test_snapshot_string(expect: Expect): | ||
expect.string("Hello World").to_match_snapshot() | ||
""" | ||
pytester.makepyfile(test_code) | ||
result = pytester.runpytest('-v') | ||
assert result.ret == 0 | ||
|
||
def test_snapshot_bytes(pytester: Pytester): | ||
"""Test snapshot with bytes data.""" | ||
expect.bytes(b"Hello World", name="bytes_snapshot").to_match_snapshot() | ||
test_code = """ | ||
from snappylapy import Expect | ||
def test_snapshot_bytes(expect: Expect): | ||
expect.bytes(b"Hello World", name="bytes_snapshot").to_match_snapshot() | ||
""" | ||
pytester.makepyfile(test_code) | ||
result = pytester.runpytest('-v') | ||
assert result.ret == 0 | ||
|
||
def test_snapshot_dict(expect: Expect): | ||
def test_snapshot_dict(pytester: Pytester): | ||
"""Test snapshot with dictionary data.""" | ||
expect.dict({ | ||
"name": "John Doe", | ||
"age": 31 | ||
}).to_match_snapshot() | ||
test_code = """ | ||
from snappylapy import Expect | ||
def test_snapshot_list(expect: Expect): | ||
def test_snapshot_dict(expect: Expect): | ||
expect.dict({ | ||
"name": "John Doe", | ||
"age": 31 | ||
}).to_match_snapshot() | ||
""" | ||
pytester.makepyfile(test_code) | ||
result = pytester.runpytest('-v') | ||
assert result.ret == 0 | ||
|
||
def test_snapshot_list(pytester: Pytester): | ||
"""Test snapshot with list data.""" | ||
expect.list(["John Doe", 31]).to_match_snapshot() | ||
test_code = """ | ||
from snappylapy import Expect | ||
def test_snapshot_list(expect: Expect): | ||
expect.list(["John Doe", 31]).to_match_snapshot() | ||
""" | ||
pytester.makepyfile(test_code) | ||
result = pytester.runpytest('-v') | ||
assert result.ret == 0 | ||
|
||
def test_snapshot_json_bytes(expect: Expect): | ||
def test_snapshot_json_bytes(pytester: Pytester): | ||
"""Test snapshot with JSON bytes data.""" | ||
data = json.dumps({"name": "John Doe", "age": 31}).encode() | ||
expect.bytes(data, name="json_bytes_snapshot").to_match_snapshot() | ||
test_code = """ | ||
import json | ||
from snappylapy import Expect | ||
def test_snapshot_python_code(expect: Expect): | ||
def test_snapshot_json_bytes(expect: Expect): | ||
data = json.dumps({"name": "John Doe", "age": 31}).encode() | ||
expect.bytes(data, name="json_bytes_snapshot").to_match_snapshot() | ||
""" | ||
pytester.makepyfile(test_code) | ||
result = pytester.runpytest('-v') | ||
assert result.ret == 0 | ||
|
||
def test_snapshot_python_code(pytester: Pytester): | ||
"""Test snapshot with Python code string.""" | ||
py_code = "print('Hello World')" | ||
expect.string(py_code, filetype="py", name="python_code_snapshot").to_match_snapshot() | ||
test_code = """ | ||
from snappylapy import Expect | ||
def test_snapshot_python_code(expect: Expect): | ||
py_code = "print('Hello World')" | ||
expect.string(py_code, filetype="py", name="python_code_snapshot").to_match_snapshot() | ||
""" | ||
pytester.makepyfile(test_code) | ||
result = pytester.runpytest('-v') | ||
assert result.ret == 0 | ||
|
||
def test_snapshot_with_custom_directories(expect: Expect): | ||
def test_snapshot_with_custom_directories(pytester: Pytester): | ||
"""Test snapshot with custom directories.""" | ||
expect.snapshot_dir = pathlib.Path("__snapshots_other_location__") | ||
expect.test_results_dir = pathlib.Path("__test_results_other_location__") | ||
expect.string("Hello World").to_match_snapshot() | ||
test_code = """ | ||
import pathlib | ||
from snappylapy import Expect | ||
def test_snapshot_multiple_assertions(expect: Expect): | ||
def test_snapshot_with_custom_directories(expect: Expect): | ||
expect.snapshot_dir = pathlib.Path("__snapshots_other_location__") | ||
expect.test_results_dir = pathlib.Path("__test_results_other_location__") | ||
expect.string("Hello World").to_match_snapshot() | ||
""" | ||
pytester.makepyfile(test_code) | ||
result = pytester.runpytest('-v') | ||
assert result.ret == 0 | ||
|
||
def test_snapshot_multiple_assertions(pytester: Pytester): | ||
"""Test snapshot with multiple assertions.""" | ||
expect.string("Hello World").to_match_snapshot() | ||
expect.dict({ | ||
"name": "John Doe", | ||
"age": 31 | ||
}).to_match_snapshot() | ||
test_code = """ | ||
from snappylapy import Expect | ||
def test_snapshot_multiple_assertions(expect: Expect): | ||
expect.string("Hello World").to_match_snapshot() | ||
expect.dict({ | ||
"name": "John Doe", | ||
"age": 31 | ||
}).to_match_snapshot() | ||
""" | ||
pytester.makepyfile(test_code) | ||
result = pytester.runpytest('-v') | ||
assert result.ret == 0 |