Passed
Push — master ( e2662a...8b3758 )
by manny
01:50
created

test_timer.get_test_race()   B

Complexity

Conditions 3

Size

Total Lines 43
Code Lines 42

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 42
dl 0
loc 43
rs 8.872
c 0
b 0
f 0
cc 3
nop 9

How to fix   Many Parameters   

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

1
from datetime import datetime, time, timedelta, timezone
2
from gadgets.timer import Timer
3
from models.race import Entrant, Goal, Race, Status
4
from users_for_testing import get_test_user, get_test_entrant
5
from categories_for_testing import get_test_race_category
6
from races_for_testing import get_test_race
7
8
9
def get_test_timer():
10
    timer = Timer()
11
    timer.source_name = "Timer source"
12
    timer.enabled = True
13
    return timer
14
15
16
def test_timer_prerace():
17
    timer = get_test_timer()
18
    race = get_test_race(status_value="open", version=12,
19
                         started_at=None, start_delay=timedelta(seconds=-15))
20
    color, text = timer.get_timer_text(race, "")
21
    assert color is None
22
    assert text == "-0:00:15.0"
23
24
    timer.use_podium_colors = True
25
    color, text = timer.get_timer_text(race, "")
26
    assert color is timer.pre_color
27
    assert text == "-0:00:15.0"
28
29
def test_timer_midrace_no_entrant():
30
    timer = get_test_timer()
31
    race = get_test_race(status_value="in_progress", version=15, entrants_count=2,
32
        started_at=datetime.now(timezone.utc)-timedelta(hours=1, minutes=20))
33
    color, text = timer.get_timer_text(race, "")
34
    assert color is None
35
    # hope this always runs in less than 0.1 seconds XD
36
    assert text == "1:20:00.0"
37
    timer.use_podium_colors = True
38
    color, text = timer.get_timer_text(race, "")
39
    assert color is timer.racing_color
40
41
42 View Code Duplication
def test_timer_midrace_w_entrant():
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
43
    timer = get_test_timer()
44
    entrant = get_test_entrant(status_value="finished", finished_at=datetime.now(timezone.utc), finish_time=timedelta(hours=1, minutes=42, seconds=6.9))
45
    race = get_test_race(version=16, entrants_count=2, entrant=entrant)
46
    color, text = timer.get_timer_text(race, entrant.user.full_name)
47
    assert color is None
48
    assert text == "1:42:06.9"
49
    timer.use_podium_colors = True
50
    color, text = timer.get_timer_text(race, entrant.user.full_name)
51
    assert color == timer.racing_color
52
53
def test_timer_midrace_w_user_not_in_race():
54
    timer = get_test_timer()
55
    race = get_test_race(version=17, entrants_count=2, started_at=datetime.now(timezone.utc)-timedelta(hours=1, minutes=42, seconds=42.0))
56
    color, text = timer.get_timer_text(race, "user_not_in_race#6969")
57
    assert color is None
58
    assert text == "1:42:42.0"
59
    timer.use_podium_colors = True
60
    color, text = timer.get_timer_text(race, "user_not_in_race#6969")
61
    assert color == timer.racing_color
62
63
def test_timer_race_cancelled():
64
    timer = get_test_timer()
65
    race = get_test_race(status_value="cancelled", cancelled_at=datetime.now(timezone.utc)+timedelta(minutes=20))
66
    color, text = timer.get_timer_text(race, "")
67
    assert color is None
68
    assert text == "--:--:--.-"
69
    timer.use_podium_colors = True
70
    color, text = timer.get_timer_text(race, "")
71
    # currently, the timer is always red for canceled or dq races
72
    assert color is timer.cancel_dq_color
73
74
def test_timer_user_dqed():
75
    timer = get_test_timer()
76
    entrant = get_test_entrant(status_value="dq")
77
    race = get_test_race(entrant=entrant)
78
    color, text = timer.get_timer_text(race, entrant.user.full_name)
79
    assert color is None
80
    assert text == "--:--:--.-"
81
    timer.use_podium_colors = True
82
    color, text = timer.get_timer_text(race, entrant.user.full_name)
83
    assert color == timer.cancel_dq_color
84
85 View Code Duplication
def test_user_finished_first():
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
86
    timer = get_test_timer()
87
    entrant = get_test_entrant(status_value="finished", finished_at=datetime.now(timezone.utc), finish_time=timedelta(hours=1, minutes=9, seconds=42, microseconds=1), place=1)
88
    race = get_test_race(started_at=datetime.now(timezone.utc)-entrant.finish_time, entrant=entrant, entrants_count=5)
89
    color, text = timer.get_timer_text(race, entrant.user.full_name)
90
    assert color is None
91
    assert text == "1:09:42.0"
92
    timer.use_podium_colors = True
93
    color, text = timer.get_timer_text(race, entrant.user.full_name)
94
    assert color == timer.first_color
95
96 View Code Duplication
def test_user_finished_first():
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
97
    timer = get_test_timer()
98
    entrant = get_test_entrant(status_value="finished", finished_at=datetime.now(timezone.utc), finish_time=timedelta(hours=1, minutes=9, seconds=42, microseconds=1), place=2)
99
    race = get_test_race(started_at=datetime.now(timezone.utc)-entrant.finish_time, entrant=entrant, entrants_count=5)
100
    color, text = timer.get_timer_text(race, entrant.user.full_name)
101
    assert color is None
102
    assert text == "1:09:42.0"
103
    timer.use_podium_colors = True
104
    color, text = timer.get_timer_text(race, entrant.user.full_name)
105
    assert color == timer.second_color
106
107 View Code Duplication
def test_user_finished_first():
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
108
    timer = get_test_timer()
109
    entrant = get_test_entrant(status_value="finished", finished_at=datetime.now(timezone.utc), finish_time=timedelta(hours=1, minutes=9, seconds=42, microseconds=1), place=3)
110
    race = get_test_race(started_at=datetime.now(timezone.utc)-entrant.finish_time, entrant=entrant, entrants_count=5)
111
    color, text = timer.get_timer_text(race, entrant.user.full_name)
112
    assert color is None
113
    assert text == "1:09:42.0"
114
    timer.use_podium_colors = True
115
    color, text = timer.get_timer_text(race, entrant.user.full_name)
116
    assert color == timer.third_color
117
118 View Code Duplication
def test_user_finished_other():
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
119
    timer = get_test_timer()
120
    entrant = get_test_entrant(status_value="finished", finished_at=datetime.now(timezone.utc), finish_time=timedelta(hours=1, minutes=9, seconds=42, microseconds=1), place=5)
121
    race = get_test_race(started_at=datetime.now(timezone.utc)-entrant.finish_time, entrant=entrant, entrants_count=5)
122
    color, text = timer.get_timer_text(race, entrant.user.full_name)
123
    assert color is None
124
    assert text == "1:09:42.0"
125
    timer.use_podium_colors = True
126
    color, text = timer.get_timer_text(race, entrant.user.full_name)
127
    assert color == timer.finished_color