|
2 | 2 | import unittest |
3 | 3 |
|
4 | 4 | from pyof.foundation import basic_types |
| 5 | +from pyof.foundation.basic_types import BinaryData |
5 | 6 |
|
6 | 7 |
|
7 | 8 | class TestUBInt8(unittest.TestCase): |
@@ -160,3 +161,33 @@ def test_get_size(self): |
160 | 161 | """Testing get_size from IPAddress.""" |
161 | 162 | ip_addr = basic_types.IPAddress('192.168.0.1/24') |
162 | 163 | self.assertEqual(ip_addr.get_size(), 4) |
| 164 | + |
| 165 | + |
| 166 | +class TestBinaryData(unittest.TestCase): |
| 167 | + """Test Binary data type.""" |
| 168 | + |
| 169 | + def test_default_value(self): |
| 170 | + """Default packed value should be an empty byte.""" |
| 171 | + expected = b'' |
| 172 | + actual = BinaryData().pack() |
| 173 | + self.assertEqual(expected, actual) |
| 174 | + |
| 175 | + def test_pack_bytes(self): |
| 176 | + """Test packing some bytes.""" |
| 177 | + expected = b'forty two' |
| 178 | + actual = BinaryData(expected).pack() |
| 179 | + self.assertEqual(expected, actual) |
| 180 | + |
| 181 | + def test_pack_empty_bytes(self): |
| 182 | + """Test packing empty bytes.""" |
| 183 | + expected = b'' |
| 184 | + actual = BinaryData(expected).pack() |
| 185 | + self.assertEqual(expected, actual) |
| 186 | + |
| 187 | + def test_unexpected_value(self): |
| 188 | + """Should raise ValueError if constructor value is not bytes.""" |
| 189 | + self.assertRaises(ValueError, BinaryData, "can't be string") |
| 190 | + |
| 191 | + def test_unexpected_value_as_parameter(self): |
| 192 | + """Should raise ValueError if pack value is not bytes.""" |
| 193 | + self.assertRaises(ValueError, BinaryData().pack, "can't be string") |
0 commit comments