示例#1
0
def test_is_valid5():
    """test for having invalid 32bit FCS field"""
    genericframe = GenericFrame()
    genericframe.parse(b'\x00')
    assert genericframe.is_valid() is False
示例#2
0
def test_set_address1():
    """setting an arbitary 8bit address with clear MSB should work."""
    genericframe = GenericFrame()
    genericframe.set_address(bytes([42]))
示例#3
0
def test_is_valid1():
    """test for having valid 16bit FCS field"""
    genericframe = GenericFrame()
    genericframe.parse(b'\x00')
    assert genericframe.is_valid() is True
示例#4
0
def test_is_allstation3(chunk2):
    """"given a no-station address, testing is_allstation should yield False"""
    genericframe = GenericFrame()
    genericframe.parse_address(chunk2)
    assert genericframe.is_allstation() is False
示例#5
0
def test_is_nostation2(chunk1):
    """parsing a all-station address should return False on is_nostation()"""
    genericframe = GenericFrame()
    genericframe.parse_address(chunk1)
    assert genericframe.is_nostation() is False
示例#6
0
def test_parse_address7():
    """unstripped input, 4 bytes, invalid closing flags"""
    genericframe = GenericFrame()
    with pytest.raises(ValueError):
        genericframe.parse_address(b'\x7e\x00\x00\x42')
示例#7
0
def test_is_allstation1(chunk1):
    """test frame generated with unicast/allstation address for having one"""
    genericframe = GenericFrame()
    genericframe.parse_address(chunk1)
    assert genericframe.is_allstation() is True
示例#8
0
def test_set_control0():
    """test for passing a bytes instance."""
    genericframe = GenericFrame()
    genericframe.set_control(bytes([42]))
示例#9
0
def test_set_control1():
    """test for passing Bytes array."""
    genericframe = GenericFrame()
    with pytest.raises(TypeError):
        genericframe.set_control(bytearray(1))
示例#10
0
def test_get_address0():
    """setting and retrieving an 8bit address on a genericframe."""
    genericframe = GenericFrame()
    genericframe.set_address(bytes([42]))
    assert bytes([42]) == genericframe.get_address()
示例#11
0
def test_get_address1():
    """test for returning bytes()"""
    genericframe = GenericFrame()
    assert isinstance(genericframe.get_address(), bytes)
示例#12
0
def test_set_address4():
    """setting 'all station' should work"""
    genericframe = GenericFrame()
    genericframe.set_address(bytes([255]))
    assert genericframe.is_allstation() is True
示例#13
0
def test_set_address3():
    """giving string as address should fail"""
    genericframe = GenericFrame()
    with pytest.raises(TypeError):
        genericframe.set_address('23')
示例#14
0
def test_set_address2():
    """giving int as address should fail"""
    genericframe = GenericFrame()
    with pytest.raises(TypeError):
        genericframe.set_address(42)
示例#15
0
def test_parse_address3():
    """test for too short bytearray """
    genericframe = GenericFrame()
    with pytest.raises(TypeError):
        genericframe.parse_address(bytearray(1))
示例#16
0
def test_get_control0():
    """test for retrieving set control field."""
    genericframe = GenericFrame()
    genericframe.set_control(bytes([42]))
    assert bytes([42]) == genericframe.get_control()
示例#17
0
def test_parse_address4():
    """stripped input: just two zero-bytes"""
    genericframe = GenericFrame()
    with pytest.raises(ValueError):
        genericframe.parse_address(bytes(2))
示例#18
0
def test_get_control1():
    """test for retrieving correct type"""
    genericframe = GenericFrame()
    assert isinstance(genericframe.get_control(), bytes)
示例#19
0
def test_parse_address9(chunk4):
    """parse I-frame control field with 1 byte address"""
    genericframe = GenericFrame()
    genericframe.parse_address(chunk4)
示例#20
0
def test_parse_address2():
    """test for rejecting float input"""
    genericframe = GenericFrame()
    with pytest.raises(TypeError):
        genericframe.parse_address(2.3)
示例#21
0
def test_is_allstation2():
    """vanilla object should not have an allstation address assigned"""
    genericframe = GenericFrame()
    assert genericframe.is_allstation() is False
示例#22
0
def test_is_IFrame0():
    """set I-frame bit and control for it."""
    genericframe = GenericFrame()
    genericframe.set_control(bytes([42]))
    assert genericframe.is_IFrame() is True
示例#23
0
def test_is_nostation1():
    """'no station' should be the default address for a base frame."""
    genericframe = GenericFrame()
    assert genericframe.is_nostation() is True
示例#24
0
def test_is_IFrame1():
    """test non-I-frame for being one."""
    genericframe = GenericFrame()
    genericframe.set_control(bytes([128]))
    assert genericframe.is_IFrame() is False
示例#25
0
def test_is_nostation3(chunk2):
    """parsing a no-station address should return True in is_nostation()"""
    genericframe = GenericFrame()
    genericframe.parse_address(chunk2)
    assert genericframe.is_nostation() is True
示例#26
0
def test_parse_address1():
    """test for rejecting strings"""
    genericframe = GenericFrame()
    with pytest.raises(TypeError):
        genericframe.parse_address('test')