@@ -121,6 +121,16 @@ def extend_file(path, content):
121121 print (line , file = existing_file )
122122
123123
124+ def replace_in_file (path : str , old : str , new : str ) -> None :
125+ with open (path , "r" , encoding = "utf-8" ) as f :
126+ content = f .read ()
127+
128+ content = content .replace (old , new )
129+
130+ with open (path , "w" , encoding = "utf-8" ) as f :
131+ f .write (content )
132+
133+
124134def list_dir (path ):
125135 # Get list of all nodes
126136 nodes = [os .path .normpath (path ).split (os .sep )]
@@ -144,6 +154,11 @@ def list_dir(path):
144154 return result
145155
146156
157+ @given ('"{old}" is replaced with "{new}" in "{path}"' )
158+ def step_impl (_ , old : str , new : str , path : str ):
159+ replace_in_file (path , old , new )
160+
161+
147162@given ("the patch file '{name}'" )
148163def step_impl (context , name ):
149164 generate_file (os .path .join (os .getcwd (), name ), context .text )
@@ -187,6 +202,7 @@ def step_impl(context, args, path=None):
187202 call_command (context , args .split (), path )
188203
189204
205+ @given ('"{path}" in {directory} is changed locally' )
190206@when ('"{path}" in {directory} is changed locally' )
191207def step_impl (_ , directory , path ):
192208 with in_directory (directory ):
0 commit comments