Remove duplicate import in test

This commit is contained in:
thePR0M3TH3AN
2025-08-05 22:18:26 -04:00
parent 1870614d8a
commit 6888fa2431
8 changed files with 138 additions and 53 deletions

View File

@@ -38,13 +38,16 @@ from .atomic_write import atomic_write
# Optional clipboard support
try: # pragma: no cover - exercised when dependency missing
from .clipboard import copy_to_clipboard
from .clipboard import ClipboardUnavailableError, copy_to_clipboard
except Exception as exc: # pragma: no cover - executed only if pyperclip missing
class ClipboardUnavailableError(RuntimeError):
"""Stub exception when clipboard support is unavailable."""
def copy_to_clipboard(*_args, **_kwargs):
"""Stub when clipboard support is unavailable."""
logger.warning("Clipboard support unavailable: %s", exc)
return False
raise ClipboardUnavailableError(str(exc))
__all__ = [
@@ -69,6 +72,7 @@ __all__ = [
"timed_input",
"InMemorySecret",
"copy_to_clipboard",
"ClipboardUnavailableError",
"clear_screen",
"clear_and_print_fingerprint",
"clear_header_with_notification",

View File

@@ -1,3 +1,5 @@
"""Clipboard utility helpers."""
import logging
import shutil
import sys
@@ -5,6 +7,11 @@ import threading
import pyperclip
class ClipboardUnavailableError(RuntimeError):
"""Raised when required clipboard utilities are not installed."""
logger = logging.getLogger(__name__)
@@ -15,31 +22,17 @@ def _ensure_clipboard() -> None:
except pyperclip.PyperclipException as exc:
if sys.platform.startswith("linux"):
if shutil.which("xclip") is None and shutil.which("xsel") is None:
raise pyperclip.PyperclipException(
raise ClipboardUnavailableError(
"Clipboard support requires the 'xclip' package. "
"Install it with 'sudo apt install xclip' and restart SeedPass."
"Install it with 'sudo apt install xclip' and restart SeedPass.",
) from exc
raise
def copy_to_clipboard(text: str, timeout: int) -> bool:
"""Copy text to the clipboard and clear after timeout seconds if unchanged.
"""Copy text to the clipboard and clear after ``timeout`` seconds if unchanged."""
Returns True if the text was successfully copied, False otherwise.
"""
try:
_ensure_clipboard()
except pyperclip.PyperclipException as exc:
warning = (
"Clipboard unavailable: "
+ str(exc)
+ "\nSeedPass secret mode requires clipboard support. "
"Install xclip or disable secret mode to view secrets."
)
logger.warning(warning)
print(warning)
return False
_ensure_clipboard()
pyperclip.copy(text)
@@ -51,3 +44,6 @@ def copy_to_clipboard(text: str, timeout: int) -> bool:
timer.daemon = True
timer.start()
return True
__all__ = ["copy_to_clipboard", "ClipboardUnavailableError"]