test_arg_parser.py 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. from opendevin.config import get_parser
  2. import pytest
  3. def test_help_message(capsys):
  4. parser = get_parser()
  5. with pytest.raises(SystemExit): # `--help` causes SystemExit
  6. parser.parse_args(['--help'])
  7. captured = capsys.readouterr()
  8. expected_help_message = """
  9. usage: pytest [-h] [-d DIRECTORY] [-t TASK] [-f FILE] [-c AGENT_CLS]
  10. [-m MODEL_NAME] [-i MAX_ITERATIONS] [-n MAX_CHARS]
  11. Run an agent with a specific task
  12. options:
  13. -h, --help show this help message and exit
  14. -d DIRECTORY, --directory DIRECTORY
  15. The working directory for the agent
  16. -t TASK, --task TASK The task for the agent to perform
  17. -f FILE, --file FILE Path to a file containing the task. Overrides -t if
  18. both are provided.
  19. -c AGENT_CLS, --agent-cls AGENT_CLS
  20. The agent class to use
  21. -m MODEL_NAME, --model-name MODEL_NAME
  22. The (litellm) model name to use
  23. -i MAX_ITERATIONS, --max-iterations MAX_ITERATIONS
  24. The maximum number of iterations to run the agent
  25. -n MAX_CHARS, --max-chars MAX_CHARS
  26. The maximum number of characters to send to and
  27. receive from LLM per task
  28. """
  29. actual_lines = captured.out.strip().split('\n')
  30. expected_lines = expected_help_message.strip().split('\n')
  31. # Ensure both outputs have the same number of lines
  32. assert len(actual_lines) == len(expected_lines), 'The number of lines in the help message does not match.'
  33. # Compare each line
  34. for actual, expected in zip(actual_lines, expected_lines):
  35. assert actual.strip() == expected.strip(), f"Expected '{expected}', got '{actual}'"