GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — develop ( ab6579...087080 )
by Michael
01:35
created

opt()   A

Complexity

Conditions 1

Size

Total Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
dl 0
loc 2
rs 10
c 0
b 0
f 0
1
"""
2
This module is the 'top level' configuration for all the unit tests.
3
4
'Real world' fixtures are put here.
5
If a test suite needs specific mocked versions of dependencies,
6
these should be put in the ``conftest.py'' relative to it.
7
"""
8
9
import asyncio
10
11
import logging
12
import subprocess
0 ignored issues
show
Unused Code introduced by
The import subprocess seems to be unused.
Loading history...
13
import sys
0 ignored issues
show
Unused Code introduced by
The import sys seems to be unused.
Loading history...
14
from server.config import DB_SERVER, DB_LOGIN, DB_PORT, DB_PASSWORD
15
16
import pytest
17
from unittest import mock
18
from trueskill import Rating
0 ignored issues
show
Configuration introduced by
The import trueskill could not be resolved.

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...
19
20
logging.getLogger().setLevel(logging.DEBUG)
21
22
import os
0 ignored issues
show
Unused Code introduced by
The import os seems to be unused.
Loading history...
23
24
25
def async_test(f):
26
    def wrapper(*args, **kwargs):
27
        coro = asyncio.coroutine(f)
28
        future = coro(*args, **kwargs)
29
        loop = asyncio.get_event_loop()
0 ignored issues
show
Comprehensibility Bug introduced by
loop is re-defining a name which is already available in the outer-scope (previously defined on line 90).

It is generally a bad practice to shadow variables from the outer-scope. In most cases, this is done unintentionally and might lead to unexpected behavior:

param = 5

class Foo:
    def __init__(self, param):   # "param" would be flagged here
        self.param = param
Loading history...
30
        loop.run_until_complete(future)
31
    return wrapper
32
33
34
def pytest_pycollect_makeitem(collector, name, obj):
35
    if name.startswith('test_') and asyncio.iscoroutinefunction(obj):
36
        return list(collector._genfunctions(name, obj))
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like _genfunctions 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...
37
38
39
def pytest_addoption(parser):
40
    parser.addoption('--noslow', action='store_true', default=False,
41
                     help="Don't run slow tests")
42
    parser.addoption('--aiodebug', action='store_true', default=False,
43
                     help='Enable asyncio debugging')
44
    parser.addoption('--mysql_host', action='store', default=DB_SERVER, help='mysql host to use for test database')
45
    parser.addoption('--mysql_username', action='store', default=DB_LOGIN, help='mysql username to use for test database')
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (122/120).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
46
    parser.addoption('--mysql_password', action='store', default=DB_PASSWORD, help='mysql password to use for test database')
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (125/120).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
47
    parser.addoption('--mysql_database', action='store', default='faf_test', help='mysql database to use for tests')
48
    parser.addoption('--mysql_port',     action='store', default=int(DB_PORT), help='mysql port to use for tests')
49
50
51
def pytest_configure(config):
52
    if config.getoption('--aiodebug'):
53
        logging.getLogger('quamash').setLevel(logging.DEBUG)
54
        logging.captureWarnings(True)
55
    else:
56
        logging.getLogger('quamash').setLevel(logging.INFO)
57
58
59
def pytest_runtest_setup(item):
60
    """
61
    Skip tests if they are marked slow, and --noslow is given on the commandline
62
    :param item:
63
    :return:
64
    """
65
    if getattr(item.obj, 'slow', None) and item.config.getvalue('noslow'):
66
        pytest.skip("slow test")
67
68
def pytest_pyfunc_call(pyfuncitem):
69
    testfn = pyfuncitem.obj
70
71
    if not asyncio.iscoroutinefunction(testfn):
72
        return
73
74
    funcargs = pyfuncitem.funcargs
75
    testargs = {}
76
    for arg in pyfuncitem._fixtureinfo.argnames:
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like _fixtureinfo 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...
77
        testargs[arg] = funcargs[arg]
78
    loop = testargs.get('loop', asyncio.get_event_loop())
