Skip to content

Commit 960f9df

Browse files
committed
Make test for local ip address more relaxed
Since this does not work reliably anways, e.g. if WSL is installed.
1 parent aa74b07 commit 960f9df

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed

webware/MiscUtils/Tests/TestFuncs.py

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -85,20 +85,21 @@ def testHostName(self):
8585
self.assertEqual(host, host.lower())
8686

8787
def testLocalIP(self):
88-
ip = localIP()
89-
self.assertTrue(ip)
90-
self.assertFalse(ip.startswith('127.'))
91-
self.assertEqual(localIP(), ip) # second invocation
92-
self.assertEqual(localIP(useCache=None), ip)
93-
# ignore if the following tests fetch the WSL address
94-
ips = (ip, '192.168.80.1', '172.22.32.1', '172.25.112.1')
95-
self.assertIn(
96-
localIP(remote=None, useCache=None), ips,
97-
'See if this works: localIP(remote=None).'
98-
' If this fails, dont worry.')
99-
self.assertIn(
88+
ip_local = localIP()
89+
self.assertTrue(ip_local)
90+
self.assertFalse(ip_local.startswith('127.'))
91+
self.assertEqual(localIP(), ip_local) # second invocation
92+
self.assertEqual(localIP(useCache=None), ip_local)
93+
94+
def assert_local(ip):
95+
self.assertTrue(
96+
ip == ip_local or ip.startswith(('127.', '192.168.'))
97+
or '172.16.' <= ip <= '172.31.')
98+
99+
assert_local(localIP(remote=None, useCache=None))
100+
assert_local(
100101
localIP(remote=('www.hostname.and.domain.are.invalid', 80),
101-
useCache=None), ips)
102+
useCache=None))
102103

103104
def testPositiveId(self):
104105
# About all we can do is invoke positiveId()

0 commit comments

Comments
 (0)