test_arg_parser.py 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. import pytest
  2. from opendevin.core.config import get_parser
  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. [-i MAX_ITERATIONS] [-b MAX_BUDGET_PER_TASK]
  11. [--eval-output-dir EVAL_OUTPUT_DIR]
  12. [--eval-n-limit EVAL_N_LIMIT]
  13. [--eval-num-workers EVAL_NUM_WORKERS] [--eval-note EVAL_NOTE]
  14. [-l LLM_CONFIG]
  15. Run an agent with a specific task
  16. options:
  17. -h, --help show this help message and exit
  18. -d DIRECTORY, --directory DIRECTORY
  19. The working directory for the agent
  20. -t TASK, --task TASK The task for the agent to perform
  21. -f FILE, --file FILE Path to a file containing the task. Overrides -t if
  22. both are provided.
  23. -c AGENT_CLS, --agent-cls AGENT_CLS
  24. Name of the default agent to use
  25. -i MAX_ITERATIONS, --max-iterations MAX_ITERATIONS
  26. The maximum number of iterations to run the agent
  27. -b MAX_BUDGET_PER_TASK, --max-budget-per-task MAX_BUDGET_PER_TASK
  28. The maximum budget allowed per task, beyond which the
  29. agent will stop.
  30. --eval-output-dir EVAL_OUTPUT_DIR
  31. The directory to save evaluation output
  32. --eval-n-limit EVAL_N_LIMIT
  33. The number of instances to evaluate
  34. --eval-num-workers EVAL_NUM_WORKERS
  35. The number of workers to use for evaluation
  36. --eval-note EVAL_NOTE
  37. The note to add to the evaluation directory
  38. -l LLM_CONFIG, --llm-config LLM_CONFIG
  39. The group of llm settings, e.g. "llama3" for
  40. [llm.llama3] section in the toml file. Overrides model
  41. if both are provided.
  42. """
  43. actual_lines = captured.out.strip().split('\n')
  44. print('\n'.join(actual_lines))
  45. expected_lines = expected_help_message.strip().split('\n')
  46. # Ensure both outputs have the same number of lines
  47. assert len(actual_lines) == len(
  48. expected_lines
  49. ), 'The number of lines in the help message does not match.'
  50. # Compare each line
  51. for actual, expected in zip(actual_lines, expected_lines):
  52. assert (
  53. actual.strip() == expected.strip()
  54. ), f"Expected '{expected}', got '{actual}'"