1
|
|
|
import gc |
2
|
|
|
from unittest import mock |
3
|
|
|
|
4
|
|
|
from trueskill import Rating |
|
|
|
|
5
|
|
|
|
6
|
|
|
from faf.factions import Faction |
|
|
|
|
7
|
|
|
from server.players import Player |
8
|
|
|
|
9
|
|
|
|
10
|
|
|
def test_ratings(): |
11
|
|
|
p = Player('Schroedinger') |
12
|
|
|
p.global_rating = (1500, 20) |
13
|
|
|
assert p.global_rating == (1500, 20) |
14
|
|
|
p.global_rating = Rating(1700, 20) |
15
|
|
|
assert p.global_rating == (1700, 20) |
16
|
|
|
p.ladder_rating = (1200, 20) |
17
|
|
|
assert p.ladder_rating == (1200, 20) |
18
|
|
|
p.ladder_rating = Rating(1200, 20) |
19
|
|
|
assert p.ladder_rating == (1200, 20) |
20
|
|
|
|
21
|
|
|
|
22
|
|
|
def test_faction(): |
23
|
|
|
""" |
24
|
|
|
Yes, this test was motivated by a bug |
25
|
|
|
:return: |
26
|
|
|
""" |
27
|
|
|
p = Player('Schroedinger2') |
28
|
|
|
p.faction = 'aeon' |
29
|
|
|
assert p.faction == Faction.aeon |
30
|
|
|
p.faction = Faction.aeon |
31
|
|
|
assert p.faction == Faction.aeon |
32
|
|
|
|
33
|
|
|
|
34
|
|
|
def test_equality_by_id(): |
35
|
|
|
p = Player('Sheeo', 42) |
36
|
|
|
p2 = Player('RandomSheeo', 42) |
37
|
|
|
assert p == p2 |
38
|
|
|
assert p.__hash__() == p2.__hash__() |
39
|
|
|
|
40
|
|
|
|
41
|
|
|
def test_weak_references(): |
42
|
|
|
p = Player(login='Test') |
43
|
|
|
weak_properties = ['lobby_connection', 'game_connection', 'game'] |
44
|
|
|
referent = mock.Mock() |
45
|
|
|
for prop in weak_properties: |
46
|
|
|
setattr(p, prop, referent) |
47
|
|
|
|
48
|
|
|
del referent |
49
|
|
|
gc.collect() |
50
|
|
|
|
51
|
|
|
for prop in weak_properties: |
52
|
|
|
assert getattr(p, prop) is None |
53
|
|
|
|
54
|
|
|
def test_unlink_weakref(): |
55
|
|
|
p = Player(login='Test') |
56
|
|
|
mock_game = mock.Mock() |
57
|
|
|
p.game = mock_game |
58
|
|
|
assert p.game == mock_game |
59
|
|
|
del p.game |
60
|
|
|
assert p.game is None |
61
|
|
|
|
62
|
|
|
def test_serialize(): |
63
|
|
|
p = Player(id=42, |
64
|
|
|
login='Something', |
65
|
|
|
global_rating=(1234, 68), |
66
|
|
|
ladder_rating=(1500, 230), |
67
|
|
|
clan='TOAST', |
68
|
|
|
numGames=542) |
69
|
|
|
assert p.to_dict() == { |
70
|
|
|
"id": 42, |
71
|
|
|
"login": 'Something', |
72
|
|
|
"global_rating": (1234, 68), |
73
|
|
|
"ladder_rating": (1500, 230), |
74
|
|
|
"number_of_games": 542, |
75
|
|
|
"clan": 'TOAST' |
76
|
|
|
} |
77
|
|
|
|
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.
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.