Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test failure in 23.5.8 #7944

Closed
antonio-rojas opened this issue May 9, 2023 · 10 comments
Closed

Test failure in 23.5.8 #7944

antonio-rojas opened this issue May 9, 2023 · 10 comments

Comments

@antonio-rojas
Copy link

With Python 3.11.3:

Traceback (most recent call last):
  File "/build/flatbuffers/src/flatbuffers-23.5.8/tests/py_test.py", line 39, in <module>
    import MyGame.Example.Monster  # refers to generated code
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/build/flatbuffers/src/flatbuffers-23.5.8/tests/MyGame/Example/Monster.py", line 884, in <module>
    def AddPos(builder: flatbuffers.Builder, pos: Any):
                                                  ^^^
NameError: name 'Any' is not defined. Did you mean: 'any'?
@dbaileychess
Copy link
Collaborator

if you manually changed Any -> any does it fix it?

@antonio-rojas
Copy link
Author

There is another failure after that:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/home/antonio/Software/Arch/community/flatbuffers/trunk/src/flatbuffers-23.5.8/tests/MyGame/Example/Monster.py", line 1318, in <module>
    def AddNativeInline(builder: flatbuffers.Builder, nativeInline: Any):
                                                                    ^^^
NameError: name 'Any' is not defined. Did you mean: 'any'?

Changing it to any here too fixes it in the sense that the file can be imported in Python. Running the tests still fail because the file is regenerated with the wrong parameters by PythonTest.sh

@yan12125
Copy link
Contributor

Incorrectly-generated type annotation Any can be fixed with:

diff --git a/src/idl_gen_python.cpp b/src/idl_gen_python.cpp
index 1b11bbe2..72b54604 100644
--- a/src/idl_gen_python.cpp
+++ b/src/idl_gen_python.cpp
@@ -773,8 +773,14 @@ class PythonGenerator : public BaseGenerator {
 
     if (!parser_.opts.one_file && !parser_.opts.python_no_type_prefix_suffix) {
       // Generate method without struct name.
-      code += "def Add" + field_method + "(builder: flatbuffers.Builder, " + field_var + ": " + field_ty + "):\n";
+      code += "def Add" + field_method;
+      if (parser_.opts.python_typing) {
+        code += "(builder: flatbuffers.Builder, " + field_var + ": " + field_ty;
+      } else {
+        code += "(builder, " + field_var;
+      }
+      code += "):\n";
       code +=
           Indent + namer_.Type(struct_def) + "Add" + field_method;
       code += "(builder, ";
       code += field_var;

There are more test errors, though:

Running tests...
Test project /build/flatbuffers/src/build
    Start 1: flattests
1/1 Test #1: flattests ........................   Passed    1.38 sec

100% tests passed, 0 tests failed out of 1

Total Test time (real) =   1.38 sec
which: no python2.6 in (/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl)
which: no python2.7 in (/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl)
which: no python2.7 in (/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl)
Testing with interpreter: python3
======================================================================
ERROR: test_nested_monster_testnestedflatbuffer (__main__.TestAllCodePathsOfExampleSchema.test_nested_monster_testnestedflatbuffer)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/build/flatbuffers/src/flatbuffers-23.5.9/tests/py_test.py", line 2369, in test_nested_monster_testnestedflatbuffer
    nestedMon2 = mon2.TestnestedflatbufferNestedRoot()
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/build/flatbuffers/src/flatbuffers-23.5.9/tests/MyGame/Example/Monster.py", line 216, in TestnestedflatbufferNestedRoot
    from .MyGame.Example.Monster import Monster
ModuleNotFoundError: No module named 'MyGame.Example.MyGame'

======================================================================
ERROR: test_nondefault_monster_enemy (__main__.TestAllCodePathsOfExampleSchema.test_nondefault_monster_enemy)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/build/flatbuffers/src/flatbuffers-23.5.9/tests/py_test.py", line 2293, in test_nondefault_monster_enemy
    self.assertEqual(88, mon2.Enemy().Hp())
                         ^^^^^^^^^^^^
  File "/build/flatbuffers/src/flatbuffers-23.5.9/tests/MyGame/Example/Monster.py", line 191, in Enemy
    from .MyGame.Example.Monster import Monster
ModuleNotFoundError: No module named 'MyGame.Example.MyGame'

======================================================================
ERROR: test_nondefault_monster_parent_namespace_test (__main__.TestAllCodePathsOfExampleSchema.test_nondefault_monster_parent_namespace_test)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/build/flatbuffers/src/flatbuffers-23.5.9/tests/py_test.py", line 2456, in test_nondefault_monster_parent_namespace_test
    isinstance(monster.ParentNamespaceTest(),
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/build/flatbuffers/src/flatbuffers-23.5.9/tests/MyGame/Example/Monster.py", line 508, in ParentNamespaceTest
    from .MyGame.InParentNamespace import InParentNamespace
ModuleNotFoundError: No module named 'MyGame.Example.MyGame'

======================================================================
ERROR: test_nondefault_monster_testarrayoftables (__main__.TestAllCodePathsOfExampleSchema.test_nondefault_monster_testarrayoftables)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/build/flatbuffers/src/flatbuffers-23.5.9/tests/py_test.py", line 2254, in test_nondefault_monster_testarrayoftables
    self.assertEqual(99, mon2.Testarrayoftables(0).Hp())
                         ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/build/flatbuffers/src/flatbuffers-23.5.9/tests/MyGame/Example/Monster.py", line 168, in Testarrayoftables
    from .MyGame.Example.Monster import Monster
ModuleNotFoundError: No module named 'MyGame.Example.MyGame'

======================================================================
ERROR: test_nondefault_monster_testempty (__main__.TestAllCodePathsOfExampleSchema.test_nondefault_monster_testempty)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/build/flatbuffers/src/flatbuffers-23.5.9/tests/py_test.py", line 2390, in test_nondefault_monster_testempty
    self.assertEqual(123, mon2.Testempty().Val())
                          ^^^^^^^^^^^^^^^^
  File "/build/flatbuffers/src/flatbuffers-23.5.9/tests/MyGame/Example/Monster.py", line 237, in Testempty
    from .MyGame.Example.Stat import Stat
ModuleNotFoundError: No module named 'MyGame.Example.MyGame'

======================================================================
ERROR: test_mutate_enemy (__main__.TestAllMutableCodePathsOfExampleSchema.test_mutate_enemy)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/build/flatbuffers/src/flatbuffers-23.5.9/tests/py_test.py", line 489, in test_mutate_enemy
    self.assertEqual(monster.Enemy().Hp(), 200)
                     ^^^^^^^^^^^^^^^
  File "/build/flatbuffers/src/flatbuffers-23.5.9/tests/MyGame/Example/Monster.py", line 191, in Enemy
    from .MyGame.Example.Monster import Monster
ModuleNotFoundError: No module named 'MyGame.Example.MyGame'

======================================================================
ERROR: test_mutate_parentnamespacetest (__main__.TestAllMutableCodePathsOfExampleSchema.test_mutate_parentnamespacetest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/build/flatbuffers/src/flatbuffers-23.5.9/tests/py_test.py", line 586, in test_mutate_parentnamespacetest
    isinstance(monster.ParentNamespaceTest(),
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/build/flatbuffers/src/flatbuffers-23.5.9/tests/MyGame/Example/Monster.py", line 508, in ParentNamespaceTest
    from .MyGame.InParentNamespace import InParentNamespace
ModuleNotFoundError: No module named 'MyGame.Example.MyGame'

======================================================================
ERROR: test_mutate_pos (__main__.TestAllMutableCodePathsOfExampleSchema.test_mutate_pos)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/build/flatbuffers/src/flatbuffers-23.5.9/tests/py_test.py", line 369, in test_mutate_pos
    pos = monster.Pos()
          ^^^^^^^^^^^^^
  File "/build/flatbuffers/src/flatbuffers-23.5.9/tests/MyGame/Example/Monster.py", line 37, in Pos
    from .MyGame.Example.Vec3 import Vec3
ModuleNotFoundError: No module named 'MyGame.Example.MyGame'

======================================================================
ERROR: test_mutate_test4 (__main__.TestAllMutableCodePathsOfExampleSchema.test_mutate_test4)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/build/flatbuffers/src/flatbuffers-23.5.9/tests/py_test.py", line 442, in test_mutate_test4
    test0 = monster.Test4(0)
            ^^^^^^^^^^^^^^^^
  File "/build/flatbuffers/src/flatbuffers-23.5.9/tests/MyGame/Example/Monster.py", line 121, in Test4
    from .MyGame.Example.Test import Test
ModuleNotFoundError: No module named 'MyGame.Example.MyGame'

======================================================================
ERROR: test_mutate_testarrayoftables (__main__.TestAllMutableCodePathsOfExampleSchema.test_mutate_testarrayoftables)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/build/flatbuffers/src/flatbuffers-23.5.9/tests/py_test.py", line 476, in test_mutate_testarrayoftables
    self.assertEqual(monster.Testarrayoftables(0).Hp(), 200)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/build/flatbuffers/src/flatbuffers-23.5.9/tests/MyGame/Example/Monster.py", line 168, in Testarrayoftables
    from .MyGame.Example.Monster import Monster
ModuleNotFoundError: No module named 'MyGame.Example.MyGame'

======================================================================
ERROR: test_fixed_length_array (__main__.TestFixedLengthArrays.test_fixed_length_array)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/build/flatbuffers/src/flatbuffers-23.5.9/tests/py_test.py", line 2686, in test_fixed_length_array
    self.assertEqual(table.A().A(), 0.5)
                     ^^^^^^^^^
  File "/build/flatbuffers/src/flatbuffers-23.5.9/tests/MyGame/Example/ArrayTable.py", line 36, in A
    from .MyGame.Example.ArrayStruct import ArrayStruct
ModuleNotFoundError: No module named 'MyGame.Example.MyGame'

======================================================================
ERROR: test_nested_union_tables (__main__.TestNestedUnionTables.test_nested_union_tables)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/build/flatbuffers/src/flatbuffers-23.5.9/tests/py_test.py", line 2732, in test_nested_union_tables
    nestUnionDecodeT = MyGame.Example.NestedUnion.NestedUnionTest.NestedUnionTestT.InitFromObj(nestUnionDecode)
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/build/flatbuffers/src/flatbuffers-23.5.9/tests/MyGame/Example/NestedUnion/NestedUnionTest.py", line 125, in InitFromObj
    x._UnPack(nestedUnionTest)
  File "/build/flatbuffers/src/flatbuffers-23.5.9/tests/MyGame/Example/NestedUnion/NestedUnionTest.py", line 134, in _UnPack
    self.data = MyGame.Example.NestedUnion.Any.AnyCreator(self.dataType, nestedUnionTest.Data())
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/build/flatbuffers/src/flatbuffers-23.5.9/tests/MyGame/Example/NestedUnion/Any.py", line 16, in AnyCreator
    return MyGame.Example.NestedUnion.Vec3.Vec3T.InitFromBuf(table.Bytes, table.Pos)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/build/flatbuffers/src/flatbuffers-23.5.9/tests/MyGame/Example/NestedUnion/Vec3.py", line 142, in InitFromBuf
    return cls.InitFromObj(vec3)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/build/flatbuffers/src/flatbuffers-23.5.9/tests/MyGame/Example/NestedUnion/Vec3.py", line 152, in InitFromObj
    x._UnPack(vec3)
  File "/build/flatbuffers/src/flatbuffers-23.5.9/tests/MyGame/Example/NestedUnion/Vec3.py", line 164, in _UnPack
    if vec3.Test3() is not None:
       ^^^^^^^^^^^^
  File "/build/flatbuffers/src/flatbuffers-23.5.9/tests/MyGame/Example/NestedUnion/Vec3.py", line 67, in Test3
    from .MyGame.Example.NestedUnion.Test import Test
ModuleNotFoundError: No module named 'MyGame.Example.NestedUnion.MyGame'

======================================================================
ERROR: test_consistency_with_repeated_pack_and_unpack (__main__.TestObjectBasedAPI.test_consistency_with_repeated_pack_and_unpack)
Checks the serialization and deserialization between a buffer and
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/build/flatbuffers/src/flatbuffers-23.5.9/tests/py_test.py", line 144, in test_consistency_with_repeated_pack_and_unpack
    monsterT1 = _MONSTER.MonsterT.InitFromObj(monster1)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/build/flatbuffers/src/flatbuffers-23.5.9/tests/MyGame/Example/Monster.py", line 1483, in InitFromObj
    x._UnPack(monster)
  File "/build/flatbuffers/src/flatbuffers-23.5.9/tests/MyGame/Example/Monster.py", line 1490, in _UnPack
    if monster.Pos() is not None:
       ^^^^^^^^^^^^^
  File "/build/flatbuffers/src/flatbuffers-23.5.9/tests/MyGame/Example/Monster.py", line 37, in Pos
    from .MyGame.Example.Vec3 import Vec3
ModuleNotFoundError: No module named 'MyGame.Example.MyGame'

======================================================================
ERROR: test_wire_format (__main__.TestWireFormat.test_wire_format)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/build/flatbuffers/src/flatbuffers-23.5.9/tests/py_test.py", line 110, in test_wire_format
    CheckReadBuffer(
  File "/build/flatbuffers/src/flatbuffers-23.5.9/tests/py_test.py", line 645, in CheckReadBuffer
    vec = monster.Pos()
          ^^^^^^^^^^^^^
  File "/build/flatbuffers/src/flatbuffers-23.5.9/tests/MyGame/Example/Monster.py", line 37, in Pos
    from .MyGame.Example.Vec3 import Vec3
ModuleNotFoundError: No module named 'MyGame.Example.MyGame'

----------------------------------------------------------------------
Ran 121 tests in 0.028s

FAILED (errors=14)
Tests failed, skipping benchmarks.
Testing with multi-file generated code
numpy available

@yan12125
Copy link
Contributor

PythonTests.sh is run on GitHub Actions but errors are ignored (ex: https://github.com/google/flatbuffers/actions/runs/4933552489/jobs/8817618327).

run: bash PythonTest.sh

This line should be bash -e PythonTest.sh or ./PythonTest.sh for proper testing.

@dbaileychess
Copy link
Collaborator

Thanks, PR are welcomed

@yan12125
Copy link
Contributor

Thanks, but a PR may not be meaningful unless changes are properly tested.

By the way, those ModuleNotFound errors seem related to #7951.

@dbaileychess
Copy link
Collaborator

I meant a PR with the fixes and the CI updated to catch them.

@yan12125
Copy link
Contributor

By "properly tested", I meant CI checks are green if relevant codes are fixed and vice versa. With changes for #7951, I can get tests run on my machine, so here it is: #7960.

@yan12125
Copy link
Contributor

Thanks! Is there a timeline for a release including relevant fixes?

@miloder
Copy link

miloder commented Aug 25, 2023

Hi, was this ever fixed? I seem to be running into the same issue with flatc version 23.5.9. Changing "Any" to "any" manually fixes it, but obviously I'd have to do that every time I generate the code.

jochenparm pushed a commit to jochenparm/flatbuffers that referenced this issue Oct 29, 2024
* Don't generate types unless --python-typing specified

Fixes google#7944

* Fix incorrect import statements

Fixes google#7951

* Fix $PYTHONPATH in PythonTest.sh

Regressed from google#7529

* PythonTest: fail if something goes wrong

GitHub Actions runs `bash PythonTest.sh`, and thus failures were not
visible.

* Build flatc for Python tests

* Regenerate codes

---------

Co-authored-by: Derek Bailey <derekbailey@google.com>
jochenparm pushed a commit to jochenparm/flatbuffers that referenced this issue Oct 29, 2024
* Don't generate types unless --python-typing specified

Fixes google#7944

* Fix incorrect import statements

Fixes google#7951

* Fix $PYTHONPATH in PythonTest.sh

Regressed from google#7529

* PythonTest: fail if something goes wrong

GitHub Actions runs `bash PythonTest.sh`, and thus failures were not
visible.

* Build flatc for Python tests

* Regenerate codes

---------

Co-authored-by: Derek Bailey <derekbailey@google.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants