Coverage for src/km3pipe/tests/test_controlhost.py: 100%

34 statements  

« prev     ^ index     » next       coverage.py v7.4.4, created at 2024-04-20 03:14 +0000

1# Filename: test_controlhost.py 

2# pylint: disable=locally-disabled,C0111,R0904,R0201,C0103,W0612 

3""" 

4Unit tests for the controlhost module. 

5 

6""" 

7 

8from km3pipe.controlhost import Tag, Message, Prefix 

9 

10from km3pipe.testing import TestCase 

11 

12__author__ = "Tamas Gal" 

13__copyright__ = "Copyright 2016, Tamas Gal and the KM3NeT collaboration." 

14__credits__ = [] 

15__license__ = "MIT" 

16__maintainer__ = "Tamas Gal" 

17__email__ = "tgal@km3net.de" 

18__status__ = "Development" 

19 

20 

21class TestTag(TestCase): 

22 def test_empty_tag_has_correct_length(self): 

23 tag = Tag() 

24 self.assertEqual(Tag.SIZE, len(tag)) 

25 

26 def test_tag_has_correct_length(self): 

27 for tag_name in (b"foo", b"bar", b"baz", b"1"): 

28 tag = Tag(tag_name) 

29 self.assertEqual(Tag.SIZE, len(tag)) 

30 

31 def test_tag_with_invalid_length_raises_valueerror(self): 

32 self.assertRaises(ValueError, Tag, "123456789") 

33 

34 def test_tag_has_correct_data(self): 

35 tag = Tag(b"foo") 

36 self.assertEqual(b"foo\x00\x00\x00\x00\x00", tag.data) 

37 tag = Tag("abcdefgh") 

38 self.assertEqual("abcdefgh", tag.data) 

39 

40 def test_tag_has_correct_string_representation(self): 

41 tag = Tag(b"foo") 

42 self.assertEqual("foo", str(tag)) 

43 

44 

45class TestPrefix(TestCase): 

46 def test_init(self): 

47 Prefix(b"foo", 1) 

48 

49 

50class TestMessage(TestCase): 

51 def test_init(self): 

52 Message("")