Exemplo n.º 1
0
def test_decode_invalid_nrq():
    try:
        APRSUtils.decode_nrq("S29")
        assert False
    except ValueError:
        assert True
    except Exception:
        assert False
Exemplo n.º 2
0
def test_decode_invalid_phg():
    # PHG values must be numerical
    try:
        APRSUtils.decode_phg("PHG513T")
        assert False
    except ValueError:
        assert True
    except Exception:
        assert False
Exemplo n.º 3
0
def test_decode_invalid_dfs():
    # DFS values must be numerical
    try:
        APRSUtils.decode_dfs("DFS236Z")
        assert False
    except ValueError:
        assert True
    except Exception:
        assert False
Exemplo n.º 4
0
def test_decode_phg():
    (power, height, gain, directivity) = APRSUtils.decode_phg("5132")

    assert power == 25
    assert height == 20
    assert gain == 3
    assert directivity == 90

    (power, height, gain, directivity) = APRSUtils.decode_phg("5130")

    assert power == 25
    assert height == 20
    assert gain == 3
    assert directivity is None
Exemplo n.º 5
0
def test_decode_dfs():
    (strength, height, gain, directivity) = APRSUtils.decode_dfs("2360")

    assert strength == 2
    assert height == 80
    assert gain == 6
    assert directivity == None

    (strength, height, gain, directivity) = APRSUtils.decode_dfs("2361")

    assert strength == 2
    assert height == 80
    assert gain == 6
    assert directivity == 45
Exemplo n.º 6
0
def test_decode_timestamp_hms_time():
    timestamp, timestamp_type = APRSUtils.decode_timestamp("234517h")

    assert type(timestamp) == datetime
    assert timestamp_type == "hms"
    assert timestamp.hour == 23
    assert timestamp.minute == 45
    assert timestamp.second == 17
Exemplo n.º 7
0
def test_decode_timestamp_in_previous_month():
    # Fake the date, ensure we get returned the previous month
    with mock.patch('aprspy.utils.APRSUtils._get_utc',
                    return_value=datetime(2019, 10, 10)):
        timestamp, timestamp_type = APRSUtils.decode_timestamp("302345z")

        assert timestamp.day == 30
        assert timestamp.month == 9
Exemplo n.º 8
0
def test_decode_timestamp_local_time():
    timestamp, timestamp_type = APRSUtils.decode_timestamp("092345/")

    assert type(timestamp) == datetime
    assert timestamp_type == "local"
    assert timestamp.day == 9
    assert timestamp.hour == 23
    assert timestamp.minute == 45
Exemplo n.º 9
0
def test_decode_nrq():
    # Test with example from APRS 1.01
    n, r, q = APRSUtils.decode_nrq("729")

    assert n == 87.5
    assert r == 4
    assert q == 1

    # Test with 0
    n, r, q = APRSUtils.decode_nrq("029")

    assert n == None
    assert r == None
    assert q == None

    # Test with manual
    n, r, q = APRSUtils.decode_nrq("929")

    assert n == "manual"

    # Test different qualities
    # These don't fit neatly into 2 ** x
    n, r, q = APRSUtils.decode_nrq("722")

    assert q == 120

    n, r, q = APRSUtils.decode_nrq("721")

    assert q == 240

    n, r, q = APRSUtils.decode_nrq("720")

    assert q == None
Exemplo n.º 10
0
def test_decode_uncompressed_latitude_with_ambiguity_4():
    # Test uncompressed latitude with 4 levels of ambiguity
    lat, ambiguity = APRSUtils.decode_uncompressed_latitude("49  .  N")

    assert lat == 49
    assert ambiguity == 4
Exemplo n.º 11
0
def test_decode_timestamp_zulu_invalid_time_value():
    with pytest.raises(ParseError):
        APRSUtils.decode_timestamp("322345z")
Exemplo n.º 12
0
def test_decode_timestamp_hms_invalid_time_value():
    with pytest.raises(ParseError):
        APRSUtils.decode_timestamp("254517h")
Exemplo n.º 13
0
def test_encode_phg():
    phg = APRSUtils.encode_phg(power=25, height=20, gain=3, directivity=90)
    assert phg == "5132"

    phg = APRSUtils.encode_phg(power=25, height=20, gain=3, directivity=None)
    assert phg == "5130"
Exemplo n.º 14
0
def test_decode_uncompressed_latitude_invalid_latitude():
    with pytest.raises(ParseError):
        # 91 degrees north is not a valid latitude
        APRSUtils.decode_uncompressed_latitude("9100.00N")
Exemplo n.º 15
0
def test_generate_passcode():
    passcode = APRSUtils.generate_passcode(callsign="XX1XX")

    assert passcode == "17122"
Exemplo n.º 16
0
def test_encode_uncompressed_latitude_padding():
    # Test latitude
    latitude = APRSUtils.encode_uncompressed_latitude(5)
    assert latitude == "0500.00N"
