Test Failed
Push — master ( 9e4203...5a4935 )
by George
01:43
created

dummy_route()   A

Complexity

Conditions 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

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

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...
7
from loafer.exceptions import ProviderError, ConfigurationError
8
from loafer.managers import LoaferManager
9
from loafer.routes import Route
0 ignored issues
show
Bug introduced by
The name routes does not seem to exist in module loafer.
Loading history...
Configuration introduced by
Unable to import 'loafer.routes' (invalid syntax (<string>, line 55))

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...
10
from loafer.runners import LoaferRunner
11
12
13
@pytest.fixture
14
def dummy_route(dummy_provider):
15
    return Route(dummy_provider, handler=mock.Mock())
16
17
18
def test_dispatcher_invalid_routes():
19
    manager = LoaferManager(routes=[])
20
    with pytest.raises(ConfigurationError):
21
        manager.dispatcher
0 ignored issues
show
Unused Code introduced by
This statement seems to have no effect and could be removed.

This issue is typically triggered when a function that does not have side-effects is called and the return value is discarded:

class SomeClass:
    def __init__(self):
        self._x = 5

    def squared(self):
        return self._x * self._x

some_class = SomeClass()
some_class.squared()        # Flagged, as the return value is not used
print(some_class.squared()) # Ok
Loading history...
22
23
24
def test_dispatcher_invalid_route_instance():
0 ignored issues
show
Coding Style Naming introduced by
The name test_dispatcher_invalid_route_instance does not conform to the function naming conventions ([a-z_][a-z0-9_]{2,30}$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
25
    manager = LoaferManager(routes=[mock.Mock()])
26
    with pytest.raises(ConfigurationError):
27
        manager.dispatcher
0 ignored issues
show
Unused Code introduced by
This statement seems to have no effect and could be removed.

This issue is typically triggered when a function that does not have side-effects is called and the return value is discarded:

class SomeClass:
    def __init__(self):
        self._x = 5

    def squared(self):
        return self._x * self._x

some_class = SomeClass()
some_class.squared()        # Flagged, as the return value is not used
print(some_class.squared()) # Ok
Loading history...
28
29
30
def test_dispatcher(dummy_route):
31
    manager = LoaferManager(routes=[dummy_route])
32
    assert manager.dispatcher
33
    assert isinstance(manager.dispatcher, LoaferDispatcher)
34
35
36
def test_default_runner():
37
    manager = LoaferManager(routes=[])
38
    assert manager.runner
39
    assert isinstance(manager.runner, LoaferRunner)
40
41
42
def test_custom_runner():
43
    runner = mock.Mock()
44
    manager = LoaferManager(routes=[], runner=runner)
45
    assert manager.runner
46
    assert isinstance(manager.runner, mock.Mock)
47
48
49
def test_on_future_errors():
50
    manager = LoaferManager(routes=[])
51
    manager.runner = mock.Mock()
52
    future = asyncio.Future()
53
    future.set_exception(ProviderError)
54
    manager.on_future__errors(future)
55
56
    assert manager.runner.stop.called
57
    assert manager.runner.stop.called_once_with()
58
59
60
def test_on_loop__stop():
61
    manager = LoaferManager(routes=[])
62
    manager.dispatcher = mock.Mock()
63
    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...
64
    manager.on_loop__stop()
65
66
    assert manager.dispatcher.stop.called
67
    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...
68