|
39 | 39 | }, |
40 | 40 | { |
41 | 41 | "cell_type": "code", |
42 | | - "execution_count": 13, |
| 42 | + "execution_count": null, |
43 | 43 | "metadata": {}, |
44 | | - "outputs": [ |
45 | | - { |
46 | | - "name": "stdout", |
47 | | - "output_type": "stream", |
48 | | - "text": [ |
49 | | - "✅ Pydantic model created successfully from valid data.\n", |
50 | | - "✅ Pydantic correctly raised a ValidationError for invalid data.\n" |
51 | | - ] |
52 | | - } |
53 | | - ], |
| 44 | + "outputs": [], |
54 | 45 | "source": [ |
55 | 46 | "from typing import Annotated\n", |
56 | 47 | "\n", |
|
72 | 63 | "# 1. Test the successful case\n", |
73 | 64 | "valid_data = {\"id\": 1, \"name\": \"Alice\", \"age\": 30}\n", |
74 | 65 | "user = User.model_validate(valid_data)\n", |
| 66 | + "user\n" |
| 67 | + ] |
| 68 | + }, |
| 69 | + { |
| 70 | + "cell_type": "code", |
| 71 | + "execution_count": null, |
| 72 | + "metadata": {}, |
| 73 | + "outputs": [], |
| 74 | + "source": [ |
75 | 75 | "\n", |
76 | 76 | "assert user.id == 1\n", |
77 | 77 | "assert user.name == \"Alice\"\n", |
|
120 | 120 | }, |
121 | 121 | { |
122 | 122 | "cell_type": "code", |
123 | | - "execution_count": 14, |
| 123 | + "execution_count": null, |
124 | 124 | "metadata": {}, |
125 | | - "outputs": [ |
126 | | - { |
127 | | - "name": "stdout", |
128 | | - "output_type": "stream", |
129 | | - "text": [ |
130 | | - "✅ `parse_user_id` returned Success for valid input.\n", |
131 | | - "✅ `parse_user_id` returned Failure for invalid format.\n", |
132 | | - "✅ `parse_user_id` returned Failure for invalid value.\n" |
133 | | - ] |
134 | | - } |
135 | | - ], |
| 125 | + "outputs": [], |
136 | 126 | "source": [ |
137 | 127 | "from returns.result import Failure, Result, Success\n", |
138 | 128 | "\n", |
|
153 | 143 | "\n", |
154 | 144 | "# 1. Test the Success case\n", |
155 | 145 | "success_result = parse_user_id(\"123\")\n", |
| 146 | + "success_result\n" |
| 147 | + ] |
| 148 | + }, |
| 149 | + { |
| 150 | + "cell_type": "code", |
| 151 | + "execution_count": null, |
| 152 | + "metadata": {}, |
| 153 | + "outputs": [], |
| 154 | + "source": [ |
156 | 155 | "assert isinstance(success_result, Success)\n", |
157 | 156 | "assert success_result.unwrap() == 123\n", |
158 | 157 | "print(\"✅ `parse_user_id` returned Success for valid input.\")\n", |
159 | 158 | "\n", |
160 | 159 | "# 2. Test the Failure case (format)\n", |
161 | 160 | "failure_result_format = parse_user_id(\"abc\")\n", |
| 161 | + "failure_result_format" |
| 162 | + ] |
| 163 | + }, |
| 164 | + { |
| 165 | + "cell_type": "code", |
| 166 | + "execution_count": null, |
| 167 | + "metadata": {}, |
| 168 | + "outputs": [], |
| 169 | + "source": [ |
162 | 170 | "assert isinstance(failure_result_format, Failure)\n", |
163 | 171 | "assert \"Invalid format\" in failure_result_format.failure()\n", |
164 | 172 | "print(\"✅ `parse_user_id` returned Failure for invalid format.\")\n", |
165 | 173 | "\n", |
166 | 174 | "# 3. Test the Failure case (value)\n", |
167 | 175 | "failure_result_value = parse_user_id(\"0\")\n", |
| 176 | + "failure_result_value" |
| 177 | + ] |
| 178 | + }, |
| 179 | + { |
| 180 | + "cell_type": "code", |
| 181 | + "execution_count": null, |
| 182 | + "metadata": {}, |
| 183 | + "outputs": [], |
| 184 | + "source": [ |
168 | 185 | "assert isinstance(failure_result_value, Failure)\n", |
169 | 186 | "assert \"must be positive\" in failure_result_value.failure()\n", |
170 | 187 | "print(\"✅ `parse_user_id` returned Failure for invalid value.\")" |
|
188 | 205 | }, |
189 | 206 | { |
190 | 207 | "cell_type": "code", |
191 | | - "execution_count": 15, |
| 208 | + "execution_count": null, |
192 | 209 | "metadata": {}, |
193 | | - "outputs": [ |
194 | | - { |
195 | | - "name": "stdout", |
196 | | - "output_type": "stream", |
197 | | - "text": [ |
198 | | - "Pipeline: ' This is a Long String of Text ' to '\"this is a !\"'\n", |
199 | | - "✅ Pipeline correctly working\n" |
200 | | - ] |
201 | | - } |
202 | | - ], |
| 210 | + "outputs": [], |
203 | 211 | "source": [ |
204 | 212 | "from returns.pipeline import pipe\n", |
205 | 213 | "\n", |
|
221 | 229 | "raw_input = \" This is a Long String of Text \"\n", |
222 | 230 | "\n", |
223 | 231 | "# Use pipe to compose the functions into a pipeline\n", |
224 | | - "processed_text = pipe(clean_text, truncate_text, emphasize_text)(raw_input) # pyright: ignore\n", |
| 232 | + "processed_text = pipe(clean_text, truncate_text, emphasize_text)(raw_input)\n", |
| 233 | + "processed_text\n" |
| 234 | + ] |
| 235 | + }, |
| 236 | + { |
| 237 | + "cell_type": "code", |
| 238 | + "execution_count": null, |
| 239 | + "metadata": {}, |
| 240 | + "outputs": [], |
| 241 | + "source": [ |
225 | 242 | "\n", |
226 | 243 | "# --- Verification ---\n", |
227 | 244 | "print(f\"Pipeline: '{raw_input}' to '{processed_text}'\")\n", |
|
261 | 278 | }, |
262 | 279 | { |
263 | 280 | "cell_type": "code", |
264 | | - "execution_count": 16, |
| 281 | + "execution_count": null, |
265 | 282 | "metadata": {}, |
266 | | - "outputs": [ |
267 | | - { |
268 | | - "name": "stderr", |
269 | | - "output_type": "stream", |
270 | | - "text": [ |
271 | | - "\u001b[34m\u001b[1mDEBUG \u001b[0m | \u001b[36m__main__:<module>:19\u001b[0m - \u001b[34m\u001b[1mThis is a debug message. Useful for developers.\u001b[0m\n", |
272 | | - "\u001b[1mINFO \u001b[0m | \u001b[36m__main__:<module>:20\u001b[0m - \u001b[1mApplication is starting up...\u001b[0m\n", |
273 | | - "\u001b[32m\u001b[1mSUCCESS \u001b[0m | \u001b[36m__main__:<module>:21\u001b[0m - \u001b[32m\u001b[1mA task was completed successfully.\u001b[0m\n", |
274 | | - "\u001b[33m\u001b[1mWARNING \u001b[0m | \u001b[36m__main__:<module>:22\u001b[0m - \u001b[33m\u001b[1mSomething looks a bit strange, but it's not an error.\u001b[0m\n", |
275 | | - "\u001b[31m\u001b[1mERROR \u001b[0m | \u001b[36m__main__:<module>:23\u001b[0m - \u001b[31m\u001b[1mAn error occurred! This needs attention.\u001b[0m\n" |
276 | | - ] |
277 | | - }, |
278 | | - { |
279 | | - "name": "stdout", |
280 | | - "output_type": "stream", |
281 | | - "text": [ |
282 | | - "\n", |
283 | | - "✅ Loguru demonstrated various log levels.\n" |
284 | | - ] |
285 | | - } |
286 | | - ], |
| 283 | + "outputs": [], |
287 | 284 | "source": [ |
288 | 285 | "import sys\n", |
289 | 286 | "\n", |
|
0 commit comments