0 ignored issues
show
Comprehensibility Bug introduced by
loop is re-defining a name which is already available in the outer-scope (previously defined on line 90).

It is generally a bad practice to shadow variables from the outer-scope. In most cases, this is done unintentionally and might lead to unexpected behavior:

param = 5

class Foo:
    def __init__(self, param):   # "param" would be flagged here
        self.param = param
Loading history...
79
    loop.set_debug(True)
80
    coro = asyncio.wait_for(testfn(**testargs), 5)
81
82
    try:
83
        loop.run_until_complete(coro)
84
    except RuntimeError as err:
85
        logging.error(err)
86
        raise err
87
    return True
88
89
@pytest.fixture(scope='session', autouse=True)
90
def loop(request):
0 ignored issues
show
Unused Code introduced by
The argument request seems to be unused.
Loading history...
91
    import server
92
    server.stats = mock.MagicMock()
93
    return asyncio.get_event_loop()
94
95
@pytest.fixture
96
def sqlquery():
97
    query = mock.MagicMock()
98
    query.exec_ = lambda: 0
99
    query.size = lambda: 0
100
    query.lastInsertId = lambda: 1
101
    query.prepare = mock.MagicMock()
102
    query.addBindValue = lambda v: None
103
    return query
104
105
@pytest.fixture
106
def mock_db_pool(loop, db_pool, autouse=True):
0 ignored issues
show
Unused Code introduced by
The argument autouse seems to be unused.
Loading history...
Unused Code introduced by
The argument loop seems to be unused.
Loading history...
Comprehensibility Bug introduced by
db_pool is re-defining a name which is already available in the outer-scope (previously defined on line 110).

It is generally a bad practice to shadow variables from the outer-scope. In most cases, this is done unintentionally and might lead to unexpected behavior:

param = 5

class Foo:
    def __init__(self, param):   # "param" would be flagged here
        self.param = param
Loading history...
Comprehensibility Bug introduced by
loop is re-defining a name which is already available in the outer-scope (previously defined on line 90).

It is generally a bad practice to shadow variables from the outer-scope. In most cases, this is done unintentionally and might lead to unexpected behavior:

param = 5

class Foo:
    def __init__(self, param):   # "param" would be flagged here
        self.param = param
Loading history...
107
    return db_pool
108
109
@pytest.fixture(scope='session')
110
def db_pool(request, loop):
0 ignored issues
show
Comprehensibility Bug introduced by
loop is re-defining a name which is already available in the outer-scope (previously defined on line 90).

It is generally a bad practice to shadow variables from the outer-scope. In most cases, this is done unintentionally and might lead to unexpected behavior:

param = 5

class Foo:
    def __init__(self, param):   # "param" would be flagged here
        self.param = param
Loading history...
111
    import server
112
113
    def opt(val):
114
        return request.config.getoption(val)
115
    host, user, pw, db, port = opt('--mysql_host'), opt('--mysql_username'), opt('--mysql_password'), opt('--mysql_database'), opt('--mysql_port')
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (146/120).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
116
    pool_fut = asyncio.async(server.db.connect(loop=loop,
117
                                               host=host,
118
                                               user=user,
119
                                               password=pw or None,
120
                                               port=port,
121
                                               db=db))
122
    pool = loop.run_until_complete(pool_fut)
123
124
125
    def fin():
126
        pool.close()
127
        loop.run_until_complete(pool.wait_closed())
128
    request.addfinalizer(fin)
129
130
    return pool
131
132
@pytest.fixture
133
def transport():
134
    return mock.Mock(spec=asyncio.Transport)
135
136
@pytest.fixture
137
def game(players):
0 ignored issues
show
Comprehensibility Bug introduced by
players is re-defining a name which is already available in the outer-scope (previously defined on line 168).

It is generally a bad practice to shadow variables from the outer-scope. In most cases, this is done unintentionally and might lead to unexpected behavior:

param = 5

class Foo:
    def __init__(self, param):   # "param" would be flagged here
        self.param = param
Loading history...
138
    from server.games import Game
139
    from server.abc.base_game import InitMode
