Skip to content

Commit 8a89b94

Browse files
committed
fixes issue 5263 assertion fail with python3 which expects strings prefixed with the letter b: bytes literal
1 parent e47ca7a commit 8a89b94

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

samples/sample_binary.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ def main():
3535
builder = flatbuffers.Builder(0)
3636

3737
# Create some weapons for our Monster ('Sword' and 'Axe').
38-
weapon_one = builder.CreateString('Sword')
39-
weapon_two = builder.CreateString('Axe')
38+
weapon_one = builder.CreateString(b'Sword')
39+
weapon_two = builder.CreateString(b'Axe')
4040

4141
MyGame.Sample.Weapon.WeaponStart(builder)
4242
MyGame.Sample.Weapon.WeaponAddName(builder, weapon_one)
@@ -49,7 +49,7 @@ def main():
4949
axe = MyGame.Sample.Weapon.WeaponEnd(builder)
5050

5151
# Serialize the FlatBuffer data.
52-
name = builder.CreateString('Orc')
52+
name = builder.CreateString(b'Orc')
5353

5454
MyGame.Sample.Monster.MonsterStartInventoryVector(builder, 10)
5555
# Note: Since we prepend the bytes, this loop iterates in reverse order.
@@ -99,20 +99,20 @@ def main():
9999
# Note: We did not set the `Mana` field explicitly, so we get a default value.
100100
assert monster.Mana() == 150
101101
assert monster.Hp() == 300
102-
assert monster.Name() == 'Orc'
102+
assert monster.Name() == b'Orc'
103103
assert monster.Color() == MyGame.Sample.Color.Color().Red
104104
assert monster.Pos().X() == 1.0
105105
assert monster.Pos().Y() == 2.0
106106
assert monster.Pos().Z() == 3.0
107107

108108
# Get and test the `inventory` FlatBuffer `vector`.
109-
for i in xrange(monster.InventoryLength()):
109+
for i in range(monster.InventoryLength()):
110110
assert monster.Inventory(i) == i
111111

112112
# Get and test the `weapons` FlatBuffer `vector` of `table`s.
113-
expected_weapon_names = ['Sword', 'Axe']
113+
expected_weapon_names = [b'Sword', b'Axe']
114114
expected_weapon_damages = [3, 5]
115-
for i in xrange(monster.WeaponsLength()):
115+
for i in range(monster.WeaponsLength()):
116116
assert monster.Weapons(i).Name() == expected_weapon_names[i]
117117
assert monster.Weapons(i).Damage() == expected_weapon_damages[i]
118118

@@ -128,10 +128,10 @@ def main():
128128
union_weapon = MyGame.Sample.Weapon.Weapon()
129129
union_weapon.Init(monster.Equipped().Bytes, monster.Equipped().Pos)
130130

131-
assert union_weapon.Name() == "Axe"
131+
assert union_weapon.Name() == b'Axe'
132132
assert union_weapon.Damage() == 5
133133

134-
print 'The FlatBuffer was successfully created and verified!'
134+
print('The FlatBuffer was successfully created and verified!')
135135

136136
if __name__ == '__main__':
137137
main()

0 commit comments

Comments
 (0)