File tree Expand file tree Collapse file tree 2 files changed +20
-7
lines changed Expand file tree Collapse file tree 2 files changed +20
-7
lines changed Original file line number Diff line number Diff line change @@ -108,7 +108,12 @@ def create(path: str) -> None:
108108 :param string path: path name
109109 """
110110 log .debug ("Creating directory %s" , path )
111- pathlib .Path (path ).mkdir (parents = True , exist_ok = True )
111+ try :
112+ pathlib .Path (path ).mkdir (parents = True , exist_ok = True )
113+ except Exception as issue :
114+ raise KiwiFileAccessError (
115+ f'Cannot create directory: { path } : { issue } '
116+ )
112117
113118 @staticmethod
114119 def wipe (path : str ) -> None :
Original file line number Diff line number Diff line change 11import logging
2- import pathlib
3- from unittest .mock import patch , call
2+ from unittest .mock import (
3+ patch , call , Mock
4+ )
45from pytest import (
56 raises , fixture
67)
@@ -24,10 +25,17 @@ def test_sort_by_hierarchy(self):
2425 )
2526 assert ordered == ['usr' , 'etc' , 'usr/bin' , 'usr/lib' ]
2627
27- def test_create (self , tmp_path : pathlib .Path ):
28- dest = tmp_path / "foo" / "bar" / "baz"
29- Path .create (str (dest ))
30- assert pathlib .Path (dest ).exists ()
28+ @patch ('pathlib.Path' )
29+ def test_create (self , mock_Path ):
30+ path = Mock ()
31+ mock_Path .return_value = path
32+ Path .create ('foo' )
33+ path .mkdir .assert_called_once_with (
34+ parents = True , exist_ok = True
35+ )
36+ mock_Path .return_value = Exception
37+ with raises (KiwiFileAccessError ):
38+ Path .create ('foo' )
3139
3240 @patch ('kiwi.command.os.path.exists' )
3341 @patch ('kiwi.command.Command.run' )
You can’t perform that action at this time.
0 commit comments