def test_pre_release_ids(self): self.assertEqual(Version(1, 2, 3, "alpha.3"), Version.parse_from("1.2.3-alpha.3")) self.assertEqual(Version(1, 2, 3, "alpha.3-special"), Version.parse_from("1.2.3-alpha.3-special")) self.assertEqual(Version(1, 2, 3, "alpha.3-more-special"), Version.parse_from("1.2.3-alpha.3-more-special")) self.assertEqual(Version(1, 2, 3, "alpha.3", None, 0, True), Version.parse_from("v1.2.3-alpha.3-dirty")) self.assertEqual(Version(1, 2, 3, "alpha.3", "296cf8b", 12, True), Version.parse_from("v1.2.3-alpha.3-12-g296cf8b-dirty"))
def test_pre_release_ids(self): self.assertEqual(Version(1, 2, 3, "alpha.3"), Version.parse_from("1.2.3-alpha.3")) self.assertEqual(Version(1, 2, 3, "alpha.3-special"), Version.parse_from("1.2.3-alpha.3-special")) self.assertEqual(Version(1, 2, 3, "alpha.3-more-special"), Version.parse_from("1.2.3-alpha.3-more-special")) self.assertEqual(Version(1, 2, 3, "alpha.3", None, 0, True), Version.parse_from("v1.2.3-alpha.3-dirty")) self.assertEqual( Version(1, 2, 3, "alpha.3", "296cf8b", 12, True), Version.parse_from("v1.2.3-alpha.3-12-g296cf8b-dirty"))
def test_tag_only_no_patch(self): self.assertEqual(Version(1, 2, 0), Version.parse_from("v1.2")) self.assertEqual(Version(1, 2, 0), Version.parse_from("1.2"))
def test_tag_only(self): self.assertEqual(Version(1, 2, 3), Version.parse_from("v1.2.3")) self.assertEqual(Version(1, 2, 3), Version.parse_from("1.2.3"))
def test_tag_only_dirty(self): self.assertEqual(Version(1, 2, 3, is_dirty=True), Version.parse_from("v1.2.3-dirty")) self.assertEqual(Version(1, 2, 3, is_dirty=True), Version.parse_from("1.2.3-dirty"))
def test_hash_only(self): self.assertEqual(Version(0, 0, commit_hash="abcdefg"), Version.parse_from("abcdefg"))
def test_hash_only_dirty(self): self.assertEqual(Version(0, 0, commit_hash="abcdefg", is_dirty=True), Version.parse_from("abcdefg-dirty"))
def test_EmptyString_raises(self): self.assertRaises(ValueError, lambda: Version.parse_from(''))
def test_commits_since(self): self.assertEqual(Version(1, 2, 0, None, "296cf8b", 12, False), Version.parse_from("v1.2.0-12-g296cf8b")) self.assertEqual(Version(1, 2, 0, None, "296cf8b", 12, True), Version.parse_from("v1.2.0-12-g296cf8b-dirty"))
def test_tag_only_no_patch_dirty(self): self.assertEqual(Version(1, 2, 0, is_dirty=True), Version.parse_from("v1.2-dirty")) self.assertEqual(Version(1, 2, 0, is_dirty=True), Version.parse_from("1.2-dirty"))
def test_invalid_tag(self): self.assertRaises(ValueError, lambda: Version.parse_from("v1.2.3.1.1.1.1"))
def test_None_raises(self): self.assertRaises(ValueError, lambda: Version.parse_from(None))