test_commands.py 1009 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import pytest
  2. from src.commands import COMMANDS
  3. def test_help_returns_nonempty_string():
  4. result = COMMANDS["help"]()
  5. assert isinstance(result, str)
  6. assert len(result) > 0
  7. def test_help_mentions_help_command():
  8. result = COMMANDS["help"]()
  9. assert "help" in result
  10. def test_unknown_command_not_in_registry():
  11. assert "foobar" not in COMMANDS
  12. def test_all_commands_are_callable():
  13. for name, handler in COMMANDS.items():
  14. assert callable(handler), f"Command '{name}' is not callable"
  15. def test_exit_raises_system_exit(capsys):
  16. with pytest.raises(SystemExit) as exc_info:
  17. COMMANDS["exit"]()
  18. assert exc_info.value.code == 0
  19. def test_exit_prints_goodbye(capsys):
  20. with pytest.raises(SystemExit):
  21. COMMANDS["exit"]()
  22. captured = capsys.readouterr()
  23. assert "Goodbye!" in captured.out
  24. def test_exit_is_in_registry():
  25. assert "exit" in COMMANDS
  26. def test_help_mentions_exit():
  27. result = COMMANDS["help"]()
  28. assert "exit" in result