コード例 #1
0
ファイル: test_paths.py プロジェクト: bossjones/ultron8
    def test_file_isWritable(self, mocker: MockFixture) -> None:
        # mock
        mock_os_access = mocker.MagicMock(name="mock_os_access")
        # patch
        mocker.patch.object(ultron8.paths.os, "access", mock_os_access)
        # mock_is_readable_dir = mocker.patch.object(
        #     ultron8.paths, "is_readable_dir", return_value=False, autospec=True
        # )
        mock_is_readable_dir = mocker.patch.object(
            ultron8.paths,
            "is_readable_dir",
            return_value={"result": False},
            autospec=True,
        )

        path = "file:///tmp/fake_file"

        # patch return values
        mock_os_access.return_value = True

        # run test
        result = paths.isWritable(path)

        # tests
        mock_is_readable_dir.assert_called_once_with("file:///tmp/fake_file")
        mock_os_access.assert_called_once_with("file:///tmp", os.W_OK)
        assert result == True
コード例 #2
0
ファイル: test_paths.py プロジェクト: bossjones/ultron8
    def test_mkdir_if_does_not_exist_true(self, mocker: MockFixture) -> None:
        # mock
        mock_mkdir_p = mocker.MagicMock(name="mock_mkdir_p")
        mock_dir_exists = mocker.MagicMock(name="mock_dir_exists", return_value=True)
        # patch
        mocker.patch.object(ultron8.paths, "mkdir_p", mock_mkdir_p)
        mocker.patch.object(ultron8.paths, "dir_exists", mock_dir_exists)

        path = "/opt/ultron8"

        # run test
        result = paths.mkdir_if_does_not_exist(path)

        # assert
        assert mock_mkdir_p.call_count == 0
        assert mock_dir_exists.call_count == 1
        assert result == False
コード例 #3
0
ファイル: test_paths.py プロジェクト: bossjones/ultron8
    def test_mkdir_p(self, mocker: MockFixture) -> None:
        # mock
        # mock_logger_info = mocker.MagicMock(name="mock_logger_info")
        mock_dir_exists = mocker.MagicMock(name="mock_dir_exists")
        mock_path = mocker.MagicMock(name="mock_path")
        # patch

        mocker.patch.object(ultron8.paths, "dir_exists", mock_dir_exists)
        mocker.patch.object(ultron8.paths, "Path", mock_path)

        path = "/opt/ultron8"

        mock_dir_exists.return_value = True

        # run test
        paths.mkdir_p(path)

        # assert
        mock_path.assert_called_once_with(path)

        mock_path().mkdir.assert_any_call(parents=True, exist_ok=True)
コード例 #4
0
ファイル: test_paths.py プロジェクト: bossjones/ultron8
    def test_fname_exists_true(self, mocker: MockFixture) -> None:
        # mock
        mock_path = mocker.MagicMock(name="mock_path")
        # patch
        mocker.patch.object(ultron8.paths, "Path", mock_path)

        path = "/opt/ultron8/generator.dot"

        mock_path_instance = mock_path()

        mock_path_instance.exists.return_value = True

        # run test
        result = paths.fname_exists(path)

        assert mock_path_instance.exists.call_count == 1
        mock_path.assert_any_call(path)
        assert result == True
コード例 #5
0
ファイル: test_paths.py プロジェクト: bossjones/ultron8
    def test_dir_exists_false(self, mocker: MockFixture) -> None:
        # mock
        # mock_logger_error = mocker.MagicMock(name="mock_logger_error")
        mock_path = mocker.MagicMock(name="mock_path")
        # patch
        # mocker.patch.object(
        #     scarlett_os.subprocess.logging.Logger, "error", mock_logger_error
        # )
        mocker.patch.object(ultron8.paths, "Path", mock_path)

        path = "/opt/ultron8"

        mock_path_instance = mock_path()

        mock_path_instance.is_dir.return_value = False

        # run test
        paths.dir_exists(path)

        # assert
        # assert mock_logger_error.call_count == 1
        assert mock_path_instance.is_dir.call_count == 2