Skip to content

Commit e4fce94

Browse files
fix: Fix the tests to add the parse_version_to_tuple function
Signed-off-by: Radhika Agrawal <agrawalradhika@google.com>
1 parent cc6573e commit e4fce94

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

tests/test_discovery.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@
6363
except ImportError:
6464
HAS_UNIVERSE = False
6565

66-
from google.api_core._python_package_support import parse_version_to_tuple
6766
from googleapiclient import _helpers as util
6867
from googleapiclient.discovery import (DISCOVERY_URI,
6968
MEDIA_BODY_PARAMETER_DEFAULT_VALUE,
@@ -142,6 +141,28 @@ def read_datafile(filename, mode="r"):
142141
with open(datafile(filename), mode=mode) as f:
143142
return f.read()
144143

144+
def parse_version_to_tuple(version_string: str) -> ParsedVersion:
145+
"""Safely converts a semantic version string to a comparable tuple of integers.
146+
147+
Example: "4.25.8" -> (4, 25, 8)
148+
Ignores non-numeric parts and handles common version formats.
149+
150+
Args:
151+
version_string: Version string in the format "x.y.z" or "x.y.z<suffix>"
152+
153+
Returns:
154+
Tuple of integers for the parsed version string.
155+
"""
156+
parts = []
157+
for part in version_string.split("."):
158+
try:
159+
parts.append(int(part))
160+
except ValueError:
161+
# If it's a non-numeric part (e.g., '1.0.0b1' -> 'b1'), stop here.
162+
# This is a simplification compared to 'packaging.parse_version', but sufficient
163+
# for comparing strictly numeric semantic versions.
164+
break
165+
return tuple(parts)
145166

146167
class SetupHttplib2(unittest.TestCase):
147168
def test_retries(self):

0 commit comments

Comments
 (0)