@@ -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