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

Error with mock in Python 3.8.3 and 3.9 #923

Open
radarsat1 opened this issue Jun 17, 2020 · 3 comments
Open

Error with mock in Python 3.8.3 and 3.9 #923

radarsat1 opened this issue Jun 17, 2020 · 3 comments

Comments

@radarsat1
Copy link

Hello,

While testing on Debian unstable, the test_helper.py has failed with an error related to Mock when applied to MergeLayer. I have been trying to fix it but I do not know the mock library well and haven't yet succeeded. Any ideas? It seems the output_shape property is triggering an unimplemented function in MergeLayer.

Output of pytest:

$ pytest-3 -k helper -x
======================================== test session starts ========================================
platform linux -- Python 3.8.3, pytest-4.6.11, py-1.8.1, pluggy-0.13.0 -- /usr/bin/python3
cachedir: .pytest_cache
rootdir: /home/sinclairs/projects/debian/lasagne, inifile: setup.cfg
collected 1404 items / 1348 deselected / 56 selected                                                
  
lasagne/layers/helper.py::lasagne.layers.helper.count_params PASSED                           [  1%]
lasagne/layers/helper.py::lasagne.layers.helper.get_all_layers PASSED                         [  3%]
lasagne/layers/helper.py::lasagne.layers.helper.get_all_param_values PASSED                   [  5%]
lasagne/layers/helper.py::lasagne.layers.helper.get_all_params PASSED                         [  7%]
lasagne/layers/helper.py::lasagne.layers.helper.set_all_param_values PASSED                   [  8%]
lasagne/tests/layers/test_helper.py::TestGetAllLayers::test_stack PASSED                      [ 10%]
lasagne/tests/layers/test_helper.py::TestGetAllLayers::test_merge PASSED                      [ 12%]
lasagne/tests/layers/test_helper.py::TestGetAllLayers::test_split PASSED                      [ 14%]
lasagne/tests/layers/test_helper.py::TestGetAllLayers::test_bridge PASSED                     [ 16%]
lasagne/tests/layers/test_helper.py::TestGetOutput_InputLayer::test_get_output_without_arguments PASSED [ 17%]
lasagne/tests/layers/test_helper.py::TestGetOutput_InputLayer::test_get_output_input_is_variable PASSED [ 19%]
lasagne/tests/layers/test_helper.py::TestGetOutput_InputLayer::test_get_output_input_is_array PASSED [ 21%]
lasagne/tests/layers/test_helper.py::TestGetOutput_InputLayer::test_get_output_input_is_a_mapping PASSED [ 23%]
lasagne/tests/layers/test_helper.py::TestGetOutput_Layer::test_get_output_without_arguments PASSED [ 25%]
lasagne/tests/layers/test_helper.py::TestGetOutput_Layer::test_get_output_with_single_argument PASSED [ 26%]
lasagne/tests/layers/test_helper.py::TestGetOutput_Layer::test_get_output_input_is_a_mapping PASSED [ 28%]
lasagne/tests/layers/test_helper.py::TestGetOutput_Layer::test_get_output_input_is_a_mapping_no_key PASSED [ 30%]
lasagne/tests/layers/test_helper.py::TestGetOutput_Layer::test_get_output_input_is_a_mapping_to_array PASSED [ 32%]
lasagne/tests/layer/test_helper.py::TestGetOutput_Layer::test_get_output_input_is_a_mapping_for_layer PASSED [ 33%]lasagne/tests/layers/test_helper.py::TestGetOutput_Layer::test_get_output_input_is_a_mapping_for_input_layer PASSED [ 35%]
lasagne/tests/layers/test_helper.py::TestGetOutput_Layer::test_get_output_with_unused_kwarg PASSED [ 37%]
lasagne/tests/layers/test_helper.py::TestGetOutput_Layer::test_get_output_with_no_unused_kwarg PASSED [ 39%]
lasagne/tests/layers/test_helper.py::TestGetOutput_Layer::test_layer_from_shape_invalid_get_output PASSED [ 41%]
lasagne/tests/layers/test_helper.py::TestGetOutput_Layer::test_layer_from_shape_valid_get_output PASSED [ 42%]
lasagne/tests/layers/test_helper.py::TestGetOutput_MergeLayer::test_get_output_without_arguments ERROR [ 44%]

============================================== ERRORS ===============================================
___________ ERROR at setup of TestGetOutput_MergeLayer.test_get_output_without_arguments ____________

self = <test_helper.TestGetOutput_MergeLayer object at 0x7f27f7479a30>
  
    @pytest.fixture
    def layers(self):
        from lasagne.layers.base import Layer, MergeLayer
        from lasagne.layers.input import InputLayer
        # create two mocks of the same attributes as an InputLayer instance
        l1 = [Mock(InputLayer((None,)), output_shape=(None,),
                   get_output_kwargs=[]),
              Mock(InputLayer((None,)), output_shape=(None,),
                   get_output_kwargs=[])]
        # create two mocks of the same attributes as a Layer instance
        l2 = [Mock(Layer(l1[0]), output_shape=(None,),
                   get_output_kwargs=[]),
              Mock(Layer(l1[1]), output_shape=(None,),
                   get_output_kwargs=[])]
        # link them to the InputLayer mocks
        l2[0].input_layer = l1[0]
        l2[1].input_layer = l1[1]
        # create a mock that has the same attributes as a MergeLayer
>       l3 = Mock(MergeLayer(l2), get_output_kwargs=['kwarg'])
  
lasagne/tests/layers/test_helper.py:306:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
/usr/lib/python3/dist-packages/mock/mock.py:1082: in __init__
    _safe_super(CallableMixin, self).__init__(
/usr/lib/python3/dist-packages/mock/mock.py:439: in __init__
    self._mock_add_spec(spec, spec_set, _spec_as_instance, _eat_self)
/usr/lib/python3/dist-packages/mock/mock.py:494: in _mock_add_spec
    if iscoroutinefunction(getattr(spec, attr, None)):
lasagne/layers/base.py:269: in output_shape
    shape = self.get_output_shape_for(self.input_shapes)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
  
self = <lasagne.layers.base.MergeLayer object at 0x7f27f7479c70>, input_shapes = [(None,), (None,)]
  
    def get_output_shape_for(self, input_shapes):
        """
        Computes the output shape of this layer, given a list of input shapes.
    
        Parameters
        ----------
        input_shape : list of tuple
            A list of tuples, with each tuple representing the shape of one of
            the inputs (in the correct order). These tuples should have as many
            elements as there are input dimensions, and the elements should be
            integers or `None`.
    
        Returns
        -------
        tuple
            A tuple representing the shape of the output of this layer. The
            tuple has as many elements as there are output dimensions, and the
            elements are all either integers or `None`.
    
        Notes
        -----
        This method must be overridden when implementing a new
        :class:`Layer` class with multiple inputs. By default it raises
        `NotImplementedError`.
        """
>       raise NotImplementedError
E       NotImplementedError
  
lasagne/layers/base.py:303: NotImplementedError
...
@radarsat1
Copy link
Author

(By the way it is easy to test using docker run --rm -it debian:unstable and then installing python, git etc. and then simply running pytest.)

@radarsat1
Copy link
Author

Some more information: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=962938

@eamanu
Copy link

eamanu commented Jan 2, 2021

Also for 3.9 https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=972910

@radarsat1 Could you edit the title for 3.8 and 3.9 if I'm not wrong, please?

@f0k f0k changed the title Error with mock in Python 3.8.3 Error with mock in Python 3.8.3 and 3.9 Jan 21, 2021
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

No branches or pull requests

2 participants