Exemplo n.º 17
0
def test_encode_invalid_dfs():
    # Invalid strength
    try:
        dfs = APRSUtils.encode_dfs(strength=10,
                                   height=80,
                                   gain=6,
                                   directivity=None)
        assert False
    except ValueError:
        assert True
    except Exception:
        assert False

    try:
        dfs = APRSUtils.encode_dfs(strength="2",
                                   height=80,
                                   gain=6,
                                   directivity=None)
        assert False
    except TypeError:
        assert True
    except Exception:
        assert False

    # Invalid height
    try:
        dfs = APRSUtils.encode_dfs(strength=2,
                                   height=90,
                                   gain=6,
                                   directivity=None)
        assert False
    except ValueError:
        assert True
    except Exception:
        assert False

    try:
        dfs = APRSUtils.encode_dfs(strength=2,
                                   height="80",
                                   gain=6,
                                   directivity=None)
        assert False
    except TypeError:
        assert True
    except Exception:
        assert False

    # Invalid gain
    try:
        dfs = APRSUtils.encode_dfs(strength=2,
                                   height=80,
                                   gain=10,
                                   directivity=None)
        assert False
    except ValueError:
        assert True
    except Exception:
        assert False

    try:
        dfs = APRSUtils.encode_dfs(strength=2,
                                   height=80,
                                   gain="6",
                                   directivity=None)
        assert False
    except TypeError:
        assert True
    except Exception:
        assert False

    # Invalid directivity
    try:
        dfs = APRSUtils.encode_dfs(strength=2,
                                   height=80,
                                   gain=6,
                                   directivity=47)
        assert False
    except ValueError:
        assert True
    except Exception:
        assert False

    try:
        dfs = APRSUtils.encode_dfs(strength=2,
                                   height=80,
                                   gain=6,
                                   directivity="None")
        assert False
    except TypeError:
        assert True
    except Exception:
        assert False
Exemplo n.º 18
0
def test_validate_passcode_with_ssid():
    valid = APRSUtils.validate_passcode(callsign="XX1XX-1", passcode="17122")

    assert valid is True
Exemplo n.º 19
0
def test_generate_passcode_with_ssid():
    passcode = APRSUtils.generate_passcode(callsign="XX1XX-1")

    assert passcode == "17122"
Exemplo n.º 20
0
def test_decode_uncompressed_latitude_invalid_ambiguity():
    with pytest.raises(ValueError):
        # >4 units of ambiguity is invalid for latitude
        APRSUtils.decode_uncompressed_latitude("5   . N")
Exemplo n.º 21
0
def test_decode_uncompressed_latitude_malformed_latitude():
    with pytest.raises(ValueError):
        # Period is in the wrong position
        APRSUtils.decode_uncompressed_latitude("49035.0N")
Exemplo n.º 22
0
def test_decode_uncompressed_latitude_invalid_direction():
    with pytest.raises(ValueError):
        # West is not a valid latitude direction
        APRSUtils.decode_uncompressed_latitude("4903.50W")
Exemplo n.º 23
0
def test_encode_invalid_phg():
    # Invalid power
    try:
        phg = APRSUtils.encode_phg(power=10,
                                   height=80,
                                   gain=6,
                                   directivity=None)
        assert False
    except ValueError:
        assert True
    except Exception:
        assert False

    try:
        phg = APRSUtils.encode_phg(power="10",
                                   height=80,
                                   gain=6,
                                   directivity=None)
        assert False
    except TypeError:
        assert True
    except Exception:
        assert False

    # Invalid height
    try:
        phg = APRSUtils.encode_phg(power=25,
                                   height=90,
                                   gain=6,
                                   directivity=None)
        assert False
    except ValueError:
        assert True
    except Exception:
        assert False

    try:
        phg = APRSUtils.encode_phg(power=25,
                                   height="90",
                                   gain=6,
                                   directivity=None)
        assert False
    except TypeError:
        assert True
    except Exception:
        assert False

    # Invalid gain
    try:
        phg = APRSUtils.encode_phg(power=25,
                                   height=80,
                                   gain=10,
                                   directivity=None)
        assert False
    except ValueError:
        assert True
    except Exception:
        assert False

    try:
        phg = APRSUtils.encode_phg(power=25,
                                   height=80,
                                   gain="10",
                                   directivity=None)
        assert False
    except TypeError:
        assert True
    except Exception:
        assert False

    # Invalid directivity
    try:
        phg = APRSUtils.encode_phg(power=25, height=80, gain=6, directivity=47)
        assert False
    except ValueError:
        assert True
    except Exception:
        assert False

    try:
        phg = APRSUtils.encode_phg(power=25,
                                   height=80,
                                   gain=6,
                                   directivity="None")
        assert False
    except TypeError:
        assert True
    except Exception:
        assert False
Exemplo n.º 24
0
def test_encode_uncompressed_latitude_with_ambiguity_1():
    # Test latitude with differing levels of ambiguity
    latitude = APRSUtils.encode_uncompressed_latitude(51.473821, 1)
    assert latitude == "5128.4 N"
Exemplo n.º 25
0
def test_encode_dfs():
    dfs = APRSUtils.encode_dfs(strength=2, height=80, gain=6, directivity=None)
    assert dfs == "2360"

    dfs = APRSUtils.encode_dfs(strength=2, height=80, gain=6, directivity=45)
    assert dfs == "2361"
Exemplo n.º 26
0
def test_encode_uncompressed_latitude_with_ambiguity_2():
    latitude = APRSUtils.encode_uncompressed_latitude(51.473821, 2)
    assert latitude == "5128.  N"
Exemplo n.º 27
0
def test_decode_uncompressed_latitude_complete_garbage():
    with pytest.raises(ValueError):
        # Random garbage
        APRSUtils.decode_uncompressed_latitude("GARBAGE")
Exemplo n.º 28
0
def test_validate_invalid_passcode():
    valid = APRSUtils.validate_passcode(callsign="XX1XX", passcode="17123")

    assert valid is False
Exemplo n.º 29
0
def test_timestamp():
    timestamp = APRSUtils.decode_timestamp("091234z")
Exemplo n.º 30
0
def test_encode_uncompressed_latitude_without_ambiguity():
    # Test latitude
    latitude = APRSUtils.encode_uncompressed_latitude(51.473821)
    assert latitude == "5128.43N"