Skip to content
Snippets Groups Projects
Commit d70c391b authored by Tamas Gal's avatar Tamas Gal :speech_balloon:
Browse files

Tag implementation

parent d8d8dc7f
Branches
No related tags found
No related merge requests found
......@@ -20,11 +20,35 @@ __status__ = "Development"
class Tag(object):
def __init__(self):
pass
SIZE = 8
def __init__(self, data=None):
self._data = b''
self.data = data
@property
def data(self):
return self._data
@data.setter
def data(self, value):
if not value:
value = b''
if len(value) > self.SIZE:
raise ValueError("The maximum tag size is {0}".format(self.SIZE))
self._data = value
while len(self._data) < self.SIZE:
self._data += b'\x00'
def __str__(self):
return str(self.data).strip('\x00')
def __len__(self):
return len(self._data)
class Message(object):
pass
class Prefix(object):
pass
class Message(object):
pass
......@@ -14,12 +14,36 @@ class TestTag(unittest.TestCase):
def test_init(self):
tag = Tag()
def test_empty_tag_has_correct_length(self):
tag = Tag()
self.assertEqual(Tag.SIZE, len(tag))
def test_tag_has_correct_length(self):
for tag_name in ('foo', 'bar', 'baz', '1'):
tag = Tag(tag_name)
self.assertEqual(Tag.SIZE, len(tag))
def test_tag_with_invalid_length_raises_valueerror(self):
with self.assertRaises(ValueError):
tag = Tag('123456789')
def test_tag_has_correct_data(self):
tag = Tag('foo')
self.assertEqual('foo\x00\x00\x00\x00\x00', tag.data)
tag = Tag('abcdefgh')
self.assertEqual('abcdefgh', tag.data)
def test_tag_has_correct_string_representation(self):
tag = Tag('foo')
self.assertEqual('foo', str(tag))
class TestMessage(unittest.TestCase):
def test_init(self):
message = Message()
class TestPrefix(unittest.TestCase):
def test_init(self):
prefix = Prefix()
class TestMessage(unittest.TestCase):
def test_init(self):
message = Message()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment