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

DM-40817: Allow skipping modules in ImportTestCase #173

Merged
merged 3 commits into from Sep 19, 2023

Conversation

arunkannawadi
Copy link
Member

@arunkannawadi arunkannawadi commented Sep 18, 2023

Checklist

  • ran Jenkins
  • added a release note for user-visible changes to doc/changes

@codecov
Copy link

codecov bot commented Sep 18, 2023

Codecov Report

Patch coverage: 100.00% and project coverage change: +0.01% 🎉

Comparison is base (42b57e1) 94.28% compared to head (413e2b0) 94.30%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #173      +/-   ##
==========================================
+ Coverage   94.28%   94.30%   +0.01%     
==========================================
  Files          46       46              
  Lines        3169     3180      +11     
==========================================
+ Hits         2988     2999      +11     
  Misses        181      181              
Files Changed Coverage Δ
python/lsst/utils/tests.py 79.22% <100.00%> (+0.35%) ⬆️
tests/test_import.py 100.00% <100.00%> (ø)

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@arunkannawadi arunkannawadi changed the title Allow skipping modules in ImportTestCase DM-40817: Allow skipping modules in ImportTestCase Sep 18, 2023
@arunkannawadi
Copy link
Member Author

Do we actually support python 3.9? There's a strange error that doesn't occur with python 3.10 or 3.11 and I am not sure if I should dig deep into this.

@timj
Copy link
Member

timj commented Sep 18, 2023

The error on 3.9 seems to be an interaction between importlib.resources and how it scans that package that lives in the tests directory. I think we have three options:

  • Change tests.py to use importlib_resources on python 3.9 (which is the 3.11 version of the code) and add dependency.
  • Give up on 3.9 completely
  • Skip the test case on python 3.9.

None of these options are more than a few lines to fix. My philosophy for utils is that, given it's a very low level package, I try to support as old a python as I can until I get annoyed by doing so.

@timj
Copy link
Member

timj commented Sep 18, 2023

I think my preference is to see if importlib_resources works on 3.9.

import sys
if sys.version_info < (3, 10, 0):
    import importlib_resources as resources
else:
    from importlib import resources

or something and see if that fixes it. (will need importlib_resources added as dependency to pyproject.toml and requirements.txt and I don't think there is a way to only make that happen on 3.9 distros)


def test_import(self):
"""Test that we can import utils."""
import import_test # noqa: F401
Copy link
Member

@timj timj Sep 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This import might be a no-op depending on what other tests have already run. (pkg_resources used to import parent classes as it went but I'm not sure if importlib.resources does so)

SKIP_MODULES: ClassVar[Mapping[str, Iterable[str]]] = {}
"""Modules to be skipped importing as key-value pairs.

The key is the package name and the value is a set of module names to skip.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is "module name" the right word here? Aren't these file names? ie you are requiring the .py extension.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could change it to SKIP_FILES. While on that, I should also change the type of the value to be Container[str], since I only need in to work.

python/lsst/utils/tests.py Outdated Show resolved Hide resolved
@@ -43,7 +43,11 @@
import unittest
import warnings
from collections.abc import Callable, Iterable, Iterator, Mapping, Sequence
from importlib import resources
import sys
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove.

from importlib import resources
import sys
if sys.version_info < (3, 10, 0):
import importlib_resources as resources
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that importlib_resources has to be added as a dependency to pyproject.toml and requirements.txt

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

from importlib import resources seems to work in python3.9 anyway. Does that have a different behavior despite the same name?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not the same name. It's different. importlib_resources is a PyPI package that allows older pythons to use the newer implementation of importlib.resources. That's why I was saying that you need to add importlib_resources as a dependency in pyproject.toml and requirements.txt.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

importlib.resources was working fine on python 3.9 until you caused it trouble by asking it to scan that package inside the tests directory. The reason I'm asking you to try importlib_resources on python 3.9 is that they might have fixed a bug in that area which explains why it worked fine on 3.10.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, this patch works! Thanks Tim, will clean up the changes, address the other minor comments and merge.

Copy link
Member

@timj timj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some minor comments.

@arunkannawadi arunkannawadi force-pushed the tickets/DM-40817 branch 2 times, most recently from 607d4d1 to c643c4b Compare September 18, 2023 21:05
@@ -346,6 +351,12 @@ class ImportTestCase(unittest.TestCase):
PACKAGES: ClassVar[Iterable[str]] = ()
"""Packages to be imported."""

SKIP_FILES: ClassVar[Mapping[str, Container[str]]] = {}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't forget to change the doc string.

@arunkannawadi arunkannawadi merged commit 3bf5ff2 into main Sep 19, 2023
15 checks passed
@arunkannawadi arunkannawadi deleted the tickets/DM-40817 branch September 19, 2023 15:42
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

Successfully merging this pull request may close these issues.

None yet

2 participants