Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 11 additions & 28 deletions tests/test_commands/test_async_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,21 @@
"""

import asyncio
import os
import sys
import termios
import threading
import time

import pytest

import recline
from recline.commands.async_command import AsyncCommand
from recline.commands.async_command import (
AsyncCommand,
CommandBackgrounded,
CommandCancelled,
set_terminal_echo,
)


@pytest.mark.usefixtures("clean_jobs")
Expand Down Expand Up @@ -111,8 +121,6 @@ async def test_coro():
def test_command_backgrounded_exception():
"""Verify CommandBackgrounded carries its job_pid attribute."""

from recline.commands.async_command import CommandBackgrounded

exc = CommandBackgrounded(42)
assert exc.job_pid == 42

Expand All @@ -121,8 +129,6 @@ def test_command_backgrounded_exception():
def test_command_cancelled_exception():
"""Verify CommandCancelled carries its job_pid attribute."""

from recline.commands.async_command import CommandCancelled

exc = CommandCancelled(99)
assert exc.job_pid == 99

Expand Down Expand Up @@ -159,8 +165,6 @@ async def test_coro():
def test_async_command_foreground_killed():
"""Verify that foreground() raises CommandCancelled when the thread was killed."""

from recline.commands.async_command import CommandCancelled

i_was_started = False

@recline.command(name="test")
Expand Down Expand Up @@ -190,9 +194,6 @@ def test_async_command_foreground_backgrounded():
to the background while foreground() is waiting.
"""

import time
from recline.commands.async_command import CommandBackgrounded

ready = [False]

@recline.command(name="test")
Expand All @@ -211,7 +212,6 @@ def do_background():
time.sleep(0.05)
thread.background()

import threading
t = threading.Thread(target=do_background)
t.start()

Expand All @@ -227,9 +227,6 @@ def do_background():
def test_set_terminal_echo_no_termios(monkeypatch):
"""Verify set_terminal_echo gracefully yields when termios is unavailable (e.g. Windows)."""

import sys
from recline.commands.async_command import set_terminal_echo

# Setting termios to None in sys.modules causes 'import termios' to raise ImportError
monkeypatch.setitem(sys.modules, "termios", None)

Expand All @@ -242,11 +239,6 @@ def test_set_terminal_echo_no_termios(monkeypatch):
def test_set_terminal_echo_with_tty(monkeypatch):
"""Verify set_terminal_echo modifies echo when stdin is a real TTY."""

import os
import sys
import termios
from recline.commands.async_command import set_terminal_echo

fake_attrs = [0, 0, 0, termios.ECHO, 0, 0, [b'\x00'] * 19]
set_calls = []

Expand All @@ -265,11 +257,6 @@ def test_set_terminal_echo_with_tty(monkeypatch):
def test_set_terminal_echo_enabled_true(monkeypatch):
"""Verify set_terminal_echo correctly enables ECHO (covering the enabled=True branch)."""

import os
import sys
import termios
from recline.commands.async_command import set_terminal_echo

# Start with ECHO disabled (bit not set)
fake_attrs = [0, 0, 0, 0, 0, 0, [b'\x00'] * 19]
set_calls = []
Expand All @@ -288,10 +275,6 @@ def test_set_terminal_echo_enabled_true(monkeypatch):
def test_set_terminal_echo_non_tty(monkeypatch):
"""Verify set_terminal_echo yields without changes when stdin is not a TTY."""

import os
import sys
from recline.commands.async_command import set_terminal_echo

monkeypatch.setattr(sys.stdin, "fileno", lambda: 0)
monkeypatch.setattr(os, "isatty", lambda fd: False)

Expand Down
23 changes: 2 additions & 21 deletions tests/test_commands/test_builtin_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@
A test module for the recline.commands.builtin_commands module
"""

import curses
import pdb
import pudb
import pytest

import recline
from recline.commands import builtin_commands
from recline.commands import ReclineCommandError, builtin_commands
from recline.commands.cli_command import CLICommand


Expand Down Expand Up @@ -124,8 +125,6 @@ def test_man_commands_returns_non_aliases():
def test_exit_command_with_jobs_decline(monkeypatch):
"""Verify exit_command() with backgrounded jobs does NOT exit if user declines."""

import recline

monkeypatch.setattr(recline, "JOBS", {1: object()})
monkeypatch.setattr("builtins.input", lambda _: "n")
# Should return without raising SystemExit
Expand All @@ -135,8 +134,6 @@ def test_exit_command_with_jobs_decline(monkeypatch):
def test_exit_command_with_jobs_accept(monkeypatch):
"""Verify exit_command() with backgrounded jobs exits when user confirms."""

import recline

class _FakeJob:
def stop(self, dont_delete=False):
pass
Expand All @@ -151,8 +148,6 @@ def stop(self, dont_delete=False):
def test_exit_command_abort_jobs(monkeypatch):
"""Verify exit_command() with abort_jobs=True cleans up jobs and exits."""

import recline

stopped = []

class _FakeJob:
Expand All @@ -168,9 +163,6 @@ def stop(self, dont_delete=False):
def test_fg_no_jobs(monkeypatch):
"""Verify fg() raises ReclineCommandError when there are no jobs."""

import recline
from recline.commands import ReclineCommandError

monkeypatch.setattr(recline, "JOBS", {})
with pytest.raises(ReclineCommandError, match="No running jobs"):
builtin_commands.fg()
Expand All @@ -179,9 +171,6 @@ def test_fg_no_jobs(monkeypatch):
def test_fg_invalid_job(monkeypatch):
"""Verify fg() raises ReclineCommandError for an unknown job ID."""

import recline
from recline.commands import ReclineCommandError

monkeypatch.setattr(recline, "JOBS", {1: object()})
with pytest.raises(ReclineCommandError, match="Could not find"):
builtin_commands.fg(job=999)
Expand All @@ -190,8 +179,6 @@ def test_fg_invalid_job(monkeypatch):
def test_fg_with_job_no_formatter(monkeypatch):
"""Verify fg() completes silently when the job's command has no output formatter."""

import recline

class _FakeCommand:
output_formatter = None

Expand Down Expand Up @@ -241,8 +228,6 @@ def test_debug_interrupt_handler_callable(monkeypatch):
def test_fg_with_valid_job(monkeypatch):
"""Verify fg() calls foreground() and formats output for a known job."""

import recline

formatted = []

class _FakeFormatter:
Expand Down Expand Up @@ -274,8 +259,6 @@ def test_man_unknown_command(capsys):
def test_man_command_large_window(monkeypatch):
"""Test man command with a large window so all text fits and (END) is displayed."""

import curses

@recline.command(name="man large cmd")
def _man_large():
"""Short description for large-window man test."""
Expand Down Expand Up @@ -313,8 +296,6 @@ def getch(self):
def test_man_command_scrolling(monkeypatch):
"""Test man command with a small window to exercise KEY_DOWN and KEY_UP scrolling."""

import curses

@recline.command(name="man scroll cmd")
def _man_scroll():
"""Short desc for scroll test.
Expand Down
Loading
Loading