test_version.py 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. # Licensed to the Apache Software Foundation (ASF) under one
  2. # or more contributor license agreements. See the NOTICE file
  3. # distributed with this work for additional information
  4. # regarding copyright ownership. The ASF licenses this file
  5. # to you under the Apache License, Version 2.0 (the
  6. # "License"); you may not use this file except in compliance
  7. # with the License. You may obtain a copy of the License at
  8. #
  9. # http://www.apache.org/licenses/LICENSE-2.0
  10. #
  11. # Unless required by applicable law or agreed to in writing,
  12. # software distributed under the License is distributed on an
  13. # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  14. # KIND, either express or implied. See the License for the
  15. # specific language governing permissions and limitations
  16. # under the License.
  17. """Test command line interface subcommand `version`."""
  18. from unittest.mock import patch
  19. import pytest
  20. import pydolphinscheduler
  21. from pydolphinscheduler.cli.commands import cli
  22. from tests.testing.cli import CliTestWrapper
  23. def test_version():
  24. """Test whether subcommand `version` correct."""
  25. cli_test = CliTestWrapper(cli, ["version"])
  26. cli_test.assert_success(output=f"{pydolphinscheduler.__version__}")
  27. @pytest.mark.parametrize(
  28. "version, part, idx",
  29. [
  30. ("1.2.3", "major", 0),
  31. ("0.1.3", "minor", 1),
  32. ("3.1.0", "micro", 2),
  33. ("1.2.3-beta-1", "micro", 2),
  34. ("1.2.3-alpha", "micro", 2),
  35. ("1.2.3a2", "micro", 2),
  36. ("1.2.3b1", "micro", 2),
  37. ],
  38. )
  39. @patch("pydolphinscheduler.__version__")
  40. def test_version_part(mock_version, version: str, part: str, idx: int):
  41. """Test subcommand `version` option `--part`."""
  42. mock_version.return_value = version
  43. cli_test = CliTestWrapper(cli, ["version", "--part", part])
  44. cli_test.assert_success(output=f"{pydolphinscheduler.__version__.split('.')[idx]}")
  45. @pytest.mark.parametrize(
  46. "option, output",
  47. [
  48. # not support option
  49. (["version", "--not-support"], "No such option"),
  50. # not support option value
  51. (["version", "--part", "abc"], "Invalid value for '--part'"),
  52. ],
  53. )
  54. def test_version_not_support_option(option, output):
  55. """Test subcommand `version` not support option or option value."""
  56. cli_test = CliTestWrapper(cli, option)
  57. cli_test.assert_fail(ret_code=2, output=output, fuzzy=True)