Skip to content
This repository has been archived by the owner on May 28, 2022. It is now read-only.

Refactor and add tests for plugins.py #642

Closed

Conversation

SRomansky
Copy link
Contributor

Improvement to the tests currently being run on plugins.py

related #644

@dideler dideler added this to the 2014 Fall - UCOSP milestone Nov 3, 2014
for plugin in plugins:
plugin.plugin_object.load_config(plugin_manager)
if plugin.name == "Firewire Source":
# There is an issue with Firewire Source in testing
Copy link
Member

Choose a reason for hiding this comment

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

This would be better as a FIXME comment. Also refer to any related issues on GH if they exist.

Copy link
Member

Choose a reason for hiding this comment

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

sorry, what exactly is the issue?

Edit: can you explain the issue in the comment and also link to relevant bug numbers so that the next person who looks at this code has a fighting chance of understanding it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am not sure what the bug is. I thought https://github.com/Freeseer/freeseer/pull/589/files had discovered the bug but it appears it has not. I will look through git history to figure out when the comment was put it.

edit:
It appears that the firewire issue comment has existed since Freeseer was switch to git revision system.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The follow error is thrown when the firewire conditional is removed from the loop. This error occurs in the firewire src plugin based when constructing the pipe for GStreamer.

=================================== FAILURES ===================================
_______________ test_plugin_bin[plugin_info2-expected_instance2] _______________

plugin_manager = <freeseer.framework.plugin.PluginManager object at 0x7f04682b9a68>
plugin_info = ('VideoInput', 'get_videoinput_bin')
expected_instance = <type 'gst.Bin'>

    @pytest.mark.parametrize('plugin_info, expected_instance', [
        (('AudioInput', 'get_audioinput_bin'), gst.Bin),
        (('AudioMixer', 'get_audiomixer_bin'), gst.Bin),
        (('VideoInput', 'get_videoinput_bin'), gst.Bin),
        (('VideoMixer', 'get_videomixer_bin'), gst.Bin),
        (('Output', 'get_output_bin'), gst.Bin)
    ])
    def test_plugin_bin(plugin_manager, plugin_info, expected_instance):
        """Check that a plugin and its get method returns the proper gst.Bin object"""
        plugin_name, get_plugin_method = plugin_info
        plugins = plugin_manager.get_plugins_of_category(plugin_name)

        for plugin in plugins:
            plugin.plugin_object.load_config(plugin_manager)
    #        if plugin.name == "Firewire Source":
                # There is an issue with Firewire Source in testing found in gh#589
                # Skip until this is resolved
    #            continue
>           plugin_bin = getattr(plugin.plugin_object, get_plugin_method)()

freeseer/tests/framework/test_plugins.py:59: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <yapsy_loaded_plugin_Firewire_Source_19.FirewireSrc object at 0x7f04600dce90>

    def get_videoinput_bin(self):
        bin = gst.Bin()  # Do not pass a name so that we can load this input more than once.

        videosrc = gst.element_factory_make("dv1394src", "videosrc")
        dv1394q1 = gst.element_factory_make('queue', 'dv1394q1')
        dv1394dvdemux = gst.element_factory_make('dvdemux', 'dv1394dvdemux')
        dv1394q2 = gst.element_factory_make('queue', 'dv1394q2')
        dv1394dvdec = gst.element_factory_make('dvdec', 'dv1394dvdec')

        # Add Elements
        bin.add(videosrc)
        bin.add(dv1394q1)
        bin.add(dv1394dvdemux)
        bin.add(dv1394q2)
        bin.add(dv1394dvdec)

        # Link Elements
        videosrc.link(dv1394q1)
        dv1394q1.link(dv1394dvdemux)
>       dv1394dvdemux.link(dv1394q2)
E       LinkError: failed to link dv1394dvdemux with dv1394q2

freeseer/plugins/videoinput/firewiresrc/__init__.py:100: LinkError
------------------------------- Captured stderr --------------------------------
2014-11-03 16:52:49,449 (   DEBUG) freeseer.framework.plugin               : Plugin manager initialized.
--------------- coverage: platform linux2, python 2.7.6-final-0 ----------------

