|
1 | 1 | # Snappylapy |
2 | 2 |
|
3 | | -Welcome to **Snappylapy**, a powerful and intuitive snapshot testing tool for Python's pytest framework. Snappylapy simplifies the process of capturing and verifying snapshots of your data, ensuring your code behaves as expected across different runs. With Snappylapy, you can save snapshots in a human-readable format and deserialize them for robust integration testing, providing a clear separation layer to help isolate errors and maintain code integrity. |
| 3 | +Welcome to **Snappylapy**, a powerful and intuitive snapshot testing plugin for Python's pytest framework. Snappylapy simplifies the process of capturing and verifying snapshots of your data, ensuring your code behaves as expected across different runs. With Snappylapy, you can save snapshots in a human-readable format and deserialize them for robust integration testing, providing a clear separation layer to help isolate errors and maintain code integrity. |
4 | 4 |
|
5 | 5 | ## Installation |
6 | | -To get started with Snappylapy, install the package via pip: |
| 6 | +To get started with Snappylapy, install the package via pip, uv or poetry: |
7 | 7 |
|
8 | 8 | ```bash |
9 | 9 | pip install snappylapy |
10 | 10 | ``` |
11 | 11 |
|
12 | | -## Key Features |
13 | | -Legend: |
14 | | -- ✅ Implemented |
15 | | -- ❌ Not implemented yet |
| 12 | +```bash |
| 13 | +uv add snappylapy |
| 14 | +``` |
16 | 15 |
|
17 | | -The features are in development: |
18 | | - |
19 | | -- **Human-Readable Snapshots**✅: Save snapshots in a format that's easy to read and understand, making it simpler to review changes and debug issues. |
20 | | -- **Serialization and Deserialization**✅: Snapshots can be serialized and deserialized, allowing for flexible and reusable test cases. |
21 | | -- **Integration Testing**✅: Use snapshots for integration testing with a clear separation layer, preventing interdependencies between code components and making it easier to isolate and identify errors. |
22 | | -- **Easy to Use**✅: Seamlessly integrates with pytest, allowing you to start capturing and verifying snapshots with minimal setup. For a good developer experience the package is fully typed, with docstrings to provide good editor code completion. |
23 | | -- **Customizable Output**✅: Store snapshots in a location of your choice, enabling you to organize and manage your test data effectively. |
24 | | -- **Diff Report Generation**❌: Generate a diff report in html format for easy comparison between test results and snapshots. |
25 | | -- **Provides a wide set of assertions**❌: The package provides a wide set of assertions to make it easy to compare different types of data, for do fuzzy matching or ignore certain parts of the data that are variable. |
| 16 | +```bash |
| 17 | +poetry add snappylapy |
| 18 | +``` |
| 19 | + |
| 20 | +## Key Features |
| 21 | +- **Human-Readable Snapshots**: Save snapshots in a format that's easy to read and understand, making it simpler to review changes and debug issues. |
| 22 | +- **Serialization and Deserialization**: Snapshots can be serialized and deserialized, allowing for flexible and reusable test cases. |
| 23 | +- **Easy to Use**: Seamlessly integrates with pytest, enabling you to capture and verify snapshots with minimal setup. The fully typed fixtures and rich editor support provide intuitive code completion and guidance, making your workflow faster and more productive. |
| 24 | +- **Customizable Output**: Store snapshots in a location (static or dynamic) of your choice, enabling you to organize and manage your test data effectively. |
| 25 | +- **Editor Integration**: Can show a diff comparison in VS code when a snapshot test fails, for easy comparison between test results and snapshots. |
26 | 26 |
|
27 | 27 | ## Benefits of Snapshot Testing |
28 | 28 | Snapshot testing is a powerful technique for verifying the output of your code by comparing it to a stored snapshot. This approach offers several benefits, including: |
@@ -96,46 +96,25 @@ snappylapy update |
96 | 96 | ``` |
97 | 97 |
|
98 | 98 | ## Fixtures and roadmap |
99 | | -Registers fixtures: |
100 | | -- expect ✅ |
101 | | -- load_snapshot ✅ |
| 99 | +Registers pytest fixtures: |
| 100 | +- expect |
| 101 | +- load_snapshot |
102 | 102 |
|
103 | 103 | Supported data types |
104 | | -- .txt ✅ |
105 | | -- .json ✅ |
106 | | -- .csv ❌ |
107 | | -- .yaml ❌ |
108 | | -- .jsonl ❌ |
109 | | - |
110 | | -Planned data types: |
111 | | - |
112 | | -| Python Type | Default Output file type | Implementation Status | |
113 | | -|---------------------|--------------------------|---------------------------| |
114 | | -| bytes | .txt | ✅ | |
115 | | -| pd.DataFrame | .csv | ✅ (missing csv support) | |
116 | | -| pd.Series | .csv | ❌ | |
117 | | -| np.ndarray | .csv | ❌ | |
118 | | -| dict | .json | ✅ | |
119 | | -| list | .json | ✅ | |
120 | | -| tuple | .json | ❌ | |
121 | | -| set | .json | ❌ | |
122 | | -| str | .txt | ✅ | |
123 | | -| int | .txt | ❌ | |
124 | | -| float | .txt | ❌ | |
125 | | -| bool | .txt | ❌ | |
126 | | -| datetime.datetime | .txt | ❌ | |
127 | | -| datetime.date | .txt | ❌ | |
128 | | -| datetime.time | .txt | ❌ | |
129 | | -| pathlib.Path | .txt | ❌ | |
130 | | -| decimal.Decimal | .txt | ❌ | |
131 | | -| uuid.UUID | .txt | ❌ | |
132 | | -| pydantic.BaseModel | .json | ❌ | |
133 | | -| python dataclasses | .json | ❌ | |
134 | | - |
135 | | - |
136 | | - |
137 | | ---- |
138 | | - |
| 104 | +- ✅ .txt - if you provide a string |
| 105 | +- ✅ .json - for all other objects |
| 106 | +- ✅ custom (decode the data yourself and provide a file extension) |
| 107 | + |
| 108 | +### Supported data types to snapshot test |
| 109 | +Snappylapy uses jsonpickle to serialize into json, this means that it can handle almost any Python object out of the box, including: |
| 110 | + |
| 111 | +- Built-in types: str, int, float, bool, None |
| 112 | +- Collections: list, tuple, set, dict |
| 113 | +- NumPy arrays and pandas DataFrames (with optional dependencies) |
| 114 | +- Custom classes (with jsonpickle support) |
| 115 | + |
| 116 | +It is also possible to serialize objects yourself and provide them as a string or bytes data. Then it will be stored and loaded as-is. This means that with snappylapy it is possible to serialize and deserialize any Python object, even those not natively supported. |
| 117 | + |
139 | 118 | Snappylapy is your go-to tool for efficient and reliable snapshot testing in Python. By maintaining clear boundaries between different parts of your code, Snappylapy helps you isolate errors, streamline debugging, and ensure your code remains robust and maintainable. |
140 | 119 |
|
141 | 120 | ## Contributing |
|
0 commit comments