コード例 #1
0
    def test_mkdir_if_needed_raises_oserror_when_mkdir_fails(self, mock_mkdirs):
        """ Tests invocation of API mkdir_if_needed raises OSError when makedirs raises OSError"""
        # arrange
        dir_path = 'blah'
        mock_mkdirs.side_effect = OSError(errno.EACCES, 'Directory permission error')

        # act, assert
        with self.assertRaises(OSError):
            Utils.mkdir_if_needed(dir_path)
コード例 #2
0
    def test_mkdir_if_needed_when_dir_does_not_exist(self, mock_mkdirs):
        """ Test a valid invocation of API mkdir_if_needed when dir to be made does not exist """
        # arrange
        dir_path = 'blah'

        # act
        Utils.mkdir_if_needed(dir_path)

        # assert
        mock_mkdirs.assert_called_with(dir_path)
コード例 #3
0
    def test_mkdir_if_needed_when_dir_exists(self, mock_mkdirs):
        """ Test a valid invocation of API mkdir_if_needed when dir to be made already exists """
        # arrange
        dir_path = 'blah'
        mock_mkdirs.side_effect = OSError(errno.EEXIST, 'Directory exists.')

        # act
        Utils.mkdir_if_needed(dir_path)

        # assert
        mock_mkdirs.assert_called_with(dir_path)