From 389b1a9daa7f00615807d12ce571bd9f72b44034 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Sat, 23 May 2026 11:05:14 +0000 Subject: [PATCH] Fix source-code loading example crash 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_load_mod_from_source_code.py | 24 ++++++++++++++++++++++++ 3 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 tests/__init__.py create mode 100644 tests/test_load_mod_from_source_code.py diff --git a/source/load_mod_from_source_code.py b/source/load_mod_from_source_code.py index b2204a5..a9a87b1 100644 --- a/source/load_mod_from_source_code.py +++ b/source/load_mod_from_source_code.py @@ -1,4 +1,4 @@ sc = "a=b" -my_name_space = {} +my_name_space = {"b": "b"} 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_load_mod_from_source_code.py b/tests/test_load_mod_from_source_code.py new file mode 100644 index 0000000..230a0a8 --- /dev/null +++ b/tests/test_load_mod_from_source_code.py @@ -0,0 +1,24 @@ +import subprocess +import sys +import unittest +from pathlib import Path + + +class LoadModFromSourceCodeTestCase(unittest.TestCase): + def test_example_runs_and_prints_loaded_value(self): + repo_root = Path(__file__).resolve().parents[1] + + result = subprocess.run( + [sys.executable, str(repo_root / "source" / "load_mod_from_source_code.py")], + check=False, + capture_output=True, + text=True, + ) + + self.assertEqual("", result.stderr) + self.assertEqual(0, result.returncode) + self.assertEqual("b\n", result.stdout) + + +if __name__ == "__main__": + unittest.main()