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 ( e04e53...67d2ce )
by Michael
01:27
created

add_connected_players()   A

Complexity

Conditions 2

Size

Total Lines 12

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 12
rs 9.4285
1
from unittest import mock
2
import pytest
3
4
from server import GameStatsService, LobbyConnection
5
from server.games import Game
6
from server.gameconnection import GameConnection, GameConnectionState
0 ignored issues
show
Bug introduced by
The name gameconnection does not seem to exist in module server.
Loading history...
Configuration introduced by
Unable to import 'server.gameconnection' (invalid syntax (<string>, line 94))

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 tests import CoroMock
8
9
@pytest.fixture()
10
def lobbythread():
11
    return mock.Mock(
12
        sendJSON=lambda obj: None
13
    )
14
15 View Code Duplication
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
16
@pytest.fixture
17
def game_connection(request, game, loop, player_service, players, game_service, transport):
18
    from server import GameConnection, LobbyConnection
0 ignored issues
show
Comprehensibility Bug introduced by
LobbyConnection is re-defining a name which is already available in the outer-scope (previously defined on line 4).

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 import LobbyConnection was already done on line 4. You should be able to
remove this line.
Loading history...
Comprehensibility Bug introduced by
GameConnection is re-defining a name which is already available in the outer-scope (previously defined on line 6).

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...
19
    conn = GameConnection(loop=loop,
20
                          lobby_connection=mock.create_autospec(LobbyConnection(loop)),
21
                          player_service=player_service,
22
                          games=game_service)
23
    conn._transport = transport
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like _transport 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...
24
    conn.player = players.hosting
25
    conn.game = game
26
    conn.lobby = mock.Mock(spec=LobbyConnection)
27
28
    def fin():
29
        conn.abort()
30
31
    request.addfinalizer(fin)
32
    return conn
33
34 View Code Duplication
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
35
@pytest.fixture
36
def mock_game_connection(state=GameConnectionState.INITIALIZING, player=None):
37
    gc = mock.create_autospec(spec=GameConnection)
38
    gc.state = state
39
    gc.player = player
40
    return gc
41
42
43
@pytest.fixture()
44
def game_stats_service():
45
    service = mock.Mock(spec=GameStatsService)
46
    service.process_game_stats = CoroMock()
47
    return service
48
49
50
@pytest.fixture
51
def connections(loop, player_service, game_service, transport, game):
52
    from server import GameConnection
0 ignored issues
show
Comprehensibility Bug introduced by
GameConnection is re-defining a name which is already available in the outer-scope (previously defined on line 6).

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...
53
54
    def make_connection(player, connectivity):
55
        lc = LobbyConnection(loop)
56
        lc.protocol = mock.Mock()
57
        conn = GameConnection(loop=loop,
58
                              lobby_connection=lc,
59
                              player_service=player_service,
60
                              games=game_service)
61
        conn.player = player
62
        conn.game = game
63
        conn._transport = transport
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like _transport 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
        conn._connectivity_state.set_result(connectivity)
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like _connectivity_state 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...
65
        return conn
66
67
    return mock.Mock(
68
        make_connection=make_connection
69
    )
70
71
def add_connected_player(game: Game, player):
72
    game.game_service.player_service[player.id] = player
73
    gc = mock_game_connection(state=GameConnectionState.CONNECTED_TO_HOST, player=player)
74
    game.set_player_option(player.id, 'Army', 0)
75
    game.set_player_option(player.id, 'StartSpot', 0)
76
    game.set_player_option(player.id, 'Team', 0)
77
    game.set_player_option(player.id, 'Faction', 0)
78
    game.set_player_option(player.id, 'Color', 0)
79
    game.add_game_connection(gc)
80
    return gc
81
82
83
def add_connected_players(game: Game, players):
84
    """
85
    Utility to add players with army and StartSpot indexed by a list
86
    """
87
    for army, player in enumerate(players):
88
        add_connected_player(game, player)
89
        game.set_player_option(player.id, 'Army', army)
90
        game.set_player_option(player.id, 'StartSpot', army)
91
        game.set_player_option(player.id, 'Team', army)
92
        game.set_player_option(player.id, 'Faction', 0)
93
        game.set_player_option(player.id, 'Color', 0)
94
    game.host = players[0]
95
96