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 — master ( 0254c9...47ea54 )
by
unknown
01:26
created

sqlquery()   B

Complexity

Conditions 5

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
dl 0
loc 9
rs 8.5454
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
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
    @asyncio.coroutine
125
    def setup():
126
        cmd = 'SET default_storage_engine=MEMORY; drop database if exists {}; create database {}; use {}; source {};'.format(db, db, db, 'db/db-structure.sql')
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (159/120).

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

Loading history...
127
        try:
128
            subprocess.check_output(['mysql',
129
                                     '-h{}'.format(host),
130
                                     '-u{}'.format(user),
131
                                     '-p{}'.format(pw) if pw else '', '-e {}'.format(cmd)],
132
                                    stderr=subprocess.STDOUT)
133
            subprocess.check_call(['mysql',
134
                                   '-h{}'.format(host),
135
                                   '-u{}'.format(user),
136
                                   '-p{}'.format(pw) if pw else '',
137
                                   '-e use {}; source {};'.format(db, 'tests/data/db-fixtures.sql')],
138
                                  stderr=subprocess.STDOUT)
139
        except subprocess.CalledProcessError as e:
140
            raise Exception('SQL error: {} (cmd: {})'.format(e.output, e.cmd), e)
141
142
143
    def fin():
144
        pool.close()
145
        loop.run_until_complete(pool.wait_closed())
146
    request.addfinalizer(fin)
147
148
    loop.run_until_complete(setup())
149
150
    return pool
151
152
@pytest.fixture
153
def transport():
154
    return mock.Mock(spec=asyncio.Transport)
155
156
@pytest.fixture
157
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 188).

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...
158
    from server.games import Game
159
    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...
160
    mock_parent = mock.Mock()
161
    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 157).

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...
162
    players.hosting.getGame = mock.Mock(return_value=game)
163
    players.joining.getGame = mock.Mock(return_value=game)
164
    players.peer.getGame = mock.Mock(return_value=game)
165
    game.hostPlayer = players.hosting
166
    game.init_mode = InitMode.NORMAL_LOBBY
167
    game.name = "Some game name"
168
    game.id = 1
169
    return game
170
171
@pytest.fixture
172
def create_player():
173
    from server.players import Player, PlayerState
174
    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
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...
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...
175
        p = mock.create_autospec(spec=Player(login))
176
        p.global_rating = global_rating
177
        p.ladder_rating = ladder_rating
178
        p.ip = ip
179
        p.game_port = port
180
        p.state = state
181
        p.id = id
182
        p.login = login
183
        p.address_and_port = "{}:{}".format(ip, port)
184
        return p
185
    return make
186
187
@pytest.fixture
188
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 172).

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...
189
    from server.players import PlayerState
190
    return mock.Mock(
191
        hosting=create_player(login='Paula_Bean', id=1, port=6112, state=PlayerState.HOSTING),
192
        peer=create_player(login='That_Guy', id=2, port=6112, state=PlayerState.JOINING),
193
        joining=create_player(login='James_Kirk', id=3, port=6112, state=PlayerState.JOINING)
194
    )
195
196
@pytest.fixture
197
def player_service(loop, players, db_pool):
0 ignored issues
show
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...
Comprehensibility Bug introduced by
players is re-defining a name which is already available in the outer-scope (previously defined on line 188).

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
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...
198
    from server import PlayerService
199
    return PlayerService(db_pool)
200
201
@pytest.fixture
202
def game_service(loop, player_service, game_stats_service):
0 ignored issues
show
Unused Code introduced by
The argument loop seems to be unused.
Loading history...
Comprehensibility Bug introduced by
game_stats_service is re-defining a name which is already available in the outer-scope (previously defined on line 222).

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 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
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...
203
    from server import GameService
204
    return GameService(player_service, game_stats_service)
205
206
@pytest.fixture
207
def api_accessor():
208
    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...
209
    return ApiAccessor()
210
211
@pytest.fixture
212
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 207).

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...
213
    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...
214
    return EventService(api_accessor)
215
216
@pytest.fixture
217
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 207).

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

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
achievement_service is re-defining a name which is already available in the outer-scope (previously defined on line 217).

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...
223
    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...
224
    return GameStatsService(event_service, achievement_service)
225