Debian Codegraph @

test/test.rst

raw
1 Non regression tests
2 ====================
3
4 >>> from IPy import IP
5 >>> IP('::ffff:1.2.3.4').strCompressed()
6 '::ffff:1.2.3.4'
7 >>> IP('::ffff:192.168.10.0/120').strCompressed()
8 '::ffff:192.168.10.0/120'
9 >>> IP('::ffff:192.168.10.42/120', make_net=True).strCompressed()
10 '::ffff:192.168.10.0/120'
11 >>> IP('::/0', make_net=True).net()
12 IP('::')
13 >>> IP('0.0.0.0/0') + IP('0.0.0.0/0')
14 Traceback (most recent call last):
15 ...
16 ValueError: Networks with a prefixlen longer than /1 can't be added.
17
18
19 Compare 0.0.0.0/0 and ::/0 bug
20 ==============================
21
22 >>> IP('0.0.0.0/0') < IP('::/0')
23 True
24 >>> IP('0.0.0.0/0') > IP('::/0')
25 False
26 >>> IP('0.0.0.0/0') == IP('::/0')
27 False
28
29 >>> d={}
30 >>> d[IP('0.0.0.0/0')] = 1
31 >>> d[IP('::/0')] = 2
32 >>> sorted(d.items())
33 [(IP('0.0.0.0/0'), 1), (IP('::/0'), 2)]
34
35 >>> addresses = [IP('0.0.0.0/16'), IP('::7'), IP('::3'), IP('::0'),
36 ... IP('0.0.0.0'), IP('0.0.0.3'), IP('0.0.0.0/0'), IP('::/0')]
37 ...
38 >>> addresses.sort()
39 >>> addresses
40 [IP('0.0.0.0/0'), IP('0.0.0.0/16'), IP('0.0.0.0'), IP('0.0.0.3'), IP('::/0'), IP('::'), IP('::3'), IP('::7')]
41
42 >>> IP('::/0').netmask()
43 IP('::')
44
45
46 IP types
47 ========
48
49 >>> IP('10.8.3.0/24').iptype()
50 'PRIVATE'
51 >>> IP('88.164.127.124').iptype()
52 'PUBLIC'
53 >>> IP('223.0.0.0/8').iptype()
54 'PUBLIC'
55 >>> IP('224.0.0.0/8').iptype()
56 'RESERVED'
57
58 Reverse name
59 ============
60
61 >>> IP('::ffff:193.0.1.208').reverseName()
62 '208.1.0.193.in-addr.arpa.'
63 >>> IP('::ffff:193.0.1.208').reverseNames()
64 ['208.1.0.193.in-addr.arpa.']
65 >>> IP('128.0.0.0/7').reverseName()
66 '128-255..in-addr.arpa.'
67 >>> IP('128.0.0.0/7').reverseNames()
68 ['128.in-addr.arpa.', '129.in-addr.arpa.']
69 >>> IP('::ffff:128.0.0.0/103').reverseName() == IP('128.0.0.0/7').reverseName()
70 True
71 >>> IP('::ffff:128.0.0.0/103').reverseNames() == IP('128.0.0.0/7').reverseNames()
72 True
73
74 Issue #2 and #9
75 ===============
76
77 >>> IP('1.2.3.4') == None
78 False
79 >>> IP('1.2.3.4') == object()
80 False
81 >>> IP('1.2.3.4') != None
82 True
83 >>> IP('1.2.3.4') != object()
84 True
85
86
87 get_mac()
88 =========
89
90 >>> IP('fe80::f66d:04ff:fe47:2fae').get_mac()
91 'f4:6d:04:47:2f:ae'
92 >>> IP('2001:DB8::212:7FFF:FEEB:6B40').get_mac()
93 '00:12:7f:eb:6b:40'
94 >>> IP('::1').get_mac() is None
95 True
96 >>> IP('1.2.3.4').get_mac() is None
97 True
98
99 Issue #12: IPv6[index] -> IPv4
100 ==============================
101
102 >>> IP('1.2.3.0/24')[4]
103 IP('1.2.3.4')
104 >>> IP('::/0')[1]
105 IP('::1')
106