netwatch.py/netaddr-0.7.10/netaddr/tests/2.x/ip/ipglob.txt

73 lines
1.2 KiB
Plaintext

=IP Glob Tests=
Copyright (c) 2008-2012, David P. D. Moss. All rights reserved.
{{{
>>> from netaddr import *
}}}
IP Glob tests.
{{{
>>> cidr_to_glob('10.0.0.1/32')
'10.0.0.1'
>>> cidr_to_glob('192.0.2.0/24')
'192.0.2.*'
>>> cidr_to_glob('172.16.0.0/12')
'172.16-31.*.*'
>>> cidr_to_glob('0.0.0.0/0')
'*.*.*.*'
>>> glob_to_cidrs('10.0.0.1')
[IPNetwork('10.0.0.1/32')]
>>> glob_to_cidrs('192.0.2.*')
[IPNetwork('192.0.2.0/24')]
>>> glob_to_cidrs('172.16-31.*.*')
[IPNetwork('172.16.0.0/12')]
>>> glob_to_cidrs('*.*.*.*')
[IPNetwork('0.0.0.0/0')]
>>> glob_to_iptuple('*.*.*.*')
(IPAddress('0.0.0.0'), IPAddress('255.255.255.255'))
>>> iprange_to_globs('192.0.2.0', '192.0.2.255')
['192.0.2.*']
>>> iprange_to_globs('192.0.2.1', '192.0.2.15')
['192.0.2.1-15']
>>> iprange_to_globs('192.0.2.255', '192.0.4.1')
['192.0.2.255', '192.0.3.*', '192.0.4.0-1']
>>> iprange_to_globs('10.0.1.255', '10.0.255.255')
['10.0.1.255', '10.0.2-3.*', '10.0.4-7.*', '10.0.8-15.*', '10.0.16-31.*', '10.0.32-63.*', '10.0.64-127.*', '10.0.128-255.*']
}}}
Validity tests.
{{{
>>> valid_glob('1.1.1.a')
False
>>> valid_glob('1.1.1.1/32')
False
>>> valid_glob('1.1.1.a-b')
False
>>> valid_glob('1.1.a-b.*')
False
}}}