unit tests for bcd_data_stream
This commit is contained in:
parent
0f786a8c43
commit
fcc7177a9a
2 changed files with 23 additions and 4 deletions
23
tests/unit/test_bcd_data_stream.py
Normal file
23
tests/unit/test_bcd_data_stream.py
Normal file
|
@ -0,0 +1,23 @@
|
|||
from twisted.trial import unittest
|
||||
|
||||
from torba.bcd_data_stream import BCDataStream
|
||||
|
||||
|
||||
class TestBCDataStream(unittest.TestCase):
|
||||
|
||||
def test_write_read(self):
|
||||
s = BCDataStream()
|
||||
s.write_string(b'a'*252)
|
||||
s.write_string(b'b'*254)
|
||||
s.write_string(b'c'*(0xFFFF + 1))
|
||||
# s.write_string(b'd'*(0xFFFFFFFF + 1))
|
||||
s.write_boolean(True)
|
||||
s.write_boolean(False)
|
||||
s.reset()
|
||||
|
||||
self.assertEqual(s.read_string(), b'a'*252)
|
||||
self.assertEqual(s.read_string(), b'b'*254)
|
||||
self.assertEqual(s.read_string(), b'c'*(0xFFFF + 1))
|
||||
# self.assertEqual(s.read_string(), b'd'*(0xFFFFFFFF + 1))
|
||||
self.assertEqual(s.read_boolean(), True)
|
||||
self.assertEqual(s.read_boolean(), False)
|
|
@ -7,10 +7,6 @@ class BCDataStream:
|
|||
def __init__(self, data=None):
|
||||
self.data = BytesIO(data)
|
||||
|
||||
@property
|
||||
def is_at_beginning(self):
|
||||
return self.data.tell() == 0
|
||||
|
||||
def reset(self):
|
||||
self.data.seek(0)
|
||||
|
||||
|
|
Loading…
Reference in a new issue