Sample adjusted for Python3 (#7819)

Co-authored-by: chrismue <chrismue.gitlab@gmail.com>
Co-authored-by: Derek Bailey <derekbailey@google.com>
This commit is contained in:
chrismue 2023-02-07 06:47:39 +01:00 committed by GitHub
parent 535ead8d8c
commit 6af83a7d05
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 6 deletions

View File

@ -99,20 +99,20 @@ def main():
# Note: We did not set the `Mana` field explicitly, so we get a default value. # Note: We did not set the `Mana` field explicitly, so we get a default value.
assert monster.Mana() == 150 assert monster.Mana() == 150
assert monster.Hp() == 300 assert monster.Hp() == 300
assert monster.Name() == 'Orc' assert monster.Name() == b'Orc'
assert monster.Color() == MyGame.Sample.Color.Color().Red assert monster.Color() == MyGame.Sample.Color.Color().Red
assert monster.Pos().X() == 1.0 assert monster.Pos().X() == 1.0
assert monster.Pos().Y() == 2.0 assert monster.Pos().Y() == 2.0
assert monster.Pos().Z() == 3.0 assert monster.Pos().Z() == 3.0
# Get and test the `inventory` FlatBuffer `vector`. # Get and test the `inventory` FlatBuffer `vector`.
for i in xrange(monster.InventoryLength()): for i in range(monster.InventoryLength()):
assert monster.Inventory(i) == i assert monster.Inventory(i) == i
# Get and test the `weapons` FlatBuffer `vector` of `table`s. # Get and test the `weapons` FlatBuffer `vector` of `table`s.
expected_weapon_names = ['Sword', 'Axe'] expected_weapon_names = [b'Sword', b'Axe']
expected_weapon_damages = [3, 5] expected_weapon_damages = [3, 5]
for i in xrange(monster.WeaponsLength()): for i in range(monster.WeaponsLength()):
assert monster.Weapons(i).Name() == expected_weapon_names[i] assert monster.Weapons(i).Name() == expected_weapon_names[i]
assert monster.Weapons(i).Damage() == expected_weapon_damages[i] assert monster.Weapons(i).Damage() == expected_weapon_damages[i]
@ -128,10 +128,10 @@ def main():
union_weapon = MyGame.Sample.Weapon.Weapon() union_weapon = MyGame.Sample.Weapon.Weapon()
union_weapon.Init(monster.Equipped().Bytes, monster.Equipped().Pos) union_weapon.Init(monster.Equipped().Bytes, monster.Equipped().Pos)
assert union_weapon.Name() == "Axe" assert union_weapon.Name() == b"Axe"
assert union_weapon.Damage() == 5 assert union_weapon.Damage() == 5
print 'The FlatBuffer was successfully created and verified!' print('The FlatBuffer was successfully created and verified!')
if __name__ == '__main__': if __name__ == '__main__':
main() main()