Copy link
Contributor Author

Choose a reason for hiding this comment

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

#644 added and updated the code comment

@dideler
Copy link
Member

dideler commented Nov 9, 2014

count_platform_plugins_in_directory looks like an expensive operation and is called quite a bit. How long does it take for these tests to run? edit: consider caching the values

@SRomansky
Copy link
Contributor Author

On my laptop before caching the tests took 1.07 seconds to run, after caching 1.03 seconds. With a HDD the time difference would probably be even larger.

for root, directory, files in os.walk(path, topdown=False):
for filename in files:
if filename.endswith(plugin_suffix):
plugin_name = os.path.splitext(filename)[0]
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 more pythonic to ignore the second element in the tuple instead of indexing.

plugin_name, _ = os.path.splitext(filename)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh that is a cool feature, implemented.

@dideler
Copy link
Member

dideler commented Nov 14, 2014

I think this is close to being merge-ready. Can you squash your commits?

@SRomansky SRomansky force-pushed the 484-plugin-test-refactor branch 2 times, most recently from 0cc13cc to 3fbdda3 Compare November 15, 2014 18:10
for plugin in plugins:
if hasattr(plugin.plugin_object, 'config'):
assert plugin.plugin_object.CONFIG_CLASS
assert not plugin.config
Copy link
Member

Choose a reason for hiding this comment

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

Is plugin.config correct or should it be plugin.plugin_object.config?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah. Plugin Manager does not have a config attribute. Only IBackendPlugin has a config attribute.

However, in the unit test I replaced the not, so it was assert plugin.plugin_object.config and it passed, then I tried assert not plugin.plugin_object.config and it also passed. Will look into this later today.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It appears that the plugin_object never has a config attribute. Hence the assertions are never called. I am looking for an example of a plugin loading a plugin configuration with plugin_object.load_config(). However, freeseer/src$ grep -r load_config\(.*,.*,.*\) freeseer/plugins/ shows that there are no plugins who use the config arguement on the load_config function. (It should be the third value).

Copy link
Member

Choose a reason for hiding this comment

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

That's because the backend loads configuration when it needs it. See:

https://github.com/Freeseer/freeseer/blob/master/src/freeseer/framework/multimedia.py


from freeseer.framework.config.profile import ProfileManager
from freeseer.framework.plugin import PluginManager
from freeseer.framework.plugin import PluginManager, IAudioInput
from freeseer.framework.config import Config, options
Copy link
Member

Choose a reason for hiding this comment

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

One import per line please.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed, sorry about that.

@dideler
Copy link
Member

dideler commented Nov 20, 2014

Is this good to go on your end? If so, please squash again.

@SRomansky SRomansky force-pushed the 484-plugin-test-refactor branch from c9c9ada to 24c7727 Compare November 20, 2014 16:14
@SRomansky
Copy link
Contributor Author

squashed

@dideler
Copy link
Member

dideler commented Nov 20, 2014

Please fix your commit message to use proper issue referencing, see http://freeseer.readthedocs.org/en/latest/contribute/basics.html#reference-issues-in-your-commit-messages. The formatting you're using is only recognized by our IRC bot.

- Refactor test_plugins to use pytest

- add new functionality tests

- Add FIXME comment for firewiresrc issue

- Create git issue to track FIXME status

- Add a plugin information cache fixture for test efficiency

Fix Freeseer#642
Related to Freeseer#619
Related to Freeseer#484
@SRomansky SRomansky force-pushed the 484-plugin-test-refactor branch from 24c7727 to b4bceb2 Compare November 20, 2014 17:57
@SRomansky
Copy link
Contributor Author

Fixed, sorry about that.

@dideler dideler closed this in e1d1c42 Nov 20, 2014
dideler added a commit that referenced this pull request Nov 20, 2014
@dideler
Copy link
Member

dideler commented Nov 20, 2014

Merged as e1d1c42, thanks @wigglier.

@SRomansky SRomansky deleted the 484-plugin-test-refactor branch November 21, 2014 22:39
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants