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()
def test_invalid_key(self): block = { "key": "aloha", "type": "integer", "bits": 1, "mattata": "mattata", } with self.assertRaises(KeyError): spos.Block(block)
def test_invalid_choice(self): block = { "key": "aloha", "type": "integer", "mode": "wrong mode", "bits": 1, } with self.assertRaises(ValueError): spos.Block(block)
def test_wrong_type_for_optional_key(self): block = { "key": "aloha", "type": "integer", "bits": 1, "offset": "mattata", } with self.assertRaises(TypeError): spos.Block(block)
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)
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)
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)
def test_wrong_type_for_required_key(self): block = {"key": "aloha", "type": "integer", "bits": "mattata"} with self.assertRaises(TypeError): spos.Block(block)
def test_missing_required_key(self): block = {"key": "aloha", "type": "integer"} with self.assertRaises(KeyError): spos.Block(block)
def test_undefined_type(self): block = {"key": "aloha", "type": "hakuna"} with self.assertRaises(ValueError): spos.Block(block)
def test_type_not_in_block(self): block = {"key": "aloha"} with self.assertRaises(KeyError): spos.Block(block)
def test_key_value_not_a_string(self): block = {"type": "boolean", "key": True} with self.assertRaises(TypeError): spos.Block(block)
def test_key_not_in_block(self): block = {"type": "boolean"} with self.assertRaises(KeyError): spos.Block(block)