def ip6_addr_strings() -> SearchStrategy[str]:
    note_deprecation(
        "Use `ip_addresses(v=6).map(str)` instead of `ip6_addr_strings()`; "
        "the provisional strategy is less flexible and will be removed.",
        since="2020-01-21",
    )
    return ip_addresses(v=6).map(str)
Exemple #2
0
 slice:
 st.builds(
     slice,
     st.none() | st.integers(),
     st.none() | st.integers(),
     st.none() | st.integers(),
 ),
 range:
 st.one_of(
     st.integers(min_value=0).map(range),
     st.builds(range, st.integers(), st.integers()),
     st.builds(range, st.integers(), st.integers(),
               st.integers().filter(bool)),
 ),
 ipaddress.IPv4Address:
 ip_addresses(v=4),
 ipaddress.IPv6Address:
 ip_addresses(v=6),
 ipaddress.IPv4Interface:
 _networks(32).map(ipaddress.IPv4Interface),
 ipaddress.IPv6Interface:
 _networks(128).map(ipaddress.IPv6Interface),
 ipaddress.IPv4Network:
 st.one_of(
     _networks(32).map(lambda x: ipaddress.IPv4Network(x, strict=False)),
     st.sampled_from(SPECIAL_IPv4_RANGES).map(ipaddress.IPv4Network),
 ),
 ipaddress.IPv6Network:
 st.one_of(
     _networks(128).map(lambda x: ipaddress.IPv6Network(x, strict=False)),
     st.sampled_from(SPECIAL_IPv6_RANGES).map(ipaddress.IPv6Network),
Exemple #3
0
    numbers.Rational: st.fractions(),
    numbers.Number: st.complex_numbers(),
    numbers.Integral: st.integers(),
    numbers.Complex: st.complex_numbers(),
    slice: st.builds(
        slice,
        st.none() | st.integers(),
        st.none() | st.integers(),
        st.none() | st.integers(),
    ),
    range: st.one_of(
        st.integers(min_value=0).map(range),
        st.builds(range, st.integers(), st.integers()),
        st.builds(range, st.integers(), st.integers(), st.integers().filter(bool)),
    ),
    ipaddress.IPv4Address: ip_addresses(v=4),
    ipaddress.IPv6Address: ip_addresses(v=6),
    ipaddress.IPv4Interface: _networks(32).map(ipaddress.IPv4Interface),
    ipaddress.IPv6Interface: _networks(128).map(ipaddress.IPv6Interface),
    ipaddress.IPv4Network: st.one_of(
        _networks(32).map(lambda x: ipaddress.IPv4Network(x, strict=False)),
        st.sampled_from(SPECIAL_IPv4_RANGES).map(ipaddress.IPv4Network),
    ),
    ipaddress.IPv6Network: st.one_of(
        _networks(128).map(lambda x: ipaddress.IPv6Network(x, strict=False)),
        st.sampled_from(SPECIAL_IPv6_RANGES).map(ipaddress.IPv6Network),
    ),
    os.PathLike: st.builds(PurePath, st.text()),
    # Pull requests with more types welcome!
}
if zoneinfo is not None:  # pragma: no branch
    domain = domain.lower()
    iocs = find_iocs(domain)
    failure = False

    try:
        assert len(iocs['domains']) == 1
        assert iocs['domains'][0] == domain
    except AssertionError as e:
        failure = True
        print('Failed on domain: {}'.format(domain))

    if failure:
        raise AssertionError('Error parsing domains')


@given(ip_addresses(v=4))
@settings(deadline=None)
def test_ipv4_parsing(ipv4):
    iocs = find_iocs(ipv4)
    failure = False

    try:
        assert len(iocs['ipv4s']) == 1
        assert iocs['ipv4s'][0] == ipv4
    except AssertionError as e:
        failure = True
        print('Failed on ipv4: {}'.format(ipv4))

    if failure:
        raise AssertionError('Error parsing ipv4s')