@@ -978,7 +978,12 @@ def test_repo_helper() -> None:
978978 code_ctx = get_code_optimization_context (function_to_optimize , project_root )
979979 read_write_context , read_only_context = code_ctx .read_writable_code , code_ctx .read_only_context_code
980980 hashing_context = code_ctx .hashing_code_context
981+ path_to_globals = project_root / "globals.py"
981982 expected_read_write_context = f"""
983+ ```python:{ path_to_globals .relative_to (project_root )}
984+ # Define a global variable
985+ API_URL = "https://api.example.com/data"
986+ ```
982987```python:{ path_to_utils .relative_to (project_root )}
983988import math
984989
@@ -1071,7 +1076,12 @@ def test_repo_helper_of_helper() -> None:
10711076 code_ctx = get_code_optimization_context (function_to_optimize , project_root )
10721077 read_write_context , read_only_context = code_ctx .read_writable_code , code_ctx .read_only_context_code
10731078 hashing_context = code_ctx .hashing_code_context
1079+ path_to_globals = project_root / "globals.py"
10741080 expected_read_write_context = f"""
1081+ ```python:{ path_to_globals .relative_to (project_root )}
1082+ # Define a global variable
1083+ API_URL = "https://api.example.com/data"
1084+ ```
10751085```python:{ path_to_utils .relative_to (project_root )}
10761086import math
10771087from transform_utils import DataTransformer
@@ -1798,6 +1808,8 @@ def calculate(self, operation, x, y):
17981808"""
17991809 expected_read_only_context = """
18001810```python:utility_module.py
1811+ import sys
1812+
18011813DEFAULT_PRECISION = "medium"
18021814
18031815# Try-except block with variable definitions
@@ -1808,6 +1820,17 @@ def calculate(self, operation, x, y):
18081820 # Used variable in except block
18091821 CALCULATION_BACKEND = "python"
18101822
1823+ # Nested if-else with variable definitions
1824+ if sys.platform.startswith('win'):
1825+ # Used variable in outer if
1826+ SYSTEM_TYPE = "windows"
1827+ elif sys.platform.startswith('linux'):
1828+ # Used variable in outer elif
1829+ SYSTEM_TYPE = "linux"
1830+ else:
1831+ # Used variable in outer else
1832+ SYSTEM_TYPE = "other"
1833+
18111834# Function that will be used in the main code
18121835def select_precision(precision, fallback_precision):
18131836 if precision is None:
@@ -2014,6 +2037,8 @@ def get_system_details():
20142037 relative_path = file_path .relative_to (project_root )
20152038 expected_read_write_context = f"""
20162039```python:utility_module.py
2040+ import sys
2041+
20172042DEFAULT_PRECISION = "medium"
20182043
20192044# Try-except block with variable definitions
@@ -2024,6 +2049,17 @@ def get_system_details():
20242049 # Used variable in except block
20252050 CALCULATION_BACKEND = "python"
20262051
2052+ # Nested if-else with variable definitions
2053+ if sys.platform.startswith('win'):
2054+ # Used variable in outer if
2055+ SYSTEM_TYPE = "windows"
2056+ elif sys.platform.startswith('linux'):
2057+ # Used variable in outer elif
2058+ SYSTEM_TYPE = "linux"
2059+ else:
2060+ # Used variable in outer else
2061+ SYSTEM_TYPE = "other"
2062+
20272063# Function that will be used in the main code
20282064def select_precision(precision, fallback_precision):
20292065 if precision is None:
@@ -2064,6 +2100,8 @@ def __init__(self, precision="high", fallback_precision=None, mode="standard"):
20642100"""
20652101 expected_read_only_context = """
20662102```python:utility_module.py
2103+ import sys
2104+
20672105DEFAULT_PRECISION = "medium"
20682106
20692107# Try-except block with variable definitions
@@ -2073,6 +2111,17 @@ def __init__(self, precision="high", fallback_precision=None, mode="standard"):
20732111except ImportError:
20742112 # Used variable in except block
20752113 CALCULATION_BACKEND = "python"
2114+
2115+ # Nested if-else with variable definitions
2116+ if sys.platform.startswith('win'):
2117+ # Used variable in outer if
2118+ SYSTEM_TYPE = "windows"
2119+ elif sys.platform.startswith('linux'):
2120+ # Used variable in outer elif
2121+ SYSTEM_TYPE = "linux"
2122+ else:
2123+ # Used variable in outer else
2124+ SYSTEM_TYPE = "other"
20762125```
20772126"""
20782127 assert read_write_context .markdown .strip () == expected_read_write_context .strip ()
0 commit comments