Example #1
0
def test_eq_notmatch():
    """
    Test the __eq__ operator correctly identifies non-matching addresses.
    """
    a = AX25Address('VK4MSL', 12, ch=False)
    b = AX25Address('VK4MSL', 12, ch=True)
    assert a != b
Example #2
0
def test_eq_match():
    """
    Test the __eq__ operator correctly matches addresses.
    """
    a = AX25Address('VK4MSL', 12, ch=False)
    b = AX25Address('VK4MSL', 12, ch=False)
    assert a is not b
    assert a == b
Example #3
0
def test_addresses():
    """
    Test given a list of AX25Addresses, AX25Path passes them in.
    """
    path = AX25Path(AX25Address.decode('VK4MSL'), AX25Address.decode('VK4RZB'),
                    AX25Address.decode('VK4RZA'))
    eq_(path._path[0]._callsign, 'VK4MSL')
    eq_(path._path[1]._callsign, 'VK4RZB')
    eq_(path._path[2]._callsign, 'VK4RZA')
Example #4
0
def test_decode_str_invalid():
    """
    Test that strings are correctly validated.
    """
    try:
        AX25Address.decode('VK4-MSL')
        assert False, 'Should not have worked'
    except ValueError as e:
        eq_(str(e), 'Not a valid SSID: VK4-MSL')
Example #5
0
def test_mydigi_replace():
    """
    Test we can replace the digipeater call list.
    """
    digipeater = APRSDigipeater()
    digipeater._mydigi.add(AX25Address.decode('VK4MSL'))
    digipeater.mydigi = ['VK4BWI']

    eq_(digipeater.mydigi, set([AX25Address.decode('VK4BWI')]))
Example #6
0
def test_decode_wrongtype():
    """
    Test that incorrect types are handled.
    """
    try:
        AX25Address.decode(12345)
        assert False, 'Should not have worked'
    except TypeError as e:
        eq_(str(e), "Don't know how to decode 12345")
Example #7
0
def test_decode_bytes_short():
    """
    Test decoding a truncated address does not crash.
    """
    try:
        AX25Address.decode(from_hex('ac 96 68 9a a6'))
        assert False, 'This should not work'
    except ValueError as e:
        eq_(str(e), 'AX.25 addresses must be 7 bytes!')
Example #8
0
def test_decode_ax25address():
    """
    Test that passing in a AX25Address results in a clone being made.
    """
    addr1 = AX25Address('VK4MSL', 5)
    addr2 = AX25Address.decode(addr1)
    assert addr1 is not addr2
    for field in ('_callsign', '_ssid', '_ch', \
            '_res0', '_res1', '_extension'):
        eq_(getattr(addr1, field), getattr(addr2, field))
Example #9
0
def test_hash():
    """
    Test we can obtain a reliable hash.
    """
    a = AX25Address('VK4MSL', 12, ch=False)
    b = AX25Address('VK4MSL', 12, ch=False)
    c = AX25Address('VK4MSL', 12, ch=True)
    assert a is not b
    assert a is not c
    assert hash(a) == hash(b)
    assert hash(a) != hash(c)
Example #10
0
def test_decode_no_digis():
    """
    Test we can decode an AX.25 frame without digipeaters.
    """
    (header, data) = AX25FrameHeader.decode(
        from_hex('ac 96 68 84 ae 92 e0'  # Destination
                 'ac 96 68 9a a6 98 61'  # Source
                 ) + b'frame data goes here'  # Frame data
    )
    eq_(header.destination, AX25Address('VK4BWI', ch=True))
    eq_(header.source, AX25Address('VK4MSL', extension=True))
    eq_(len(header.repeaters), 0)
    eq_(data, b'frame data goes here')
Example #11
0
def test_decode_with_1digi():
    """
    Test we can decode an AX.25 frame with one digipeater.
    """
    (header, data) = AX25FrameHeader.decode(
        from_hex('ac 96 68 84 ae 92 e0'  # Destination
                 'ac 96 68 9a a6 98 60'  # Source
                 'ac 96 68 a4 b4 84 61'  # Digi
                 ) + b'frame data goes here'  # Frame data
    )
    eq_(header.destination, AX25Address('VK4BWI', ch=True))
    eq_(header.source, AX25Address('VK4MSL'))
    eq_(header.repeaters[0], AX25Address('VK4RZB', extension=True))
    eq_(data, b'frame data goes here')
Example #12
0
def test_extension_setter():
    """
    Test we can mutate the extension bit.
    """
    a = AX25Address('VK4MSL', 15, extension=False)
    a.extension = True
    assert a._extension is True
Example #13
0
def test_encode_repr():
    """
    Test we can represent the AX25Address as a Python string
    """
    eq_(repr(AX25Address('VK4MSL', ch=True)), \
            ('AX25Address(callsign=VK4MSL, ssid=0, ch=True, '\
             'res0=True, res1=True, extension=False)'))
Example #14
0
def test_ch_setter():
    """
    Test we can mutate the C/H bit.
    """
    a = AX25Address('VK4MSL', 15, ch=False)
    a.ch = True
    assert a._ch is True
