test: adapt to interface representations in different Python versions

Is 3.12.10 (or lower) being used by the runner?

Fix version ranges

Condition expected value based on observed Python behaviour

Co-authored-by: Daniele Varrazzo <daniele.varrazzo@gmail.com>
This commit is contained in:
Edgar Ramírez Mondragón 2025-10-01 22:52:42 -06:00 committed by Daniele Varrazzo
parent e0507a891c
commit 236c52b712

View File

@ -71,10 +71,13 @@ class NetworkingTestCase(testutils.ConnectingTestCase):
cur.execute("select %s", [ip.ip_interface('::ffff:102:300/128')]) cur.execute("select %s", [ip.ip_interface('::ffff:102:300/128')])
# The texual representation of addresses has changed in Python 3.13 # The texual representation of addresses has changed in Python 3.13
if sys.version_info >= (3, 13): # https://github.com/python/cpython/issues/128840
if str(ip.ip_interface("::ffff:102:300/128")) == "::ffff:1.2.3.0/128":
self.assertEquals(cur.fetchone()[0], '::ffff:1.2.3.0/128') self.assertEquals(cur.fetchone()[0], '::ffff:1.2.3.0/128')
else: elif str(ip.ip_interface("::ffff:102:300/128")) == "::ffff:102:300/128":
self.assertEquals(cur.fetchone()[0], '::ffff:102:300/128') self.assertEquals(cur.fetchone()[0], '::ffff:102:300/128')
else:
assert False, "unexpected"
@testutils.skip_if_crdb("cidr") @testutils.skip_if_crdb("cidr")
def test_cidr_cast(self): def test_cidr_cast(self):
@ -117,10 +120,13 @@ class NetworkingTestCase(testutils.ConnectingTestCase):
cur.execute("select %s", [ip.ip_network('::ffff:102:300/128')]) cur.execute("select %s", [ip.ip_network('::ffff:102:300/128')])
# The texual representation of addresses has changed in Python 3.13 # The texual representation of addresses has changed in Python 3.13
if sys.version_info >= (3, 13): # https://github.com/python/cpython/issues/128840
if str(ip.ip_interface("::ffff:102:300/128")) == "::ffff:1.2.3.0/128":
self.assertEquals(cur.fetchone()[0], '::ffff:1.2.3.0/128') self.assertEquals(cur.fetchone()[0], '::ffff:1.2.3.0/128')
else: elif str(ip.ip_interface("::ffff:102:300/128")) == "::ffff:102:300/128":
self.assertEquals(cur.fetchone()[0], '::ffff:102:300/128') self.assertEquals(cur.fetchone()[0], '::ffff:102:300/128')
else:
assert False, "unexpected"
def test_suite(): def test_suite():