The test suite in test_parser.py provides comprehensive coverage of all valid input option combinations for the dockerctl parser using Python's unittest framework.
test_version_long_option: Tests--versionprints version and exitstest_version_short_option: Tests-vprints version and exitstest_version_ignores_other_args: Verifies--versionexits immediately, ignoring other arguments
test_help_long_option: Tests--helpprints help text and exitstest_help_short_option: Tests-hprints help text and exitstest_help_ignores_other_args: Verifies--helpexits immediately, ignoring other arguments
test_list_long_option: Tests--listcallsCommands.ls()and exitstest_list_short_option: Tests-lcallsCommands.ls()and exitstest_list_ignores_other_args: Verifies--listexits immediately, ignoring other arguments
test_simple_command: Tests parsing of simple command without optionstest_command_with_additional_args: Tests command with additional docker-compose argumentstest_command_with_path_option: Tests command with--pathoptiontest_command_with_path_and_additional_args: Tests combination of--pathand additional arguments
test_all_commands_parse_correctly: Verifies all 23 supported commands parse correctly:- start, stop, restart, ps, up, kill, rm, top, logs
- images, port, pull, push, pause, unpause, add, remove
- exec, edit, show, create, update, ls, down
test_path_with_equals_syntax: Tests--path=/my/pathsyntaxtest_path_with_space_syntax: Tests--path /my/pathsyntaxtest_multiple_additional_args: Tests multiple additional argumentstest_path_with_trailing_slash: Tests path normalizationtest_compose_name_with_special_chars: Tests compose names with hyphens and underscores
test_missing_compose_name: Tests error when only command providedtest_no_arguments: Tests error when no arguments providedtest_invalid_option: Tests error for unrecognized optionstest_path_option_without_value: Tests error when--pathlacks a value
test_combined_short_options_vh: Tests-vhcombinationtest_combined_short_options_vl: Tests-vlcombinationtest_combined_short_options_hl: Tests-hlcombination
test_absolute_path: Tests absolute path handlingtest_relative_path: Tests relative path handlingtest_path_with_spaces: Tests paths with spacestest_path_with_dots: Tests parent directory references (../)
test_logs_with_docker_compose_options: Tests logs command with-f,--tail, and service nametest_exec_with_bash_command: Tests exec withbash -ccommandtest_port_with_service_name: Tests port command with service nametest_add_with_path_option: Tests add command with custom path
- Uses
unittest.mockto mock theCommandsclass and its methods - Prevents actual file system access (no need for
/etc/dockerctlor/etc/docker) - Allows testing of unprivileged environments
- All tests are independent and can run in any order
- Each test mocks necessary dependencies
- No test fixtures or setup/teardown needed
- Short options:
-v,-h,-l - Long options:
--version,--help,--list,--path - Path formats: Absolute, relative, with spaces, with dots
- Option syntax variants:
--path=valueand--path value - All 23 supported commands
- Additional arguments for docker-compose
- Option combinations (e.g.,
--pathwith commands and additional args)
- Missing required arguments
- Invalid options
- Incomplete path option
# Run all tests
python -m unittest test_parser.py -v
# Run specific test class
python -m unittest test_parser.TestParserVersion -v
# Run single test
python -m unittest test_parser.TestParserVersion.test_version_long_option -vAll 38 tests verify that:
- Option parsing works correctly with getopt
- Help, version, and list options exit immediately
- Commands are properly parsed with their compose name
- Additional arguments are preserved and passed through
- Path options are correctly captured and forwarded
- Error cases are handled gracefully
- No file system access is required