races_for_testing.get_test_race()   B
last analyzed

Complexity

Conditions 1

Size

Total Lines 45
Code Lines 43

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 43
dl 0
loc 45
rs 8.8478
c 0
b 0
f 0
cc 1
nop 10

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, timedelta, timezone
2
from typing import List
3
4
from models.race import Entrant, Goal, Race, Status
5
from models.user import User
6
7
from categories_for_testing import get_test_race_category
8
9
10
def time_ago(**kwargs):
11
    return datetime.now(timezone.utc)-timedelta(**kwargs)
12
13
14
def get_test_race(
15
        status_value="in_progress", version=1, entrants_count=2,
16
        started_at=datetime.now(timezone.utc),
17
        start_delay=timedelta(seconds=-15),
18
        opened_at=datetime.now(timezone.utc), ended_at=None,
19
        cancelled_at: datetime = None, entrants: List[Entrant] = None,
20
        opened_by: User = None
21
        ) -> Race:
22
    entrant_count_finished = list.count(
23
            (list((x.status.value == "finished" for x in entrants))), True)
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable x does not seem to be defined.
Loading history...
24
    test_race = Race(name="tested-raceroom-0420",
25
                     status=Status(value=status_value,
26
                                   verbose_value="", help_text=""),
27
                     category=get_test_race_category(),
28
                     goal=Goal("", False),
29
                     info="A test race",
30
                     url="",
31
                     data_url="",
32
                     websocket_url="",
33
                     websocket_bot_url="",
34
                     websocket_oauth_url="",
35
                     entrants_count=entrants_count,
36
                     entrants_count_inactive=0,
37
                     entrants_count_finished=entrant_count_finished,
38
                     entrants=entrants,
39
                     version=version,
40
                     started_at=started_at,
41
                     start_delay=start_delay,
42
                     ended_at=ended_at,
43
                     cancelled_at=cancelled_at,
44
                     unlisted=False,
45
                     time_limit=timedelta(days=1),
46
                     streaming_required=True,
47
                     auto_start=True,
48
                     opened_by=opened_by,
49
                     opened_at=opened_at,
50
                     monitors=[],
51
                     recordable=True,
52
                     recorded=False,
53
                     recorded_by=None,
54
                     allow_comments=True,
55
                     hide_comments=False,
56
                     allow_midrace_chat=True
57
                     )
58
    return test_race
59