Example #15
0
def test_mydigi_read():
    """
    Test we can obtain a copy of the digipeater call list.
    """
    digipeater = APRSDigipeater()
    digipeater._mydigi.add(AX25Address.decode('VK4MSL'))
    mydigi = digipeater.mydigi

    assert mydigi is not digipeater._mydigi
    eq_(mydigi, digipeater._mydigi)
Example #16
0
def test_normalised():
    """
    Test we can get normalised copies for comparison.
    """
    a = AX25Address('VK4MSL', 15, ch=True, res0=False, res1=False)
    b = a.normalised

    assert b._ch is False
    assert b._res0 is True
    assert b._res1 is True
Example #17
0
def test_disconnect_norm():
    """
    Test we can disconnect an interface without removing its call from our
    "mydigi" list.
    """
    interface = DummyAPRSInterface()
    digipeater = APRSDigipeater()
    digipeater.connect(interface)
    digipeater.disconnect(interface, rmcall=False)
    eq_(digipeater._mydigi, set([AX25Address.decode('VK4MSL-10')]))
Example #18
0
    def __init__(self):
        self._loop = DummyLoop()
        self._retransmit_count = 2
        self._retransmit_timeout_base = 5
        self._retransmit_timeout_rand = 5
        self._retransmit_timeout_scale = 1.5
        self.mycall = AX25Address.decode('N0CALL')
        self._next_msgid = 12345

        self.sent = []
        self.finished = []
Example #19
0
def test_encode_bytes_ext():
    """
    Test we can encode a AX25Address' extension bit as binary
    """
    eq_(
        to_hex(
            bytes(
                AX25Address('VK4MSL',
                            res0=False,
                            res1=False,
                            ch=False,
                            extension=True))), 'ac 96 68 9a a6 98 01')
Example #20
0
def test_copy():
    """
    Test we can make copies of the address with arbitrary fields set.
    """
    a = AX25Address('VK4MSL', 15, ch=False)
    b = a.copy(ch=True)

    assert b._ch is True

    # Everything else should be the same
    for field in ('_callsign', '_ssid', '_res0', '_res1', '_extension'):
        eq_(getattr(a, field), getattr(b, field))
Example #21
0
def test_encode_bytes_res0():
    """
    Test we can encode a AX25Address' Reserved 0 bit as binary
    """
    eq_(
        to_hex(
            bytes(
                AX25Address('VK4MSL',
                            res0=True,
                            res1=False,
                            ch=False,
                            extension=False))), 'ac 96 68 9a a6 98 20')
Example #22
0
def test_encode_bytes_ssid():
    """
    Test we can encode a AX25Address as binary
    """
    eq_(
        to_hex(
            bytes(
                AX25Address('VK4MSL',
                            11,
                            res0=False,
                            res1=False,
                            ch=False,
                            extension=False))), 'ac 96 68 9a a6 98 16')
Example #23
0
def test_msghandler_addressee():
    """
    Test the handler passes through the addressee given.
    """
    calls = []
    aprshandler = DummyAPRSHandler()
    msghandler = APRSMessageHandler(aprshandler=aprshandler,
                                    addressee='CQ',
                                    path=['WIDE1-1', 'WIDE2-1'],
                                    message='testing',
                                    replyack=False,
                                    log=logging.getLogger('messagehandler'))

    eq_(msghandler.addressee, AX25Address.decode('CQ'))
Example #24
0
 def addressee(self):
     self.addressee_calls += 1
     return AX25Address.decode('N0CALL')
Example #25
0
def test_decode_str():
    """
    Test that we can decode a call-sign into an AX.25 address.
    """
    addr = AX25Address.decode('VK4MSL')
    eq_(addr._callsign, 'VK4MSL')
Example #26
0
def test_decode_bytes_ch():
    """
    Test we can decode the C/H bit in binary.
    """
    addr = AX25Address.decode(from_hex('ac 96 68 9a a6 98 80'))
    eq_(addr._ch, True)
Example #27
0
def test_decode_bytes_res1():
    """
    Test we can decode the first reserved bit in binary.
    """
    addr = AX25Address.decode(from_hex('ac 96 68 9a a6 98 40'))
    eq_(addr._res1, True)
Example #28
0
def test_decode_bytes_ssid():
    """
    Test we can decode the SSID in binary.
    """
    addr = AX25Address.decode(from_hex('ac 96 68 9a a6 98 14'))
    eq_(addr._ssid, 10)
Example #29
0
def test_decode_bytes_ext():
    """
    Test we can decode the extension bit set in binary.
    """
    addr = AX25Address.decode(from_hex('ac 96 68 9a a6 98 01'))
    eq_(addr._extension, True)
Example #30
0
def test_decode_bytes_spaces():
    """
    Test trailing spaces are truncated in call-signs.
    """
    addr = AX25Address.decode(from_hex('ac 96 68 84 82 40 00'))
    eq_(addr._callsign, 'VK4BA')