def test_list_bool_or_str_with_mixed_value(self): obs = parse_primitive(List[Bool] | List[Str], ('peanut', 'the', 'True')) self.assertEqual(obs, ['peanut', 'the', 'True']) self.assertIsInstance(obs, list) self.assertIsInstance(obs[0], str) self.assertIsInstance(obs[-1], str)
def test_str_type_float_value(self): obs = parse_primitive(Str, '42.0') self.assertEqual(obs, '42.0') self.assertIsInstance(obs, str)
def test_str_type_str_value(self): obs = parse_primitive(Str, 'peanut') self.assertEqual(obs, 'peanut') self.assertIsInstance(obs, str)
def test_set_int_bool_or_list_float_with_bool_int_value(self): obs = parse_primitive(Set[Int | Bool] | Set[Float], ('1', '2', 'True', 'False')) self.assertEqual(obs, {1, 2, True, False})
def test_list_float_bool_or_list_str_with_int_value(self): obs = parse_primitive(List[Float | Bool] | List[Int], ('1', '2', '3', '4')) self.assertEqual(obs, [1, 2, 3, 4])
def test_str_type_bool_value(self): obs = parse_primitive(Str, 'True') self.assertEqual(obs, 'True') self.assertIsInstance(obs, str)
def test_list_int_str_or_list_float_str_bool_with_float_bool_value(self): obs = parse_primitive(List[Int | Str] | List[Float | Str | Bool], ('1.1', '2.2', 'True', 'False')) self.assertEqual(obs, [1.1, 2.2, True, False])
def test_list_int_str_or_list_float_str_bool_with_float_value(self): obs = parse_primitive(List[Int | Str] | List[Float | Str | Bool], ('1.1', '2.2', '3.3', '4.4')) self.assertEqual(obs, [1.1, 2.2, 3.3, 4.4])
def test_list_float_or_str_with_mixed_value_variant_b(self): obs = parse_primitive(List[Float | Str], ('1.1', '2.2', 'dog')) self.assertEqual(obs, [1.1, 2.2, 'dog']) self.assertIsInstance(obs, list) self.assertIsInstance(obs[0], float) self.assertIsInstance(obs[-1], str)
def test_list_float_or_str_with_mixed_value_variant_a(self): obs = parse_primitive(List[Float | Str], ('peanut', '2.2', '3.3')) self.assertEqual(obs, ['peanut', 2.2, 3.3]) self.assertIsInstance(obs, list) self.assertIsInstance(obs[0], str) self.assertIsInstance(obs[1], float)
def test_list_float_or_str_with_float_value(self): obs = parse_primitive(List[Float | Str], ('1.1', '2.2', '3.3')) self.assertEqual(obs, [1.1, 2.2, 3.3]) self.assertIsInstance(obs, list) self.assertIsInstance(obs[0], float)
def test_list_float_or_bool_with_bad_mix_value(self): with self.assertRaisesRegex(ValueError, 'Could not coerce'): parse_primitive(List[Float | Bool], ('1.1', '2.2', 'peanut'))
def test_list_float_or_bool_with_mixed_value_variant_b(self): obs = parse_primitive(List[Float | Bool], ('1.1', '2.2', 'False')) self.assertEqual(obs, [1.1, 2.2, False]) self.assertIsInstance(obs, list) self.assertIsInstance(obs[0], float) self.assertIsInstance(obs[-1], bool)
def test_list_float_or_bool_with_mixed_value_variant_a(self): obs = parse_primitive(List[Float | Bool], ('True', '2.2', '3.3')) self.assertEqual(obs, [True, 2.2, 3.3]) self.assertIsInstance(obs, list) self.assertIsInstance(obs[0], bool) self.assertIsInstance(obs[1], float)
def test_set_int_or_str_with_mixed_value(self): obs = parse_primitive(Set[Int | Str], ('1', 'the', '2', 'dog')) self.assertEqual(obs, {1, 'the', 2, 'dog'}) self.assertIsInstance(obs, set)
def test_bool_type_bool_value(self): obs = parse_primitive(Bool, 'True') self.assertEqual(obs, True) self.assertIsInstance(obs, bool)
def test_list_int_str_or_list_float_with_str_int_value(self): obs = parse_primitive(List[Int | Str] | List[Float], ('1', '2', 'peanut', 'the')) self.assertEqual(obs, [1, 2, 'peanut', 'the'])
def test_set_float_or_str_with_float_value(self): obs = parse_primitive(Set[Float | Str], ('1.1', '2.2', '3.3')) self.assertEqual(obs, {1.1, 2.2, 3.3}) self.assertIsInstance(obs, set) self.assertIsInstance(obs.pop(), float)
def test_list_int_str_or_list_float_str_bool_with_float_str_value(self): obs = parse_primitive(List[Int | Str] | List[Float | Str | Bool], ('1.1', '2.2', 'the', 'peanut')) self.assertEqual(obs, [1.1, 2.2, 'the', 'peanut'])
def test_float_type_bool_value(self): with self.assertRaisesRegex(ValueError, 'Could not coerce'): parse_primitive(Float, 'True')
def test_list_int_str_or_list_float_with_mixed_value(self): obs = parse_primitive(List[Int | Str] | List[Float], ('1.1', '2', 'True', 'peanut')) self.assertEqual(obs, ['1.1', 2, 'True', 'peanut'])
def test_list_bool_or_str_with_bool_value(self): obs = parse_primitive(List[Bool | Str], ('True', 'False', 'True')) self.assertEqual(obs, [True, False, True]) self.assertIsInstance(obs, list) self.assertIsInstance(obs[0], bool)
def test_list_float_bool_or_list_str_with_float_bool_value(self): obs = parse_primitive(List[Float | Bool] | List[Int], ('1', '2', 'True', 'False')) self.assertEqual(obs, [1, 2, True, False])
def test_list_bool_or_str_with_str_value(self): obs = parse_primitive(List[Bool | Str], ('peanut', 'the', 'dog')) self.assertEqual(obs, ['peanut', 'the', 'dog']) self.assertIsInstance(obs, list) self.assertIsInstance(obs[0], str)
def test_list_float_bool_or_list_str_with_bad_value(self): with self.assertRaisesRegex(ValueError, 'Could not coerce'): parse_primitive(List[Float | Bool] | List[Int], ('1', '2.2', 'True', 'peanut'))
def test_list_bool_or_str_with_mixed_value_variant_a(self): obs = parse_primitive(List[Bool | Str], ('True', 'the', 'dog')) self.assertEqual(obs, [True, 'the', 'dog']) self.assertIsInstance(obs, list) self.assertIsInstance(obs[0], bool) self.assertIsInstance(obs[-1], str)
def test_bool_type_str_value(self): with self.assertRaisesRegex(ValueError, 'Could not coerce'): parse_primitive(Bool, 'peanut')
def test_set_bool_or_str_with_bool_value(self): obs = parse_primitive(Set[Bool | Str], ('True', 'False', 'True')) self.assertEqual(obs, {True, False}) self.assertIsInstance(obs, set) self.assertIsInstance(obs.pop(), bool)
def test_int_type_int_value(self): obs = parse_primitive(Int, 1) self.assertEqual(obs, 1) self.assertIsInstance(obs, int)
def test_set_bool_or_str_with_str_value(self): obs = parse_primitive(Set[Bool | Str], ('peanut', 'the', 'dog')) self.assertEqual(obs, {'peanut', 'the', 'dog'}) self.assertIsInstance(obs, set) self.assertIsInstance(obs.pop(), str)