示例#1
0
 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)
示例#2
0
 def test_str_type_float_value(self):
     obs = parse_primitive(Str, '42.0')
     self.assertEqual(obs, '42.0')
     self.assertIsInstance(obs, str)
示例#3
0
 def test_str_type_str_value(self):
     obs = parse_primitive(Str, 'peanut')
     self.assertEqual(obs, 'peanut')
     self.assertIsInstance(obs, str)
示例#4
0
 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})
示例#5
0
 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])
示例#6
0
 def test_str_type_bool_value(self):
     obs = parse_primitive(Str, 'True')
     self.assertEqual(obs, 'True')
     self.assertIsInstance(obs, str)
示例#7
0
 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])
示例#8
0
 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])
示例#9
0
 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)
示例#10
0
 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)
示例#11
0
 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)
示例#12
0
 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'))
示例#13
0
 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)
示例#14
0
 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)
示例#15
0
 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)
示例#16
0
 def test_bool_type_bool_value(self):
     obs = parse_primitive(Bool, 'True')
     self.assertEqual(obs, True)
     self.assertIsInstance(obs, bool)
示例#17
0
 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'])
示例#18
0
 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)
示例#19
0
 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'])
示例#20
0
 def test_float_type_bool_value(self):
     with self.assertRaisesRegex(ValueError, 'Could not coerce'):
         parse_primitive(Float, 'True')
示例#21
0
 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'])
示例#22
0
 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)
示例#23
0
 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])
示例#24
0
 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)
示例#25
0
 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'))
示例#26
0
 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)
示例#27
0
 def test_bool_type_str_value(self):
     with self.assertRaisesRegex(ValueError, 'Could not coerce'):
         parse_primitive(Bool, 'peanut')
示例#28
0
 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)
示例#29
0
 def test_int_type_int_value(self):
     obs = parse_primitive(Int, 1)
     self.assertEqual(obs, 1)
     self.assertIsInstance(obs, int)
示例#30
0
 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)