Skip to content

TST [units]: restore consistent naming convention for array functions tests - #15719

Merged
mhvk merged 3 commits into
astropy:mainfrom
neutrinoceros:units/test/hotfix_15692
Dec 14, 2023
Merged

mhvk merged 3 commits into
astropy:mainfrom
neutrinoceros:units/test/hotfix_15692

Conversation

@neutrinoceros

Copy link
Copy Markdown
Contributor

Description

Fixes #15692

ping @hamogu @mhvk

  • By checking this box, the PR author has requested that maintainers do NOT use the "Squash and Merge" button. Maintainers should respect this when possible; however, the final decision is at the discretion of the maintainer that merges the PR.

@neutrinoceros
neutrinoceros marked this pull request as draft December 12, 2023 13:48
@neutrinoceros

Copy link
Copy Markdown
Contributor Author

switching to draft while I fix failures

@neutrinoceros
neutrinoceros force-pushed the units/test/hotfix_15692 branch from b9d8117 to 8a55d07 Compare December 12, 2023 13:56
@neutrinoceros neutrinoceros changed the title TST: restore consistent naming convention for array functions tests TST [units]: restore consistent naming convention for array functions tests Dec 12, 2023
@neutrinoceros
neutrinoceros force-pushed the units/test/hotfix_15692 branch from 8a55d07 to 1a76000 Compare December 12, 2023 14:03
@neutrinoceros
neutrinoceros marked this pull request as ready for review December 12, 2023 15:21

@mhvk mhvk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looking at the actual changes, I think I'd prefer my earlier suggestion of a class attribute... See inline comments.

raise RuntimeError(f"failed to match {k=}")
function_name = m.group("function_name")
if (module_name := m.group("module_name")) is not None:
module_name = "numpy." + module_name.replace("_", ".").lower()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I don't much like the captilization...

def populate_covered_from_members(members, covered: set[FunctionType]) -> None:
for k, v in members.items():
if inspect.isfunction(v) and k.startswith("test_"):
if (m := MOD_REGEXP.fullmatch(k.removeprefix("test_"))) is None:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This regex which forces the capitalization feels a bit over the top to me... How about we go back to my suggestion of a test class attritute, ie.,

module_name = members.get("module", "numpy") 

(class attribute could also be "tested_module" for clarity, or something similar)

That means no changes to any of the test function names (except removing the two linalg ones).


covered = set()

def __new__(mcls, name, bases, members):

@mhvk mhvk Dec 12, 2023 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thought: if we change this to __init_subclass__(cls, tested_module="numpy", **kwargs), then we could have the signature of a test class be,

class TestFFT(InvariantUnitTestSetup, tested_module="np.fft"):
    ...

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This seems like a good idea, however I feel slightly out of my depth here, and I haven't succeeded in implementing it yet.
Could you show me how to do this change in a little bit more details, or maybe point me to relevant docs that I could use to learn about it ?

@neutrinoceros
neutrinoceros force-pushed the units/test/hotfix_15692 branch from 1a76000 to 80d8921 Compare December 13, 2023 14:47
@neutrinoceros

Copy link
Copy Markdown
Contributor Author

@mhvk I've rebased the branch and kept the newest changes as a separate commit. I really like your suggestion about changing the metaclass to avoid my inelegant case-based solution, but I think I'll need a hand to get it going !

@mhvk

mhvk commented Dec 13, 2023

Copy link
Copy Markdown
Contributor

@neutrinoceros - when looking at my suggestion, I realized __init_subclass__ didn't work, but also that the metaclass idea really wasn't all that great - I liked the solution in utils.masked of just going through the module and identifying test classes much better. So, I went ahead and implemented it like that. That also meant that it became easiest to identify the test module with a class attribute, so I went ahead and did that. And then of course I got a bit carried away and simplified things further...

Right now, it may be easiest to look at all our commits together; we should definitely squash them together when merging.

@neutrinoceros

Copy link
Copy Markdown
Contributor Author

Thank you so much @mhvk, I approve of your simplifications ! Now do we need someone else to bless this PR ?

@mhvk mhvk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@neutrinoceros - I think we can approve each other's contributions!

@mhvk
mhvk merged commit ab83084 into astropy:main Dec 14, 2023

@neutrinoceros neutrinoceros left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

1641491554

@neutrinoceros
neutrinoceros deleted the units/test/hotfix_15692 branch December 14, 2023 14:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TST: astropy.units completion tests behave differently for functions with unique names

3 participants