0 ignored issues
show
Bug introduced by
The name abc does not seem to exist in module server.
Loading history...
Configuration introduced by
The import server.abc.base_game could not be resolved.

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...
140
    mock_parent = mock.Mock()
141
    game = mock.create_autospec(spec=Game(1, mock_parent, mock.Mock()))
0 ignored issues
show
Comprehensibility Bug introduced by
game is re-defining a name which is already available in the outer-scope (previously defined on line 137).

It is generally a bad practice to shadow variables from the outer-scope. In most cases, this is done unintentionally and might lead to unexpected behavior:

param = 5

class Foo:
    def __init__(self, param):   # "param" would be flagged here
        self.param = param
Loading history...
142
    players.hosting.getGame = mock.Mock(return_value=game)
143
    players.joining.getGame = mock.Mock(return_value=game)
144
    players.peer.getGame = mock.Mock(return_value=game)
145
    game.hostPlayer = players.hosting
146
    game.init_mode = InitMode.NORMAL_LOBBY
147
    game.name = "Some game name"
148
    game.id = 1
149
    return game
150
151
@pytest.fixture
152
def create_player():
153
    from server.players import Player, PlayerState
154
    def make(login='', id=0, port=6112, state=PlayerState.HOSTING, ip='127.0.0.1', global_rating=Rating(1500, 250), ladder_rating=Rating(1500, 250)):
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (149/120).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
Bug Best Practice introduced by
This seems to re-define the built-in id.

It is generally discouraged to redefine built-ins as this makes code very hard to read.

Loading history...
155
        p = mock.create_autospec(spec=Player(login))
156
        p.global_rating = global_rating
157
        p.ladder_rating = ladder_rating
158
        p.ip = ip
159
        p.game_port = port
160
        p.state = state
161
        p.id = id
162
        p.login = login
163
        p.address_and_port = "{}:{}".format(ip, port)
164
        return p
165
    return make
166
167
@pytest.fixture
168
def players(create_player):
0 ignored issues
show
Comprehensibility Bug introduced by
create_player is re-defining a name which is already available in the outer-scope (previously defined on line 152).

It is generally a bad practice to shadow variables from the outer-scope. In most cases, this is done unintentionally and might lead to unexpected behavior:

param = 5

class Foo:
    def __init__(self, param):   # "param" would be flagged here
        self.param = param
Loading history...
169
    from server.players import PlayerState
170
    return mock.Mock(
171
        hosting=create_player(login='Paula_Bean', id=1, port=6112, state=PlayerState.HOSTING),
172
        peer=create_player(login='That_Guy', id=2, port=6112, state=PlayerState.JOINING),
173
        joining=create_player(login='James_Kirk', id=3, port=6112, state=PlayerState.JOINING)
174
    )
175
176
@pytest.fixture
177
def player_service(loop, players, db_pool):
0 ignored issues
show
Comprehensibility Bug introduced by
db_pool is re-defining a name which is already available in the outer-scope (previously defined on line 110).

It is generally a bad practice to shadow variables from the outer-scope. In most cases, this is done unintentionally and might lead to unexpected behavior:

param = 5

class Foo:
    def __init__(self, param):   # "param" would be flagged here
        self.param = param
Loading history...
Comprehensibility Bug introduced by
players is re-defining a name which is already available in the outer-scope (previously defined on line 168).

It is generally a bad practice to shadow variables from the outer-scope. In most cases, this is done unintentionally and might lead to unexpected behavior:

param = 5

class Foo:
    def __init__(self, param):   # "param" would be flagged here
        self.param = param
Loading history...
Comprehensibility Bug introduced by
loop is re-defining a name which is already available in the outer-scope (previously defined on line 90).

It is generally a bad practice to shadow variables from the outer-scope. In most cases, this is done unintentionally and might lead to unexpected behavior:

param = 5

class Foo:
    def __init__(self, param):   # "param" would be flagged here
        self.param = param
Loading history...
Unused Code introduced by
The argument loop seems to be unused.
Loading history...
Unused Code introduced by
The argument players seems to be unused.
Loading history...
178
    from server import PlayerService
179
    return PlayerService(db_pool)
