Commit d9db4825 authored by tguo-aa's avatar tguo-aa

Add self.assertNotNested() in CreateString

And also add a test case.
If you try to nest CreateString you will get a clear exception.
parent e1e1bced
......@@ -350,6 +350,8 @@ class Builder(object):
def CreateString(self, s):
"""CreateString writes a null-terminated byte string as a vector."""
self.assertNotNested()
if isinstance(s, compat.string_types):
x = s.encode()
elif isinstance(s, compat.binary_type):
......
......@@ -1130,6 +1130,13 @@ class TestExceptions(unittest.TestCase):
assertRaises(self, lambda: b.PrependUOffsetTRelative(1),
flatbuffers.builder.OffsetArithmeticError)
def test_create_string_is_nested_error(self):
b = flatbuffers.Builder(0)
b.StartObject(0)
s = 'test1'
assertRaises(self, lambda: b.CreateString(s),
flatbuffers.builder.ObjectIsNestedError)
def CheckAgainstGoldDataGo():
try:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment