MCPcopy Create free account
hub / github.com/StackStorm/st2 / test_cast_string

Method test_cast_string

st2common/tests/unit/test_casts.py:25–48  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

23
24class CastsTestCase(unittest.TestCase):
25 def test_cast_string(self):
26 cast_func = get_cast("string")
27
28 value = "test1"
29 result = cast_func(value)
30 self.assertEqual(result, "test1")
31
32 value = "test2"
33 result = cast_func(value)
34 self.assertEqual(result, "test2")
35
36 value = ""
37 result = cast_func(value)
38 self.assertEqual(result, "")
39
40 # None should be preserved
41 value = None
42 result = cast_func(value)
43 self.assertEqual(result, None)
44
45 # Non string or non, should throw a friendly exception
46 value = []
47 expected_msg = r'Value "\[\]" must either be a string or None. Got "list"'
48 self.assertRaisesRegex(ValueError, expected_msg, cast_func, value)
49
50 def test_cast_array(self):
51 cast_func = get_cast("array")

Callers

nothing calls this directly

Calls 2

get_castFunction · 0.90
cast_funcFunction · 0.85

Tested by

no test coverage detected