File tree Expand file tree Collapse file tree 2 files changed +8
-2
lines changed
Expand file tree Collapse file tree 2 files changed +8
-2
lines changed Original file line number Diff line number Diff line change 88class OSProxy (types .ModuleType ):
99 """Proxy module to intercept os attribute access."""
1010 overrides = {}
11+
1112 def __init__ (self , real_os ):
1213 super ().__init__ ("os" )
1314 self ._real_os = real_os
@@ -23,6 +24,7 @@ def __dir__(self):
2324 def register_override (cls , name , value ):
2425 cls .overrides [name ] = value
2526
27+
2628class OSFinder (importlib .abc .MetaPathFinder ):
2729 """Meta path finder to intercept imports of 'os' and return our proxy."""
2830 def find_spec (self , fullname , path , target = None ):
Original file line number Diff line number Diff line change 5050_contextes = {'' : {}}
5151_curr_context = ''
5252
53- def set_context (context_name , context = {} ):
53+ def set_context (context_name , context = None ):
5454 """
5555 Set context for tracking environment changes.
5656 """
@@ -63,6 +63,7 @@ def set_context(context_name, context = {}):
6363 context = {}
6464 _contextes [context_name ] = context
6565
66+
6667def get_context ():
6768 """
6869 Return current context for tracking environment changes.
@@ -95,6 +96,7 @@ def get_changes():
9596 """
9697 return get_context ()
9798
99+
98100def apply_context (context = None ):
99101 """Return the current environment with the changes tracked in the context applied.
100102
@@ -127,8 +129,10 @@ def with_environment(copy_current=False):
127129 # Get a key that does not exist in _contextes
128130 base = '_context_'
129131 cnt = 0
130- while (context := f"{ base } { cnt } " ) in _contextes :
132+ context = f"{ base } { cnt } "
133+ while context in _contextes :
131134 cnt += 1
135+ context = f"{ base } { cnt } "
132136
133137 prev_context = _curr_context
134138 kwargs = {}
You can’t perform that action at this time.
0 commit comments