From fea32a052fbb1ef515cda346973d90d0e35c21f7 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Sun, 24 May 2026 11:03:51 +0000 Subject: [PATCH] Fix source code execution example Co-authored-by: 0-coding <0-coding@users.noreply.github.com> --- source/load_mod_from_source_code.py | 4 ++-- tests/__init__.py | 1 + tests/test_examples.py | 24 ++++++++++++++++++++++++ 3 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 tests/__init__.py create mode 100644 tests/test_examples.py diff --git a/source/load_mod_from_source_code.py b/source/load_mod_from_source_code.py index b2204a5..b9ce397 100644 --- a/source/load_mod_from_source_code.py +++ b/source/load_mod_from_source_code.py @@ -1,4 +1,4 @@ -sc = "a=b" +sc = "a='b'" my_name_space = {} exec(sc, my_name_space) -print(my_name_space['a']) \ No newline at end of file +print(my_name_space['a']) diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/tests/__init__.py @@ -0,0 +1 @@ + diff --git a/tests/test_examples.py b/tests/test_examples.py new file mode 100644 index 0000000..a7825a6 --- /dev/null +++ b/tests/test_examples.py @@ -0,0 +1,24 @@ +import contextlib +import io +import runpy +from pathlib import Path +import unittest + + +class ExampleScriptTests(unittest.TestCase): + def test_load_mod_from_source_code_runs(self): + script_path = ( + Path(__file__).resolve().parents[1] + / "source" + / "load_mod_from_source_code.py" + ) + + output = io.StringIO() + with contextlib.redirect_stdout(output): + runpy.run_path(str(script_path)) + + self.assertEqual("b\n", output.getvalue()) + + +if __name__ == "__main__": + unittest.main()