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 ( f4c05f...98987e )
by
unknown
01:56
created

add_players()   A

Complexity

Conditions 4

Size

Total Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
c 1
b 0
f 0
dl 0
loc 14
rs 9.2
1
from unittest import mock
2
import pytest
3
4
from server import GameStatsService, LobbyConnection
5
from server.abc.base_game import BaseGame
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...
6
from server.games import Game
7
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...
8
from server.players import Player
9
from tests import CoroMock
10
11
@pytest.fixture()
12
def lobbythread():
13
    return mock.Mock(
14
        sendJSON=lambda obj: None
15
    )
16
17 View Code Duplication
@pytest.fixture
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
18
def game_connection(request, game, loop, player_service, players, game_service, transport):
19
    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 7).

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...
20
    conn = GameConnection(loop=loop,
21
                          lobby_connection=mock.create_autospec(LobbyConnection(loop)),
22
                          player_service=player_service,
23
                          games=game_service)
24
    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...
25
    conn.player = players.hosting
26
    conn.game = game
27
    conn.lobby = mock.Mock(spec=LobbyConnection)
28
29
    def fin():
30
        conn.abort()
31
32
    request.addfinalizer(fin)
33
    return conn
34
35
36
@pytest.fixture
37
def mock_game_connection(state=GameConnectionState.INITIALIZING, player=None):
38
    gc = mock.create_autospec(spec=GameConnection)
39
    gc.state = state
40
    gc.player = player
41
    return gc
42
43
44
@pytest.fixture()
45
def game_stats_service():
46
    service = mock.Mock(spec=GameStatsService)
47
    service.process_game_stats = CoroMock()
48
    return service
49
50
51 View Code Duplication
@pytest.fixture
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
52
def connections(loop, player_service, game_service, transport, game):
53
    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 7).

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...
54
55
    def make_connection(player, connectivity):
56
        lc = LobbyConnection(loop)
57
        lc.protocol = mock.Mock()
58
        conn = GameConnection(loop=loop,
59
                              lobby_connection=lc,
60
                              player_service=player_service,
61
                              games=game_service)
62
        conn.player = player
63
        conn.game = game
64
        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...
65
        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...
66
        return conn
67
68
    return mock.Mock(
69
        make_connection=make_connection
70
    )
71
72
def add_connected_player(game: Game, player):
73
    game.game_service.player_service[player.id] = player
74
    gc = mock_game_connection(state=GameConnectionState.CONNECTED_TO_HOST, player=player)
75
    game.set_player_option(player.id, 'Army', 0)
76
    game.set_player_option(player.id, 'StartSpot', 0)
77
    game.set_player_option(player.id, 'Team', 0)
78
    game.set_player_option(player.id, 'Faction', 0)
79
    game.set_player_option(player.id, 'Color', 0)
80
    game.add_game_connection(gc)
81
    return gc
82
83
84
def add_connected_players(game: BaseGame, players):
85
    """
86
    Utility to add players with army and StartSpot indexed by a list
87
    """
88
    for army, player in enumerate(players):
89
        add_connected_player(game, player)
90
        game.set_player_option(player.id, 'Army', army)
91
        game.set_player_option(player.id, 'StartSpot', army)
92
        game.set_player_option(player.id, 'Team', army)
93
        game.set_player_option(player.id, 'Faction', 0)
94
        game.set_player_option(player.id, 'Color', 0)
95
    game.host = players[0]
96
97
def add_players(gameobj: BaseGame, n: int, team: int=None):
98
    game = gameobj
99
    current = len(game.players)
100
    players = []
101
    for i in range(current, current+n):
102
        players.append(Player(id=i+1, login='Player '+str(i+1), global_rating=(1500, 500)))
103
104
    add_connected_players(game, players)
105
106
    if team is not None:
107
        for p in players:
108
            game.set_player_option(p.id, 'Team', team)
109
110
    return players
111