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])
def test_gen_tags(self): version = get_version_from_string("22.2.2.2") cases = ( ("latest", ["latest", "22", "22.2", "22.2.2", "22.2.2.2"]), ("major", ["22", "22.2", "22.2.2", "22.2.2.2"]), ("minor", ["22.2", "22.2.2", "22.2.2.2"]), ("patch", ["22.2.2", "22.2.2.2"]), ("head", ["head"]), ) for case in cases: release_type = case[0] self.assertEqual(case[1], ds.gen_tags(version, release_type)) with self.assertRaises(ValueError): ds.gen_tags(version, "auto")
def version_arg(version: str) -> ClickHouseVersion: try: return get_version_from_string(version) except ValueError as e: raise argparse.ArgumentTypeError(e)
def test_auto_release_type(self, mock_tagged_versions: MagicMock): mock_tagged_versions.return_value = [ get_version_from_string("1.1.1.1"), get_version_from_string("1.2.1.1"), get_version_from_string("2.1.1.1"), get_version_from_string("2.2.1.1"), get_version_from_string("2.2.2.1"), ] cases_less = ( (get_version_from_string("1.0.1.1"), "minor"), (get_version_from_string("1.1.2.1"), "minor"), (get_version_from_string("1.3.1.1"), "major"), (get_version_from_string("2.1.2.1"), "minor"), (get_version_from_string("2.2.1.3"), "patch"), (get_version_from_string("2.2.3.1"), "latest"), (get_version_from_string("2.3.1.1"), "latest"), ) for case in cases_less: release = ds.auto_release_type(case[0], "auto") self.assertEqual(case[1], release) cases_equal = ( (get_version_from_string("1.1.1.1"), "minor"), (get_version_from_string("1.2.1.1"), "major"), (get_version_from_string("2.1.1.1"), "minor"), (get_version_from_string("2.2.1.1"), "patch"), (get_version_from_string("2.2.2.1"), "latest"), ) for case in cases_equal: release = ds.auto_release_type(case[0], "auto") self.assertEqual(case[1], release)