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

Tests fail on Python 3.10 #143

Closed
yan12125 opened this issue Jun 7, 2022 · 4 comments · Fixed by #159
Closed

Tests fail on Python 3.10 #143

yan12125 opened this issue Jun 7, 2022 · 4 comments · Fixed by #159

Comments

@yan12125
Copy link

yan12125 commented Jun 7, 2022

There are two test failures with Python 3.10. With Python 3.9 everything seems fine. Could you have a look?

================================================================================== FAILURES ==================================================================================
_________________________________________________________________________________ test_repr __________________________________________________________________________________

    def test_repr():
>     assert repr(R(123, R11(y='abc'))) == epy.dedent("""
      R(
          x=123,
          y=R11(
              x=None,
              y='abc',
              z=None,
          ),
      )
      """)
E     assert "R(x=123, y=R...bc', z=None))" == 'R(\n    x=12...e,\n    ),\n)'
E       + R(x=123, y=R11(x=None, y='abc', z=None))
E       - R(
E       -     x=123,
E       -     y=R11(
E       -         x=None,
E       -         y='abc',
E       -         z=None,...
E
E       ...Full output truncated (3 lines hidden), use '-vv' to show

etils/edc/dataclass_utils_test.py:108: AssertionError
_____________________________________________________________________________ test_resource_path _____________________________________________________________________________

    def test_resource_path():
      path = epath.resource_utils.ResourcePath(_make_zip_file())
      assert isinstance(path, os.PathLike)
      assert path.joinpath('b/c.txt').read_text() == 'content of c'
      sub_dirs = list(path.joinpath('b').iterdir())
      assert len(sub_dirs) == 3
      for p in sub_dirs:  # Childs should be `ResourcePath` instances
        assert isinstance(p, epath.resource_utils.ResourcePath)

      # Forwarded to `Path` keep the resource.
      path = epath.Path(path)
      assert isinstance(path, epath.resource_utils.ResourcePath)

>     assert path.joinpath() == path
E     AssertionError: assert ResourcePath('alpharep.zip', '') == ResourcePath('alpharep.zip', '')
E      +  where ResourcePath('alpharep.zip', '') = <bound method Path.joinpath of ResourcePath('alpharep.zip', '')>()
E      +    where <bound method Path.joinpath of ResourcePath('alpharep.zip', '')> = ResourcePath('alpharep.zip', '').joinpath

For test_repr, apparently custom __repr__ is not applied as __qualname__ is changed in Python 3.10.

For test_resource_path, joinpath() returns a new object for Python >= 3.10 as that function is not overridden.

I noticed those failures when I'm creating a unofficial package python-etils for Arch Linux as a new dependency for the latest python-tensorflow-datasets.

Environment: Arch Linux x86_64, Python 3.10.4

@Conchylicultor
Copy link
Member

Thank you for reporting and finding those bugs. Your info are very helpful.

Don't hesitate to send a PR. Otherwise I'll have a look this week

@yan12125
Copy link
Author

yan12125 commented Jun 8, 2022

Thanks for the suggestion! I didn't send a PR yet as I'm not sure how to fix the issues. The __qualname__ issue involves Python internals and I may not be able to find a good fix soon. The joinpath issue is more like an incorrect test - apparently zipfile.Path.joinpath() still creates a new object when paths to join are empty. I'm not sure if epath should match the behavior of zipfile.Path or not.

@Conchylicultor
Copy link
Member

Thanks for the answer. I fixed those issues in #159.

For the zipfile, it looks like the issue is that __eq__ and __hash__ are missing from zipfile.Path. Opened an issue in python: https://discuss.python.org/t/missing-zipfile-path-eq-and-zipfile-path-hash/16519

@yan12125
Copy link
Author

Thanks, that works!

it looks like the issue is that __eq__ and __hash__ are missing from zipfile.Path

Yeah, that sounds reasonable. I found a more ambitious attempt python/cpython#31085: "It could also be used to make zipfile.Path objects fully pathlib-compatible (no missing methods!)"

copybara-service bot pushed a commit that referenced this issue Jun 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants