Passed
Push — master ( d3d957...12fe94 )
by George
01:20
created

test_dispatcher_without_enabled_routes()   A

Complexity

Conditions 2

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
c 0
b 0
f 0
dl 0
loc 5
rs 9.4285
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 17))

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 56))

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_without_enabled_routes(dummy_route):
0 ignored issues
show
Coding Style Naming introduced by
The name test_dispatcher_without_enabled_routes 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...
31
    dummy_route.enabled = False
32
    manager = LoaferManager(routes=[dummy_route])
33
    with pytest.raises(ConfigurationError):
34
        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...
35
36
37
def test_dispatcher(dummy_route):
38
    manager = LoaferManager(routes=[dummy_route])
39
    assert manager.dispatcher
40
    assert isinstance(manager.dispatcher, LoaferDispatcher)
41
42
43
def test_default_runner():
44
    manager = LoaferManager(routes=[])
45
    assert manager.runner
46
    assert isinstance(manager.runner, LoaferRunner)
47
48
49
def test_custom_runner():
50
    runner = mock.Mock()
51
    manager = LoaferManager(routes=[], runner=runner)
52
    assert manager.runner
53
    assert isinstance(manager.runner, mock.Mock)
54
55
56
def test_on_future_errors():
57
    manager = LoaferManager(routes=[])
58
    manager.runner = mock.Mock()
59
    future = asyncio.Future()
60
    future.set_exception(ProviderError)
61
    manager.on_future__errors(future)
62
63
    assert manager.runner.stop.called
64
    assert manager.runner.stop.called_once_with()
65
66
67
def test_on_loop__stop():
68
    manager = LoaferManager(routes=[])
69
    manager.dispatcher = mock.Mock()
70
    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...
71
    manager.on_loop__stop()
72
73
    assert manager.dispatcher.stop.called
74
    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...
75