180
181
@pytest.fixture
182
def game_service(loop, player_service, game_stats_service):
0 ignored issues
show
Comprehensibility Bug introduced by
game_stats_service is re-defining a name which is already available in the outer-scope (previously defined on line 202).

It is generally a bad practice to shadow variables from the outer-scope. In most cases, this is done unintentionally and might lead to unexpected behavior:

param = 5

class Foo:
    def __init__(self, param):   # "param" would be flagged here
        self.param = param
Loading history...
Comprehensibility Bug introduced by
player_service is re-defining a name which is already available in the outer-scope (previously defined on line 177).

It is generally a bad practice to shadow variables from the outer-scope. In most cases, this is done unintentionally and might lead to unexpected behavior:

param = 5

class Foo:
    def __init__(self, param):   # "param" would be flagged here
        self.param = param
Loading history...
Comprehensibility Bug introduced by
loop is re-defining a name which is already available in the outer-scope (previously defined on line 90).

It is generally a bad practice to shadow variables from the outer-scope. In most cases, this is done unintentionally and might lead to unexpected behavior:

param = 5

class Foo:
    def __init__(self, param):   # "param" would be flagged here
        self.param = param
Loading history...
Unused Code introduced by
The argument loop seems to be unused.
Loading history...
183
    from server import GameService
184
    return GameService(player_service, game_stats_service)
185
186
@pytest.fixture
187
def api_accessor():
188
    from server.api.api_accessor import ApiAccessor
0 ignored issues
show
Bug introduced by
The name api does not seem to exist in module server.
Loading history...
Configuration introduced by
The import server.api.api_accessor could not be resolved.

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...
189
    return ApiAccessor()
190
191
@pytest.fixture
192
def event_service(api_accessor):
0 ignored issues
show
Comprehensibility Bug introduced by
api_accessor is re-defining a name which is already available in the outer-scope (previously defined on line 187).

It is generally a bad practice to shadow variables from the outer-scope. In most cases, this is done unintentionally and might lead to unexpected behavior:

param = 5

class Foo:
    def __init__(self, param):   # "param" would be flagged here
        self.param = param
Loading history...
193
    from server.stats.event_service import EventService
0 ignored issues
show
Configuration introduced by
Unable to import 'server.stats.event_service' (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...
194
    return EventService(api_accessor)
195
196
@pytest.fixture
197
def achievement_service(api_accessor):
0 ignored issues
show
Comprehensibility Bug introduced by
api_accessor is re-defining a name which is already available in the outer-scope (previously defined on line 187).

It is generally a bad practice to shadow variables from the outer-scope. In most cases, this is done unintentionally and might lead to unexpected behavior:

param = 5

class Foo:
    def __init__(self, param):   # "param" would be flagged here
        self.param = param
Loading history...
198
    from server.stats.achievement_service import AchievementService
0 ignored issues
show
Configuration introduced by
Unable to import 'server.stats.achievement_service' (invalid syntax (<string>, line 69))

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...
199
    return AchievementService(api_accessor)
200
201
@pytest.fixture
202
def game_stats_service(event_service, achievement_service):
0 ignored issues
show
Comprehensibility Bug introduced by
achievement_service is re-defining a name which is already available in the outer-scope (previously defined on line 197).

It is generally a bad practice to shadow variables from the outer-scope. In most cases, this is done unintentionally and might lead to unexpected behavior:

param = 5

class Foo:
    def __init__(self, param):   # "param" would be flagged here
        self.param = param
Loading history...
Comprehensibility Bug introduced by
event_service is re-defining a name which is already available in the outer-scope (previously defined on line 192).

It is generally a bad practice to shadow variables from the outer-scope. In most cases, this is done unintentionally and might lead to unexpected behavior:

param = 5

class Foo:
    def __init__(self, param):   # "param" would be flagged here
        self.param = param
Loading history...
203
    from server.stats.game_stats_service import GameStatsService
0 ignored issues
show
Configuration introduced by
Unable to import 'server.stats.game_stats_service' (invalid syntax (<string>, line 15))

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...
204
    return GameStatsService(event_service, achievement_service)
205