Skip to content

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

Closed

Description

@neutrinoceros

Description

While working on #15690, I think I found a "vulnerability" in how we test for test completion for NEP 18 (array function) wrapping.
Specifically, the issue is that astropy.units.tests.test_quantity_non_ufuncs.CoverageMeta is currently not able to distinguish tests aim to cover np.linalg.outer from the ones that are targeted at np.outer because it only care about the function name, not the exact namespace it lives in.
By construction, this will not show up in tests, but I believe it'd be a good idea to make this meta test more robust.

Expected behavior

No response

How to Reproduce

No response

Versions

No response

Activity

  1. neutrinoceros commented on Dec 8, 2023

    @neutrinoceros
    ContributorAuthor

    By construction, this will not show up in tests

    I was wrong, it does show up. Now let's see why.

  2. neutrinoceros commented on Dec 8, 2023

    @neutrinoceros
    ContributorAuthor

    related: #15469

  3. neutrinoceros commented on Dec 8, 2023

    @neutrinoceros
    ContributorAuthor

    Alright I think I got it now:
    In #15469, @mhvk already added a mechanism to handle name collisions for the completion test. Specifically this was done as an edit in astropy/units/tests/test_quantity_non_ufuncs.py::get_wrapped_functions. However, I didn't initially understand the way it works, so here how it goes:

    • for each numpy function, assume we have a test named "test_{function_name}" ...
    • unless if we've already seen a function with the same name, in which case the test needs to be named test_{module_name}_{function_name}

    This worked fine for all cases known until this week, but it was somewhat confusing to discover this behaviour while working on #15691 (see d4d366b)
    I think we could make it more straightforward if we can rename all tests targeted at functions that live in sub-namespaces but share a name with another function living in the root numpy namespace. Or we could also close this as "won't fix" since it's not 100% clear it would be worth the effort. I'll let @mhvk be the judge here !

  4. mhvk commented on Dec 8, 2023

    @mhvk
    Contributor

    I think you are right, we should go to test_{module_name}_{function_name} generally (if we really want to be clever, the module name could be an attribute of the test class, but that's an implementation detail).

  5. neutrinoceros commented on Dec 8, 2023

    @neutrinoceros
    ContributorAuthor

    I'm not sure making the test code more clever will help, but I do think it would help to make it consistent. I'll pick it up soon. Thanks !

  6. neutrinoceros commented on Dec 12, 2023

    @neutrinoceros
    ContributorAuthor

    This is not critical but as I'm neck-deep into the units module these days, I might as well pick it up now !

  7. changed the title [-]TST: astropy.units NEP18 completion tests now have blindspots (colliding function names)[/-] [+]TST: astropy.units completion tests behave differently for functions with unique names[/+] on Dec 12, 2023
  8. neutrinoceros commented on Dec 12, 2023

    @neutrinoceros
    ContributorAuthor

    retitled the issue for posterity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions