Completed
Push — master ( dc3db7...c94c8e )
by George
02:13
created

test_on_future_errors()   A

Complexity

Conditions 3

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
cc 3
c 3
b 0
f 0
dl 0
loc 9
rs 9.6666
1
import asyncio
2
from unittest import mock
3
4
from loafer.dispatcher import LoaferDispatcher
0 ignored issues
show
Bug introduced by
The name dispatcher does not seem to exist in module loafer.
Loading history...
Configuration introduced by
Unable to import 'loafer.dispatcher' (invalid syntax (<string>, line 41))

This can be caused by one of the following:

1. Missing Dependencies

This error could indicate a configuration issue of Pylint. Make sure that your libraries are available by adding the necessary commands.

# .scrutinizer.yml
before_commands:
    - sudo pip install abc # Python2
    - sudo pip3 install abc # Python3
Tip: We are currently not using virtualenv to run pylint, when installing your modules make sure to use the command for the correct version.

2. Missing __init__.py files

This error could also result from missing __init__.py files in your module folders. Make sure that you place one file in each sub-folder.

Loading history...
5
from loafer.exceptions import ProviderError
6
from loafer.managers import LoaferManager
7
from loafer.runners import LoaferRunner
8
9
10
def test_dispatcher():
11
    runner = LoaferRunner(loop=mock.Mock())
12
    manager = LoaferManager(routes=[], consumers=[], runner=runner)
13
    assert manager.dispatcher
14
    assert isinstance(manager.dispatcher, LoaferDispatcher)
15
16
17
def test_on_future_errors():
18
    manager = LoaferManager(routes=[], consumers=[])
19
    manager.runner = mock.Mock()
20
    future = asyncio.Future()
21
    future.set_exception(ProviderError)
22
    manager.on_future__errors(future)
23
24
    assert manager.runner.stop.called
25
    assert manager.runner.stop.called_once_with()
26
27
28
def test_on_loop__stop():
29
    manager = LoaferManager(routes=[], consumers=[])
30
    manager.dispatcher = mock.Mock()
31
    manager._future = mock.Mock()
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like _future was declared protected and should not be accessed from this context.

Prefixing a member variable _ is usually regarded as the equivalent of declaring it with protected visibility that exists in other languages. Consequentially, such a member should only be accessed from the same class or a child class:

class MyParent:
    def __init__(self):
        self._x = 1;
        self.y = 2;

class MyChild(MyParent):
    def some_method(self):
        return self._x    # Ok, since accessed from a child class

class AnotherClass:
    def some_method(self, instance_of_my_child):
        return instance_of_my_child._x   # Would be flagged as AnotherClass is not
                                         # a child class of MyParent
Loading history...
32
    manager.on_loop__stop()
33
34
    assert manager.dispatcher.stop_providers.called
35
    assert manager._future.cancel.called
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like _future was declared protected and should not be accessed from this context.

Prefixing a member variable _ is usually regarded as the equivalent of declaring it with protected visibility that exists in other languages. Consequentially, such a member should only be accessed from the same class or a child class:

class MyParent:
    def __init__(self):
        self._x = 1;
        self.y = 2;

class MyChild(MyParent):
    def some_method(self):
        return self._x    # Ok, since accessed from a child class

class AnotherClass:
    def some_method(self, instance_of_my_child):
        return instance_of_my_child._x   # Would be flagged as AnotherClass is not
                                         # a child class of MyParent
Loading history...
36