From 25955394e16a1e1f394286d698755304b8210a17 Mon Sep 17 00:00:00 2001 From: Artucuno Date: Sun, 28 Jan 2024 19:20:09 +1100 Subject: [PATCH] Update README test --- README.md | 1 - integration_test/test_readme.py | 12 ++++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index a1fe188..5a18419 100644 --- a/README.md +++ b/README.md @@ -65,7 +65,6 @@ result = spam_repository.find_one_by_id(spam.id) # Find One By Id using string if the id attribute is a ObjectIdField result = spam_repository.find_one_by_id(ObjectId('611827f2878b88b49ebb69fc')) -assert result.foo.count == 2 # Find One By Query result = spam_repository.find_one_by({'foo.count': 1}) diff --git a/integration_test/test_readme.py b/integration_test/test_readme.py index 94c64e5..535f09e 100644 --- a/integration_test/test_readme.py +++ b/integration_test/test_readme.py @@ -2,19 +2,27 @@ import io import os import re +import sys + +# This test isn't really nessessary def extract_python_snippets(content): # Regular expression pattern for finding Python code blocks pattern = r'```python(.*?)```' snippets = re.findall(pattern, content, re.DOTALL) - return snippets + def evaluate_snippet(snippet): # Capture the output of the snippet output_buffer = io.StringIO() with contextlib.redirect_stdout(output_buffer): - exec(snippet, globals()) + try: + exec(snippet, globals()) + except Exception as e: + exc_type, exc_obj, exc_tb = sys.exc_info() + fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1] + raise Exception(f"{e} {exc_type} {fname} {exc_tb.tb_lineno}") return output_buffer.getvalue()