Esempio n. 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)
Esempio n. 2
0
 def test_str_type_float_value(self):
     obs = parse_primitive(Str, '42.0')
     self.assertEqual(obs, '42.0')
     self.assertIsInstance(obs, str)
Esempio n. 3
0
 def test_str_type_str_value(self):
     obs = parse_primitive(Str, 'peanut')
     self.assertEqual(obs, 'peanut')
     self.assertIsInstance(obs, str)
Esempio n. 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})
Esempio n. 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])
Esempio n. 6
0
 def test_str_type_bool_value(self):
     obs = parse_primitive(Str, 'True')
     self.assertEqual(obs, 'True')
     self.assertIsInstance(obs, str)
Esempio n. 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])
Esempio n. 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])
Esempio n. 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)
Esempio n. 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)
Esempio n. 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)
Esempio n. 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'))
Esempio n. 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)
Esempio n. 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)
Esempio n. 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)
Esempio n. 16
0
 def test_bool_type_bool_value(self):
     obs = parse_primitive(Bool, 'True')
     self.assertEqual(obs, True)
     self.assertIsInstance(obs, bool)
Esempio n. 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'])
Esempio n. 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)
Esempio n. 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'])
Esempio n. 20
0
 def test_float_type_bool_value(self):
     with self.assertRaisesRegex(ValueError, 'Could not coerce'):
         parse_primitive(Float, 'True')
Esempio n. 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'])
Esempio n. 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)
Esempio n. 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])
Esempio n. 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)
Esempio n. 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'))
Esempio n. 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)
Esempio n. 27
0
 def test_bool_type_str_value(self):
     with self.assertRaisesRegex(ValueError, 'Could not coerce'):
         parse_primitive(Bool, 'peanut')
Esempio n. 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)
Esempio n. 29
0
 def test_int_type_int_value(self):
     obs = parse_primitive(Int, 1)
     self.assertEqual(obs, 1)
     self.assertIsInstance(obs, int)
Esempio n. 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)