Пример #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)