Skip to content

Commit

Permalink
Move version_arg to version_helper, add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Felixoid committed Apr 7, 2022
1 parent e8168a1 commit a365ef5
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 20 deletions.
20 changes: 1 addition & 19 deletions tests/ci/docker_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
from docker_images_check import DockerImage
from env_helper import CI, GITHUB_RUN_URL, RUNNER_TEMP, S3_BUILDS_BUCKET
from get_robot_token import get_best_robot_token, get_parameter_from_ssm
from git_helper import removeprefix
from pr_info import PRInfo
from s3_helper import S3Helper
from stopwatch import Stopwatch
Expand All @@ -25,8 +24,7 @@
ClickHouseVersion,
get_tagged_versions,
get_version_from_repo,
get_version_from_string,
get_version_from_tag,
version_arg,
)

TEMP_PATH = p.join(RUNNER_TEMP, "docker_images_check")
Expand Down Expand Up @@ -114,22 +112,6 @@ def parse_args() -> argparse.Namespace:
return parser.parse_args()


def version_arg(version: str) -> ClickHouseVersion:
version = removeprefix(version, "refs/tags/")
try:
return get_version_from_string(version)
except ValueError:
pass
try:
return get_version_from_tag(version)
except ValueError:
pass

raise argparse.ArgumentTypeError(
f"version {version} does not match tag of plain version"
)


def auto_release_type(version: ClickHouseVersion, release_type: str) -> str:
if release_type != "auto":
return release_type
Expand Down
16 changes: 15 additions & 1 deletion tests/ci/version_helper.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python3
import logging
import os.path as p
from argparse import ArgumentParser, ArgumentDefaultsHelpFormatter
from argparse import ArgumentParser, ArgumentDefaultsHelpFormatter, ArgumentTypeError
from typing import Dict, List, Tuple, Union

from git_helper import Git, removeprefix
Expand Down Expand Up @@ -220,6 +220,20 @@ def get_version_from_tag(tag: str) -> ClickHouseVersion:
return get_version_from_string(tag)


def version_arg(version: str) -> ClickHouseVersion:
version = removeprefix(version, "refs/tags/")
try:
return get_version_from_string(version)
except ValueError:
pass
try:
return get_version_from_tag(version)
except ValueError:
pass

raise ArgumentTypeError(f"version {version} does not match tag of plain version")


def get_tagged_versions() -> List[ClickHouseVersion]:
versions = []
for tag in git.get_tags():
Expand Down
33 changes: 33 additions & 0 deletions tests/ci/version_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/usr/bin/env python

import unittest
from argparse import ArgumentTypeError

import version_helper as vh


class TestFunctions(unittest.TestCase):
def test_version_arg(self):
cases = (
("0.0.0.0", vh.get_version_from_string("0.0.0.0")),
("1.1.1.2", vh.get_version_from_string("1.1.1.2")),
("v1.1.1.2-lts", vh.get_version_from_string("1.1.1.2")),
("v1.1.1.2-prestable", vh.get_version_from_string("1.1.1.2")),
("v1.1.1.2-stable", vh.get_version_from_string("1.1.1.2")),
("v1.1.1.2-testing", vh.get_version_from_string("1.1.1.2")),
("refs/tags/v1.1.1.2-testing", vh.get_version_from_string("1.1.1.2")),
)
for case in cases:
version = vh.version_arg(case[0])
self.assertEqual(case[1], version)
error_cases = (
"0.0.0",
"1.1.1.a",
"1.1.1.1.1",
"1.1.1.2-testing",
"v1.1.1.2-testin",
"refs/tags/v1.1.1.2-testin",
)
for case in error_cases:
with self.assertRaises(ArgumentTypeError):
version = vh.version_arg(case[0])

0 comments on commit a365ef5

Please sign in to comment.