@@ -19,12 +19,15 @@ def pytest_ignore_collect(collection_path: pathlib.Path) -> bool:
1919 "test_clone.py" ,
2020 "test_commit.py" ,
2121 "test_config.py" ,
22+ "test_diff.py" ,
23+ "test_fetch.py" ,
2224 "test_fixtures.py" ,
2325 "test_git.py" ,
2426 "test_init.py" ,
2527 "test_log.py" ,
2628 "test_merge.py" ,
2729 "test_mv.py" ,
30+ "test_push.py" ,
2831 "test_rebase.py" ,
2932 "test_remote.py" ,
3033 "test_reset.py" ,
@@ -33,6 +36,7 @@ def pytest_ignore_collect(collection_path: pathlib.Path) -> bool:
3336 "test_rm.py" ,
3437 "test_stash.py" ,
3538 "test_status.py" ,
39+ "test_tag.py" ,
3640 ]
3741
3842
@@ -54,18 +58,6 @@ def load_page(page: Page):
5458 page .locator ("#loaded" ).wait_for ()
5559
5660
57- def os_chdir (dir : str ):
58- subprocess .run (["cd" , str (dir )], capture_output = True , check = True , text = True )
59-
60-
61- def os_getcwd ():
62- return subprocess .run (["pwd" ], capture_output = True , check = True , text = True ).stdout .strip ()
63-
64-
65- def os_remove (file : str ):
66- return subprocess .run (["rm" , str (file )], capture_output = True , check = True , text = True )
67-
68-
6961class MockPath (pathlib .Path ):
7062 def __init__ (self , path : str = "" ):
7163 super ().__init__ (path )
@@ -95,26 +87,62 @@ def mkdir(self, *, parents=False):
9587 args .append ("-p" )
9688 subprocess .run (["mkdir" ] + args , capture_output = True , text = True , check = True )
9789
90+ def read_bytes (self ) -> bytes :
91+ raise RuntimeError ("Not implemented" )
92+
9893 def read_text (self ) -> str :
9994 p = subprocess .run (["cat" , str (self )], capture_output = True , text = True , check = True )
10095 text = p .stdout
10196 if text .endswith ("\n " ):
10297 text = text [:- 1 ]
10398 return text
10499
100+ def write_bytes (self , data : bytes ):
101+ # Convert binary data to a string where each element is backslash-escaped so that we can
102+ # write to file in cockle using `echo -e <backslash-escaped data>`.
103+ encoded_string = "" .join (map (lambda d : f"\\ x{ d :02x} " , data ))
104+ cmd = ["echo" , "-e" , encoded_string , ">" , str (self )]
105+ subprocess .run (cmd , capture_output = True , text = True , check = True )
106+ return len (data )
107+
105108 def write_text (self , data : str ):
106109 # Note that in general it is not valid to direct output of a subprocess.run call to a file,
107110 # but we get away with it here as the command arguments are passed straight through to
108111 # cockle without being checked.
109- p = subprocess .run (["echo" , data , ">" , str (self )], capture_output = True , text = True )
110- assert p .returncode == 0
112+ if data .endswith ("\n " ):
113+ data = data [:- 1 ]
114+ cmd = ["echo" , data , ">" , str (self )]
115+ subprocess .run (cmd , capture_output = True , text = True , check = True )
116+ return len (data )
111117
112118 def __truediv__ (self , other ):
113119 if isinstance (other , str ):
114120 return MockPath (f"{ self } /{ other } " )
115121 raise RuntimeError ("MockPath.__truediv__ only supports strings" )
116122
117123
124+ def os_chdir (dir : str ):
125+ subprocess .run (["cd" , str (dir )], capture_output = True , check = True , text = True )
126+
127+
128+ def os_getcwd ():
129+ return subprocess .run (["pwd" ], capture_output = True , check = True , text = True ).stdout .strip ()
130+
131+
132+ def os_remove (file : str ):
133+ return subprocess .run (["rm" , str (file )], capture_output = True , check = True , text = True )
134+
135+
136+ def os_rename (src : str | MockPath , dst : str | MockPath ):
137+ return subprocess .run (["mv" , str (src ), str (dst )], capture_output = True , check = True , text = True )
138+
139+
140+ def os_symlink (src : str | MockPath , dst : str | MockPath ):
141+ return subprocess .run (
142+ ["ln" , "-s" , str (src ), str (dst )], capture_output = True , check = True , text = True
143+ )
144+
145+
118146def subprocess_run (
119147 page : Page ,
120148 cmd : list [str ],
@@ -192,3 +220,5 @@ def mock_subprocess_run(page: Page, monkeypatch):
192220 monkeypatch .setattr (os , "chdir" , os_chdir )
193221 monkeypatch .setattr (os , "getcwd" , os_getcwd )
194222 monkeypatch .setattr (os , "remove" , os_remove )
223+ monkeypatch .setattr (os , "rename" , os_rename )
224+ monkeypatch .setattr (os , "symlink" , os_symlink )
0 commit comments