File: test_ip.py

package info (click to toggle)
python-netaddr 1.3.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 9,912 kB
  • sloc: xml: 8,264; python: 6,697; makefile: 198; sh: 5
file content (22 lines) | stat: -rw-r--r-- 625 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import weakref

import pytest

from netaddr import INET_ATON, INET_PTON, IPAddress, IPNetwork, IPRange, NOHOST


def test_ip_classes_are_weak_referencable():
    weakref.ref(IPAddress('10.0.0.1'))
    weakref.ref(IPNetwork('10.0.0.1/8'))
    weakref.ref(IPRange('10.0.0.1', '10.0.0.10'))


@pytest.mark.parametrize('flags', [NOHOST, INET_ATON | INET_PTON])
def test_invalid_ipaddress_flags_are_rejected(flags):
    with pytest.raises(ValueError):
        IPAddress('1.2.3.4', flags=flags)


def test_invalid_ipnetwork_flags_are_rejected():
    with pytest.raises(ValueError):
        IPNetwork('1.2.0.0/16', flags=INET_PTON)