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
14+ from twyn .file_handler .exceptions import EmptyFileError , PathIsNotFileError , PathNotFoundError
1515
1616
1717class TestAbstractParser :
@@ -22,26 +22,50 @@ def parse(self) -> set[str]:
2222 self ._read ()
2323 return set ()
2424
25+ @patch ("pathlib.Path.stat" )
2526 @patch ("pathlib.Path.exists" )
2627 @patch ("pathlib.Path.is_file" )
27- def test_file_exists (self , mock_exists : Mock , mock_is_file : Mock ) -> None :
28+ def test_file_exists (self , mock_is_file : Mock , mock_exists : Mock , mock_stat : Mock ) -> None :
2829 mock_exists .return_value = True
2930 mock_is_file .return_value = True
31+
32+ # Mock stat to return a mock object with st_size > 0 (non-empty file)
33+ mock_stat_result = Mock ()
34+ mock_stat_result .st_size = 100
35+ mock_stat .return_value = mock_stat_result
36+
3037 parser = self .TemporaryParser ("fake_path.txt" )
3138 assert parser .file_exists () is True
3239
40+ @patch ("pathlib.Path.stat" )
3341 @patch ("pathlib.Path.exists" )
3442 @patch ("pathlib.Path.is_file" )
3543 @pytest .mark .parametrize (
36- ("file_exists" , "is_file" , "exception" ),
37- [(False , False , PathNotFoundError ), (True , False , PathIsNotFileError )],
44+ ("file_exists" , "is_file" , "file_size" , "exception" ),
45+ [
46+ (False , False , 100 , PathNotFoundError ),
47+ (True , False , 100 , PathIsNotFileError ),
48+ (True , True , 0 , EmptyFileError ),
49+ ],
3850 )
3951 def test_raise_for_valid_file (
40- self , mock_is_file : Mock , mock_exists : Mock , file_exists : Mock , is_file , exception : Mock
52+ self ,
53+ mock_is_file : Mock ,
54+ mock_exists : Mock ,
55+ mock_stat : Mock ,
56+ file_exists : bool ,
57+ is_file : bool ,
58+ file_size : int ,
59+ exception : type ,
4160 ) -> None :
4261 mock_exists .return_value = file_exists
4362 mock_is_file .return_value = is_file
4463
64+ # Mock stat to return a mock object with st_size attribute
65+ mock_stat_result = Mock ()
66+ mock_stat_result .st_size = file_size
67+ mock_stat .return_value = mock_stat_result
68+
4569 parser = self .TemporaryParser ("fake_path.txt" )
4670 assert parser .file_exists () is False
4771
0 commit comments