def test_base_command_provides_tempdir_helpers(): assert temp_dir._tempdir_manager is None assert temp_dir._tempdir_registry is None def assert_helpers_set(options, args): assert temp_dir._tempdir_manager is not None assert temp_dir._tempdir_registry is not None c = Command("fake", "fake") c.run = Mock(side_effect=assert_helpers_set) assert c.main(["fake"]) == SUCCESS c.run.assert_called_once()
def test_base_command_provides_tempdir_helpers() -> None: assert temp_dir._tempdir_manager is None assert temp_dir._tempdir_registry is None def assert_helpers_set(options: Values, args: List[str]) -> int: assert temp_dir._tempdir_manager is not None assert temp_dir._tempdir_registry is not None return SUCCESS c = Command("fake", "fake") # https://github.com/python/mypy/issues/2427 c.run = Mock(side_effect=assert_helpers_set) # type: ignore[assignment] assert c.main(["fake"]) == SUCCESS c.run.assert_called_once()
def test_base_command_local_tempdir_cleanup(kind, exists): assert temp_dir._tempdir_manager is None assert temp_dir._tempdir_registry is None def create_temp_dirs(options, args): c.tempdir_registry.set_delete(not_deleted, False) with TempDirectory(kind=kind) as d: path = d.path assert os.path.exists(path) assert os.path.exists(path) == exists c = Command("fake", "fake") c.run = Mock(side_effect=create_temp_dirs) assert c.main(["fake"]) == SUCCESS c.run.assert_called_once()
def test_base_command_global_tempdir_cleanup(kind, exists): assert temp_dir._tempdir_manager is None assert temp_dir._tempdir_registry is None class Holder(object): value = None def create_temp_dirs(options, args): c.tempdir_registry.set_delete(not_deleted, False) Holder.value = TempDirectory(kind=kind, globally_managed=True).path c = Command("fake", "fake") c.run = Mock(side_effect=create_temp_dirs) assert c.main(["fake"]) == SUCCESS c.run.assert_called_once() assert os.path.exists(Holder.value) == exists
def test_base_command_local_tempdir_cleanup(kind: str, exists: bool) -> None: assert temp_dir._tempdir_manager is None assert temp_dir._tempdir_registry is None def create_temp_dirs(options: Values, args: List[str]) -> int: assert c.tempdir_registry is not None c.tempdir_registry.set_delete(not_deleted, False) with TempDirectory(kind=kind) as d: path = d.path assert os.path.exists(path) assert os.path.exists(path) == exists return SUCCESS c = Command("fake", "fake") # https://github.com/python/mypy/issues/2427 c.run = Mock(side_effect=create_temp_dirs) # type: ignore[assignment] assert c.main(["fake"]) == SUCCESS c.run.assert_called_once()