1111)
1212from twyn .dependency_parser .parsers .abstract_parser import AbstractParser
1313from twyn .dependency_parser .parsers .yarn_lock_parser import YarnLockParser
14- from twyn .file_handler .exceptions import PathIsNotFileError , PathNotFoundError
1514
1615
1716class TestAbstractParser :
@@ -22,26 +21,49 @@ def parse(self) -> set[str]:
2221 self ._read ()
2322 return set ()
2423
24+ @patch ("pathlib.Path.stat" )
2525 @patch ("pathlib.Path.exists" )
2626 @patch ("pathlib.Path.is_file" )
27- def test_file_exists (self , mock_exists : Mock , mock_is_file : Mock ) -> None :
27+ def test_file_exists (self , mock_is_file : Mock , mock_exists : Mock , mock_stat : Mock ) -> None :
2828 mock_exists .return_value = True
2929 mock_is_file .return_value = True
30+
31+ # Mock stat to return a mock object with st_size > 0 (non-empty file)
32+ mock_stat_result = Mock ()
33+ mock_stat_result .st_size = 100
34+ mock_stat .return_value = mock_stat_result
35+
3036 parser = self .TemporaryParser ("fake_path.txt" )
3137 assert parser .file_exists () is True
3238
39+ @patch ("pathlib.Path.stat" )
3340 @patch ("pathlib.Path.exists" )
3441 @patch ("pathlib.Path.is_file" )
3542 @pytest .mark .parametrize (
36- ("file_exists" , "is_file" , "exception" ),
37- [(False , False , PathNotFoundError ), (True , False , PathIsNotFileError )],
43+ ("file_exists" , "is_file" , "file_size" ),
44+ [
45+ (False , False , 100 ),
46+ (True , False , 100 ),
47+ (True , True , 0 ),
48+ ],
3849 )
3950 def test_raise_for_valid_file (
40- self , mock_is_file : Mock , mock_exists : Mock , file_exists : Mock , is_file , exception : Mock
51+ self ,
52+ mock_is_file : Mock ,
53+ mock_exists : Mock ,
54+ mock_stat : Mock ,
55+ file_exists : bool ,
56+ is_file : bool ,
57+ file_size : int ,
4158 ) -> None :
4259 mock_exists .return_value = file_exists
4360 mock_is_file .return_value = is_file
4461
62+ # Mock stat to return a mock object with st_size attribute
63+ mock_stat_result = Mock ()
64+ mock_stat_result .st_size = file_size
65+ mock_stat .return_value = mock_stat_result
66+
4567 parser = self .TemporaryParser ("fake_path.txt" )
4668 assert parser .file_exists () is False
4769
0 commit comments