@ -49,16 +49,18 @@ def mock_lchmod(mocker):
yield m_lchmod
yield m_lchmod
@pytest.mark.parametrize ( ' previous_changes, check_mode, stdin' ,
@pytest.mark.parametrize ( ' previous_changes, check_mode, exists, stdin' ,
product ( ( True , False ) , ( True , False ) , ( { } , ) ) ,
product ( ( True , False ) , ( True , False ) , ( True , False ) , ( { } , ) ) ,
indirect = [ ' stdin ' ] )
indirect = [ ' stdin ' ] )
def test_no_mode_given_returns_previous_changes ( am , mock_stats , mock_lchmod , mocker , previous_changes , check_mode ):
def test_no_mode_given_returns_previous_changes ( am , mock_stats , mock_lchmod , mocker , previous_changes , check_mode , exists ):
am . check_mode = check_mode
am . check_mode = check_mode
mocker . patch ( ' os.lstat ' , side_effect = [ mock_stats [ ' before ' ] ] )
mocker . patch ( ' os.lstat ' , side_effect = [ mock_stats [ ' before ' ] ] )
m_lchmod = mocker . patch ( ' os.lchmod ' , return_value = None , create = True )
m_lchmod = mocker . patch ( ' os.lchmod ' , return_value = None , create = True )
m_path_exists = mocker . patch ( ' os.path.exists ' , return_value = exists )
assert am . set_mode_if_different ( ' /path/to/file ' , None , previous_changes ) == previous_changes
assert am . set_mode_if_different ( ' /path/to/file ' , None , previous_changes ) == previous_changes
assert not m_lchmod . called
assert not m_lchmod . called
assert not m_path_exists . called
@pytest.mark.parametrize ( ' mode, check_mode, stdin ' ,
@pytest.mark.parametrize ( ' mode, check_mode, stdin ' ,
@ -71,6 +73,7 @@ def test_mode_changed_to_0660(am, mock_stats, mocker, mode, check_mode):
am . check_mode = check_mode
am . check_mode = check_mode
mocker . patch ( ' os.lstat ' , side_effect = [ mock_stats [ ' before ' ] , mock_stats [ ' after ' ] , mock_stats [ ' after ' ] ] )
mocker . patch ( ' os.lstat ' , side_effect = [ mock_stats [ ' before ' ] , mock_stats [ ' after ' ] , mock_stats [ ' after ' ] ] )
m_lchmod = mocker . patch ( ' os.lchmod ' , return_value = None , create = True )
m_lchmod = mocker . patch ( ' os.lchmod ' , return_value = None , create = True )
mocker . patch ( ' os.path.exists ' , return_value = True )
assert am . set_mode_if_different ( ' /path/to/file ' , mode , False )
assert am . set_mode_if_different ( ' /path/to/file ' , mode , False )
if check_mode :
if check_mode :
@ -89,6 +92,7 @@ def test_mode_unchanged_when_already_0660(am, mock_stats, mocker, mode, check_mo
am . check_mode = check_mode
am . check_mode = check_mode
mocker . patch ( ' os.lstat ' , side_effect = [ mock_stats [ ' after ' ] , mock_stats [ ' after ' ] , mock_stats [ ' after ' ] ] )
mocker . patch ( ' os.lstat ' , side_effect = [ mock_stats [ ' after ' ] , mock_stats [ ' after ' ] , mock_stats [ ' after ' ] ] )
m_lchmod = mocker . patch ( ' os.lchmod ' , return_value = None , create = True )
m_lchmod = mocker . patch ( ' os.lchmod ' , return_value = None , create = True )
mocker . patch ( ' os.path.exists ' , return_value = True )
assert not am . set_mode_if_different ( ' /path/to/file ' , mode , False )
assert not am . set_mode_if_different ( ' /path/to/file ' , mode , False )
assert not m_lchmod . called
assert not m_lchmod . called
@ -111,6 +115,7 @@ def test_missing_lchmod_is_not_link(am, mock_stats, mocker, check_mode):
mocker . patch ( ' os.lstat ' , side_effect = [ mock_stats [ ' before ' ] , mock_stats [ ' after ' ] ] )
mocker . patch ( ' os.lstat ' , side_effect = [ mock_stats [ ' before ' ] , mock_stats [ ' after ' ] ] )
mocker . patch . object ( builtins , ' hasattr ' , side_effect = _hasattr )
mocker . patch . object ( builtins , ' hasattr ' , side_effect = _hasattr )
mocker . patch ( ' os.path.islink ' , return_value = False )
mocker . patch ( ' os.path.islink ' , return_value = False )
mocker . patch ( ' os.path.exists ' , return_value = True )
m_chmod = mocker . patch ( ' os.chmod ' , return_value = None )
m_chmod = mocker . patch ( ' os.chmod ' , return_value = None )
assert am . set_mode_if_different ( ' /path/to/file/no_lchmod ' , 0o660 , False )
assert am . set_mode_if_different ( ' /path/to/file/no_lchmod ' , 0o660 , False )
@ -137,6 +142,7 @@ def test_missing_lchmod_is_link(am, mock_stats, mocker, check_mode):
mocker . patch ( ' os.lstat ' , side_effect = [ mock_stats [ ' before ' ] , mock_stats [ ' after ' ] ] )
mocker . patch ( ' os.lstat ' , side_effect = [ mock_stats [ ' before ' ] , mock_stats [ ' after ' ] ] )
mocker . patch . object ( builtins , ' hasattr ' , side_effect = _hasattr )
mocker . patch . object ( builtins , ' hasattr ' , side_effect = _hasattr )
mocker . patch ( ' os.path.islink ' , return_value = True )
mocker . patch ( ' os.path.islink ' , return_value = True )
mocker . patch ( ' os.path.exists ' , return_value = True )
m_chmod = mocker . patch ( ' os.chmod ' , return_value = None )
m_chmod = mocker . patch ( ' os.chmod ' , return_value = None )
mocker . patch ( ' os.stat ' , return_value = mock_stats [ ' after ' ] )
mocker . patch ( ' os.stat ' , return_value = mock_stats [ ' after ' ] )