Пример #1
0
def test_lines():
    l = Hosts(context_wrap(HOSTS_EXAMPLE)).lines
    assert len(l) == 7
    assert l[2]['ip'] == l[0]['ip'] == "127.0.0.1"
    assert l[-1]['names'] == ['atlas', 'atlas.example.com']
    assert l[3][
        'raw_line'] == '10.0.0.1 nonlocal.foo.redhat.com nonlocal2.bar.redhat.com'
Пример #2
0
def test_ip_of():
    ob = Hosts(context_wrap(HOSTS_EXAMPLE))
    # One IP with multiple names
    assert ob.ip_of('localhost4.localdomain4') == '127.0.0.1'
    # IPv6 address, with single name
    assert ob.ip_of('ipv6.example.com') == '2001:db8::36'
    # No host found = None
    assert ob.ip_of('foo.example.com') is None
Пример #3
0
def test_nonlocal():
    ob = Hosts(context_wrap(HOSTS_EXAMPLE))
    expected = {
        "10.0.0.1": EXPECTED["10.0.0.1"],
        '2001:db8::36': EXPECTED['2001:db8::36'],
        '13.22.96.102': EXPECTED['13.22.96.102'],
        '2001:db8::38': EXPECTED['2001:db8::38'],
    }
    assert ob.get_nonlocal() == expected
Пример #4
0
def test_all_hosts():
    h = Hosts(context_wrap(HOSTS_EXAMPLE))
    all_names = h.all_names
    expected = set(EXPECTED["127.0.0.1"]) | set(EXPECTED["::1"]) | \
        set(EXPECTED["10.0.0.1"]) | set(EXPECTED['2001:db8::36']) | \
        set(EXPECTED["192.0.2.1"]) | set(EXPECTED['2001:db8::38'])
    assert all_names == expected
    assert len(h.all_ips) == 6
    assert h.all_ips == set(EXPECTED.keys())
Пример #5
0
def test_all_hosts():
    all_names = Hosts(context_wrap(HOSTS_EXAMPLE)).all_names
    expected = set(EXPECTED["127.0.0.1"]) | set(EXPECTED["::1"]) | \
        set(EXPECTED["10.0.0.1"]) | set(EXPECTED['2001:db8::36']) | \
        set(EXPECTED["13.22.96.102"]) | set(EXPECTED['2001:db8::38'])
    assert all_names == expected
Пример #6
0
def test_hosts():
    d = Hosts(context_wrap(HOSTS_EXAMPLE)).data
    assert len(d) == 6
    for key in ["127.0.0.1", "::1"]:
        assert key in d
        assert d[key] == EXPECTED[key]
Пример #7
0
def test_exception():
    with pytest.raises(SkipException):
        Hosts(context_wrap(""))
Пример #8
0
def test_doc():
    env = {
        'hosts': Hosts(context_wrap(HOSTS_DOC)),
    }
    failed, total = doctest.testmod(hosts, globs=env)
    assert failed == 0