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()