Completed
Pull Request — master (#15)
by
unknown
03:40 queued 01:13
created

test_manager_with_no_routes()   A

Complexity

Conditions 2

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
c 1
b 0
f 0
dl 0
loc 3
rs 10
1
# -*- coding: utf-8 -*-
2
# vi:si:et:sw=4:sts=4:ts=4
3
4
import asyncio
5
from unittest import mock
6
7
import pytest
8
9
from loafer.exceptions import ConfigurationError, ConsumerError
10
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 36))

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...
11
from loafer.manager import LoaferManager
12
from loafer.route import Route
0 ignored issues
show
Bug introduced by
The name route does not seem to exist in module loafer.
Loading history...
Configuration introduced by
Unable to import 'loafer.route' (invalid syntax (<string>, line 26))

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...
13
14
from loafer.aws.consumer import Consumer as AWSConsumer
0 ignored issues
show
Bug introduced by
The name consumer does not seem to exist in module loafer.aws.
Loading history...
Configuration introduced by
Unable to import 'loafer.aws.consumer' (invalid syntax (<string>, line 29))

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...
15
16
17
def test_manager_with_no_routes(event_loop):
18
    manager = LoaferManager('test-queue', event_loop=event_loop)
19
    assert len(manager.routes) == 0
20
21
22
def test_manager_one_route(event_loop):
23
    route = Route('test-queue', lambda x: None)
24
    manager = LoaferManager('test-queue', event_loop=event_loop)
25
    manager.routes.append(route)
26
27
    assert len(manager.routes) == 1
28
29
30
def test_routes_stop_manager_if_loop_is_running(event_loop):
0 ignored issues
show
Coding Style Naming introduced by
The name test_routes_stop_manager_if_loop_is_running 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
    manager = LoaferManager('test-queue', event_loop=event_loop)
32
    manager.stop = mock.Mock()
33
34
    with mock.patch.object(event_loop, 'is_running', return_value=True):
35
        with pytest.raises(ConfigurationError):
36
            manager.routes
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...
37
38
        assert manager.stop.called
39
        assert manager.stop.called_once_with()
40
41
42
def test_consumers(event_loop):
43
    manager = LoaferManager('test-queue', event_loop=event_loop)
44
    assert manager.consumers
45
    assert len(manager.consumers) == 1
46
47
48
def test_consumers_returns_default_if_not_manually_set(event_loop):
0 ignored issues
show
Coding Style Naming introduced by
The name test_consumers_returns_default_if_not_manually_set 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...
49
    manager = LoaferManager('test-queue', event_loop=event_loop)
50
    assert manager.consumers[0].__class__ == AWSConsumer
51
52
53
def test_dispatcher(event_loop):
54
    manager = LoaferManager('test-queue', event_loop=event_loop)
55
    manager.get_dispatcher()
56
    assert manager._dispatcher
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like _dispatcher 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...
57
    assert isinstance(manager._dispatcher, LoaferDispatcher)
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like _dispatcher 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...
58
59
60
def test_on_future_errors(event_loop):
61
    manager = LoaferManager('test-queue', event_loop=event_loop)
62
    manager.stop = mock.Mock()
63
    future = asyncio.Future()
64
    future.set_exception(ConsumerError)
65
    manager.on_future__errors(future)
66
67
    assert manager.stop.called
68
    assert manager.stop.called_once_with()
69