示例#1
0
 def test_validate_encode_input_types_decorator_type_error(self):
     block = {"key": "boolean encode true", "type": "boolean"}
     block = spos.Block(block)
     with self.assertRaises(TypeError):
         block.bin_encode(True, "err")
     with self.assertRaises(TypeError):
         block.bin_encode()
示例#2
0
 def test_invalid_key(self):
     block = {
         "key": "aloha",
         "type": "integer",
         "bits": 1,
         "mattata": "mattata",
     }
     with self.assertRaises(KeyError):
         spos.Block(block)
示例#3
0
 def test_invalid_choice(self):
     block = {
         "key": "aloha",
         "type": "integer",
         "mode": "wrong mode",
         "bits": 1,
     }
     with self.assertRaises(ValueError):
         spos.Block(block)
示例#4
0
 def test_wrong_type_for_optional_key(self):
     block = {
         "key": "aloha",
         "type": "integer",
         "bits": 1,
         "offset": "mattata",
     }
     with self.assertRaises(TypeError):
         spos.Block(block)
示例#5
0
    def evaluate_value(self, block_spec):
        block = spos.Block(block_spec)
        messages = set()
        values = list()
        for i in range(self.n_tests):
            value = srandom.block_random_value(block_spec)
            values.append(value)
            message = block.bin_encode(value)
            messages.add(message)

        if block.type not in ["array", "object"]:
            self.assertEqual(len(message) - 2, block.bits)

        if block.type == "pad":
            return
        self.assertGreaterEqual(len(messages), 2)
        self.assertGreaterEqual(len(values), 2)
示例#6
0
    def test_seed(self):
        block_spec = {
            "key": "integer",
            "type": "integer",
            "bits": 16,
        }
        messages = set()
        values = list()
        block = spos.Block(block_spec)
        for i in range(self.n_tests):
            srandom.seed(1)
            message = srandom.block_random_message(block_spec)
            messages.add(message)
            values.append(block.bin_decode(message))

        if block.type not in ["array", "object"]:
            self.assertEqual(len(message) - 2, block.bits)

        self.assertEqual(len(messages), 1)
        self.assertEqual(len(set(values)), 1)
示例#7
0
 def test_validate_encode_input_types_decorator_keyword_argument(self):
     block = {"key": "boolean encode true", "type": "boolean"}
     block = spos.Block(block)
     block.bin_encode(value=True)
示例#8
0
 def test_wrong_type_for_required_key(self):
     block = {"key": "aloha", "type": "integer", "bits": "mattata"}
     with self.assertRaises(TypeError):
         spos.Block(block)
示例#9
0
 def test_missing_required_key(self):
     block = {"key": "aloha", "type": "integer"}
     with self.assertRaises(KeyError):
         spos.Block(block)
示例#10
0
 def test_undefined_type(self):
     block = {"key": "aloha", "type": "hakuna"}
     with self.assertRaises(ValueError):
         spos.Block(block)
示例#11
0
 def test_type_not_in_block(self):
     block = {"key": "aloha"}
     with self.assertRaises(KeyError):
         spos.Block(block)
示例#12
0
 def test_key_value_not_a_string(self):
     block = {"type": "boolean", "key": True}
     with self.assertRaises(TypeError):
         spos.Block(block)
示例#13
0
 def test_key_not_in_block(self):
     block = {"type": "boolean"}
     with self.assertRaises(KeyError):
         spos.Block(block)