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

Add entry points for supported inventory sources #61

Merged
merged 8 commits into from
Dec 9, 2024

Conversation

jessicamack
Copy link
Member

A related change for ansible/awx#15658

also fix inventory name to match class
Copy link

codecov bot commented Nov 22, 2024

❌ 2 Tests Failed:

Tests completed Failed Passed Skipped
57 2 55 0
View the top 2 failed tests by shortest run time
tests/importable_test.py::::test_entry_points_are_inventory_plugin[azure-rm=awx_plugins.inventory.plugins:azure_rm@awx_plugins.inventory]
Stack Traces | 0.002s run time
self = [EntryPoint(name='azure_rm', value='awx_plugins.inventory.plugins:azure_rm', group='awx_plugins.inventory'), EntryPoin...ns.inventory'), EntryPoint(name='vmware', value='awx_plugins.inventory.plugins:vmware', group='awx_plugins.inventory')]
name = 'azure-rm'

    def __getitem__(self, name):  # -> EntryPoint:
        """
        Get the EntryPoint in self matching name.
        """
        if isinstance(name, int):
            warnings.warn(
                "Accessing entry points by index is deprecated. "
                "Cast to tuple if needed.",
                DeprecationWarning,
                stacklevel=2,
            )
            return super().__getitem__(name)
        try:
>           return next(iter(self.select(name=name)))
#x1B[1m#x1B[31mE           StopIteration#x1B[0m

__class__  = <class 'importlib.metadata.EntryPoints'>
name       = 'azure-rm'
self       = [EntryPoint(name='azure_rm', value='awx_plugins.inventory.plugins:azure_rm', group='awx_plugins.inventory'), EntryPoin...ns.inventory'), EntryPoint(name='vmware', value='awx_plugins.inventory.plugins:vmware', group='awx_plugins.inventory')]

#x1B[1m#x1B[.../Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11....../importlib/metadata/__init__.py#x1B[0m:371: StopIteration

#x1B[33mDuring handling of the above exception, another exception occurred:#x1B[0m

entry_point = EntryPointParam(group='awx_plugins.inventory', name='azure-rm', spec='awx_plugins.inventory.plugins:azure_rm')

    @with_inventory_plugins
    def test_entry_points_are_inventory_plugin(
            entry_point: EntryPointParam,
    ) -> None:
        """Ensure all exposed inventory plugins are of the same class."""  # noqa: D200, DAR101; FIXME
        entry_points = _discover_entry_points(group=entry_point.group)
>       loaded_plugin_class = entry_points[entry_point.name].load()

entry_point = EntryPointParam(group='awx_plugins.inventory', name='azure-rm', spec='awx_plugins.inventory.plugins:azure_rm')
entry_points = [EntryPoint(name='azure_rm', value='awx_plugins.inventory.plugins:azure_rm', group='awx_plugins.inventory'), EntryPoin...ns.inventory'), EntryPoint(name='vmware', value='awx_plugins.inventory.plugins:vmware', group='awx_plugins.inventory')]

#x1B[1m#x1B[31mtests/importable_test.py#x1B[0m:192: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = [EntryPoint(name='azure_rm', value='awx_plugins.inventory.plugins:azure_rm', group='awx_plugins.inventory'), EntryPoin...ns.inventory'), EntryPoint(name='vmware', value='awx_plugins.inventory.plugins:vmware', group='awx_plugins.inventory')]
name = 'azure-rm'

    def __getitem__(self, name):  # -> EntryPoint:
        """
        Get the EntryPoint in self matching name.
        """
        if isinstance(name, int):
            warnings.warn(
                "Accessing entry points by index is deprecated. "
                "Cast to tuple if needed.",
                DeprecationWarning,
                stacklevel=2,
            )
            return super().__getitem__(name)
        try:
            return next(iter(self.select(name=name)))
        except StopIteration:
>           raise KeyError(name)
#x1B[1m#x1B[31mE           KeyError: 'azure-rm'#x1B[0m

__class__  = <class 'importlib.metadata.EntryPoints'>
name       = 'azure-rm'
self       = [EntryPoint(name='azure_rm', value='awx_plugins.inventory.plugins:azure_rm', group='awx_plugins.inventory'), EntryPoin...ns.inventory'), EntryPoint(name='vmware', value='awx_plugins.inventory.plugins:vmware', group='awx_plugins.inventory')]

#x1B[1m#x1B[.../Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11....../importlib/metadata/__init__.py#x1B[0m:373: KeyError
tests/importable_test.py::::test_entry_points_exposed[azure-rm=awx_plugins.inventory.plugins:azure_rm@awx_plugins.inventory]
Stack Traces | 0.002s run time
entry_point = EntryPointParam(group='awx_plugins.inventory', name='azure-rm', spec='awx_plugins.inventory.plugins:azure_rm')

    @with_all_plugins
    def test_entry_points_exposed(entry_point: EntryPointParam) -> None:
        """Verify the plugin entry points are discoverable.
    
        This check relies on the plugin-declaring distribution package to be
        pre-installed.
        """  # noqa: DAR101; FIXME
        entry_points = _discover_entry_points(group=entry_point.group)
    
>       assert entry_point.name in entry_points.names
#x1B[1m#x1B[31mE       AssertionError: assert 'azure-rm' in {'azure_rm', 'constructed', 'controller', 'ec2', 'gce', 'insights', ...}#x1B[0m
#x1B[1m#x1B[31mE        +  where 'azure-rm' = EntryPointParam(group='awx_plugins.inventory', name='azure-rm', spec='awx_plugins.inventory.plugins:azure_rm').name#x1B[0m
#x1B[1m#x1B[31mE        +  and   {'azure_rm', 'constructed', 'controller', 'ec2', 'gce', 'insights', ...} = [EntryPoint(name='azure_rm', value='awx_plugins.inventory.plugins:azure_rm', group='awx_plugins.inventory'), EntryPoin...ns.inventory'), EntryPoint(name='vmware', value='awx_plugins.inventory.plugins:vmware', group='awx_plugins.inventory')].names#x1B[0m

entry_point = EntryPointParam(group='awx_plugins.inventory', name='azure-rm', spec='awx_plugins.inventory.plugins:azure_rm')
entry_points = [EntryPoint(name='azure_rm', value='awx_plugins.inventory.plugins:azure_rm', group='awx_plugins.inventory'), EntryPoin...ns.inventory'), EntryPoint(name='vmware', value='awx_plugins.inventory.plugins:vmware', group='awx_plugins.inventory')]

#x1B[1m#x1B[31mtests/importable_test.py#x1B[0m:170: AssertionError

To view more test analytics, go to the Test Analytics Dashboard
📢 Thoughts on this report? Let us know!

pyproject.toml Outdated Show resolved Hide resolved
jessicamack and others added 3 commits December 2, 2024 06:13
Co-authored-by: 🇺🇦 Sviatoslav Sydorenko (Святослав Сидоренко) <[email protected]>
@jessicamack jessicamack requested a review from webknjaz December 6, 2024 18:06
Copy link
Member

@webknjaz webknjaz left a comment

Choose a reason for hiding this comment

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

I suggest simplifying the tests like this.

tests/importable_test.py Outdated Show resolved Hide resolved
tests/importable_test.py Outdated Show resolved Hide resolved
tests/importable_test.py Outdated Show resolved Hide resolved
tests/importable_test.py Outdated Show resolved Hide resolved
From the runtime perspective, they are the same so there's no reason to separate
@jessicamack jessicamack requested a review from webknjaz December 6, 2024 20:16
@jessicamack jessicamack added this pull request to the merge queue Dec 9, 2024
Merged via the queue into ansible:devel with commit 9ec3d58 Dec 9, 2024
31 of 33 checks passed
@jessicamack jessicamack deleted the add-entry-points branch December 9, 2024 17:56
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.

3 participants