11from unittest .mock import patch
22
33import pytest
4- from twyn .base .exceptions import TwynError
54from twyn .dependency_parser import PoetryLockParser , RequirementsTxtParser
65from twyn .dependency_parser .abstract_parser import AbstractParser
7- from twyn .dependency_parser .exceptions import PathIsNotFileError , PathNotFoundError
6+ from twyn .file_handler .exceptions import PathIsNotFileError , PathNotFoundError
87
98
109class TestAbstractParser :
@@ -15,34 +14,26 @@ def parse(self) -> set[str]:
1514 self ._read ()
1615 return set ()
1716
18- @patch ("twyn.dependency_parser.abstract_parser.AbstractParser.raise_for_valid_file" )
19- def test_file_exists_success (self , _mock_raise_for_valid_file ):
17+ @patch ("pathlib.Path.exists" )
18+ @patch ("pathlib.Path.is_file" )
19+ def test_file_exists (self , _mock_exists , _mock_is_file ):
20+ _mock_exists .return_value = True
21+ _mock_is_file .return_value = True
2022 parser = self .TemporaryParser ("fake_path.txt" )
2123 assert parser .file_exists () is True
2224
23- @patch ("twyn.dependency_parser.abstract_parser.AbstractParser.raise_for_valid_file" )
24- def test_file_exists_fail (self , mock_raise_for_valid_file ):
25- def raise_twyn_error ():
26- raise TwynError
27-
28- mock_raise_for_valid_file .side_effect = raise_twyn_error
29- parser = self .TemporaryParser ("fake_path.txt" )
30- assert parser .file_exists () is False
31-
3225 @patch ("pathlib.Path.exists" )
3326 @patch ("pathlib.Path.is_file" )
3427 @pytest .mark .parametrize (
3528 "file_exists, is_file, exception" ,
3629 [[False , False , PathNotFoundError ], [True , False , PathIsNotFileError ]],
3730 )
38- def test_raise_for_valid_file (
39- self , mock_is_file , mock_exists , file_exists , is_file , exception
40- ):
31+ def test_raise_for_valid_file (self , mock_is_file , mock_exists , file_exists , is_file , exception ):
4132 mock_exists .return_value = file_exists
4233 mock_is_file .return_value = is_file
4334
44- with pytest . raises ( exception ):
45- self . TemporaryParser ( "fake_path" ). raise_for_valid_file ()
35+ parser = self . TemporaryParser ( "fake_path.txt" )
36+ assert parser . file_exists () is False
4637
4738
4839class TestRequirementsTxtParser :
0 commit comments