Completed
Push — master ( ce49da...e52943 )
by George
02:14
created

test_default_runner()   A

Complexity

Conditions 3

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
c 1
b 0
f 0
dl 0
loc 4
rs 10
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 31))

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
    manager = LoaferManager(routes=[])
12
    assert manager.dispatcher
13
    assert isinstance(manager.dispatcher, LoaferDispatcher)
14
15
16
def test_default_runner():
17
    manager = LoaferManager(routes=[])
18
    assert manager.runner
19
    assert isinstance(manager.runner, LoaferRunner)
20
21
22
def test_custom_runner():
23
    runner = mock.Mock()
24
    manager = LoaferManager(routes=[], runner=runner)
25
    assert manager.runner
26
    assert isinstance(manager.runner, mock.Mock)
27
28
29
def test_on_future_errors():
30
    manager = LoaferManager(routes=[])
31
    manager.runner = mock.Mock()
32
    future = asyncio.Future()
33
    future.set_exception(ProviderError)
34
    manager.on_future__errors(future)
35
36
    assert manager.runner.stop.called
37
    assert manager.runner.stop.called_once_with()
38
39
40
def test_on_loop__stop():
41
    manager = LoaferManager(routes=[])
42
    manager.dispatcher = mock.Mock()
43
    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...
44
    manager.on_loop__stop()
45
46
    assert manager.dispatcher.stop_providers.called
47
    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...
48