ilc-models 0.2.1__tar.gz → 0.2.3__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {ilc_models-0.2.1 → ilc_models-0.2.3}/CHANGELOG.md +21 -0
- {ilc_models-0.2.1 → ilc_models-0.2.3}/PKG-INFO +3 -3
- {ilc_models-0.2.1 → ilc_models-0.2.3}/README.md +1 -1
- ilc_models-0.2.3/coverage.zsh +3 -0
- ilc_models-0.2.3/docs/requirements.txt +30 -0
- {ilc_models-0.2.1 → ilc_models-0.2.3}/docs/source/conf.py +1 -1
- {ilc_models-0.2.1 → ilc_models-0.2.3}/pyproject.toml +15 -13
- {ilc_models-0.2.1 → ilc_models-0.2.3}/src/ilc_models/__init__.py +131 -12
- {ilc_models-0.2.1 → ilc_models-0.2.3}/tests/test_models.py +143 -1
- ilc_models-0.2.3/uv.lock +828 -0
- ilc_models-0.2.1/docs/requirements.txt +0 -28
- ilc_models-0.2.1/uv.lock +0 -645
- {ilc_models-0.2.1 → ilc_models-0.2.3}/.gitignore +0 -0
- {ilc_models-0.2.1 → ilc_models-0.2.3}/.python-version +0 -0
- {ilc_models-0.2.1 → ilc_models-0.2.3}/.readthedocs.yaml +0 -0
- {ilc_models-0.2.1 → ilc_models-0.2.3}/LICENSE.txt +0 -0
- {ilc_models-0.2.1 → ilc_models-0.2.3}/check.zsh +0 -0
- {ilc_models-0.2.1 → ilc_models-0.2.3}/docs/source/api.rst +0 -0
- {ilc_models-0.2.1 → ilc_models-0.2.3}/docs/source/index.rst +0 -0
- {ilc_models-0.2.1 → ilc_models-0.2.3}/src/ilc_models/py.typed +0 -0
- {ilc_models-0.2.1 → ilc_models-0.2.3}/tests/__init__.py +0 -0
- {ilc_models-0.2.1 → ilc_models-0.2.3}/tests/conftest.py +0 -0
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [0.2.3] - 2026-02-05
|
|
4
|
+
|
|
5
|
+
### Changed
|
|
6
|
+
|
|
7
|
+
- Add `teams` parameter to `Match.players()` method
|
|
8
|
+
- Add `Match.involves_any()` method
|
|
9
|
+
- Add `Match.h2h()` method
|
|
10
|
+
- Add `teams` and `h2h` parameters to `League.matches()` method
|
|
11
|
+
- Add `teams` and `h2h` parameters to `League.match_players()` method
|
|
12
|
+
|
|
13
|
+
## [0.2.2] - 2026-01-21
|
|
14
|
+
|
|
15
|
+
### Changed
|
|
16
|
+
|
|
17
|
+
- Add `team` parameter to `Match.players()` method
|
|
18
|
+
- Add `League.match_players()` method
|
|
19
|
+
|
|
3
20
|
## [0.2.1] - 2025-11-12
|
|
4
21
|
|
|
5
22
|
### Changed
|
|
@@ -68,6 +85,10 @@
|
|
|
68
85
|
|
|
69
86
|
_Initial release._
|
|
70
87
|
|
|
88
|
+
[0.2.3]: https://github.com/fourtreestech/ilc-models/releases/tag/v0.2.3
|
|
89
|
+
|
|
90
|
+
[0.2.2]: https://github.com/fourtreestech/ilc-models/releases/tag/v0.2.2
|
|
91
|
+
|
|
71
92
|
[0.2.1]: https://github.com/fourtreestech/ilc-models/releases/tag/v0.2.1
|
|
72
93
|
|
|
73
94
|
[0.2.0]: https://github.com/fourtreestech/ilc-models/releases/tag/v0.2.0
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: ilc-models
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.3
|
|
4
4
|
Summary: Data models for the ILC project
|
|
5
5
|
Project-URL: Repository, https://github.com/fourtreestech/ilc-models
|
|
6
6
|
Author-email: Neil Martin <neil@fourtrees.tech>
|
|
@@ -14,12 +14,12 @@ Classifier: Programming Language :: Python :: 3.13
|
|
|
14
14
|
Classifier: Topic :: Software Development :: Libraries
|
|
15
15
|
Classifier: Typing :: Typed
|
|
16
16
|
Requires-Python: >=3.12
|
|
17
|
-
Requires-Dist: pydantic>=2.
|
|
17
|
+
Requires-Dist: pydantic>=2.12.5
|
|
18
18
|
Description-Content-Type: text/markdown
|
|
19
19
|
|
|
20
20
|
# ilc-models
|
|
21
21
|
|
|
22
|
-

|
|
23
23
|

|
|
24
24
|

|
|
25
25
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# ilc-models
|
|
2
2
|
|
|
3
|
-

|
|
4
4
|

|
|
5
5
|

|
|
6
6
|
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
alabaster==1.0.0
|
|
2
|
+
annotated-types==0.7.0
|
|
3
|
+
babel==2.17.0
|
|
4
|
+
certifi==2026.1.4
|
|
5
|
+
charset-normalizer==3.4.4
|
|
6
|
+
colorama==0.4.6 ; sys_platform == 'win32'
|
|
7
|
+
docutils==0.22.4
|
|
8
|
+
idna==3.11
|
|
9
|
+
imagesize==1.4.1
|
|
10
|
+
jinja2==3.1.6
|
|
11
|
+
markupsafe==3.0.3
|
|
12
|
+
packaging==25.0
|
|
13
|
+
pydantic==2.12.5
|
|
14
|
+
pydantic-core==2.41.5
|
|
15
|
+
pygments==2.19.1
|
|
16
|
+
requests==2.32.5
|
|
17
|
+
roman-numerals==4.1.0
|
|
18
|
+
snowballstemmer==3.0.1
|
|
19
|
+
sphinx==9.1.0
|
|
20
|
+
sphinx-rtd-theme==3.1.0
|
|
21
|
+
sphinxcontrib-applehelp==2.0.0
|
|
22
|
+
sphinxcontrib-devhelp==2.0.0
|
|
23
|
+
sphinxcontrib-htmlhelp==2.1.0
|
|
24
|
+
sphinxcontrib-jquery==4.1
|
|
25
|
+
sphinxcontrib-jsmath==1.0.1
|
|
26
|
+
sphinxcontrib-qthelp==2.0.0
|
|
27
|
+
sphinxcontrib-serializinghtml==2.0.0
|
|
28
|
+
typing-extensions==4.15.0
|
|
29
|
+
typing-inspection==0.4.2
|
|
30
|
+
urllib3==2.6.3
|
|
@@ -15,7 +15,7 @@ sys.path.insert(0, str(Path("..", "..", "src").resolve()))
|
|
|
15
15
|
project = "ilc-models"
|
|
16
16
|
copyright = "2025, Neil Martin"
|
|
17
17
|
author = "Neil Martin"
|
|
18
|
-
release = "0.2.
|
|
18
|
+
release = "0.2.3"
|
|
19
19
|
|
|
20
20
|
# -- General configuration ---------------------------------------------------
|
|
21
21
|
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "ilc-models"
|
|
3
|
-
version = "0.2.
|
|
3
|
+
version = "0.2.3"
|
|
4
4
|
description = "Data models for the ILC project"
|
|
5
5
|
readme = "README.md"
|
|
6
6
|
authors = [
|
|
@@ -9,7 +9,7 @@ authors = [
|
|
|
9
9
|
requires-python = ">=3.12"
|
|
10
10
|
license = "MIT"
|
|
11
11
|
dependencies = [
|
|
12
|
-
"pydantic>=2.
|
|
12
|
+
"pydantic>=2.12.5",
|
|
13
13
|
]
|
|
14
14
|
classifiers = [
|
|
15
15
|
"Development Status :: 4 - Beta",
|
|
@@ -29,7 +29,7 @@ requires = ["hatchling"]
|
|
|
29
29
|
build-backend = "hatchling.build"
|
|
30
30
|
|
|
31
31
|
[tool.bumpver]
|
|
32
|
-
current_version = "0.2.
|
|
32
|
+
current_version = "0.2.3"
|
|
33
33
|
version_pattern = "MAJOR.MINOR.PATCH"
|
|
34
34
|
commit_message = "Bump version {old_version} -> {new_version}"
|
|
35
35
|
tag_message = "{new_version}"
|
|
@@ -66,19 +66,21 @@ env_list = ["3.13", "3.12"]
|
|
|
66
66
|
|
|
67
67
|
[tool.tox.env_run_base]
|
|
68
68
|
description = "Run tests under {base_python}"
|
|
69
|
-
deps = ["pytest>=
|
|
69
|
+
deps = ["pytest>=9", "pytest-cov>=7", "pytest-randomly>=4", "ilc_provider>=0.1.3"]
|
|
70
70
|
commands = [["pytest"]]
|
|
71
71
|
|
|
72
72
|
[dependency-groups]
|
|
73
73
|
dev = [
|
|
74
|
-
"faker>=
|
|
75
|
-
"ilc-provider>=0.1.
|
|
76
|
-
"mypy>=1.
|
|
77
|
-
"pytest>=
|
|
78
|
-
"pytest-cov>=
|
|
79
|
-
"pytest-randomly>=
|
|
80
|
-
"rich>=
|
|
81
|
-
|
|
82
|
-
|
|
74
|
+
"faker>=40.1.2",
|
|
75
|
+
"ilc-provider>=0.1.3",
|
|
76
|
+
"mypy>=1.19.1",
|
|
77
|
+
"pytest>=9.0.2",
|
|
78
|
+
"pytest-cov>=7.0.0",
|
|
79
|
+
"pytest-randomly>=4.0.1",
|
|
80
|
+
"rich>=14.2.0",
|
|
81
|
+
]
|
|
82
|
+
docs = [
|
|
83
|
+
"sphinx>=9.1.0",
|
|
84
|
+
"sphinx-rtd-theme>=3.1.0",
|
|
83
85
|
]
|
|
84
86
|
|
|
@@ -18,7 +18,7 @@ from pydantic import (
|
|
|
18
18
|
model_validator,
|
|
19
19
|
)
|
|
20
20
|
|
|
21
|
-
__version__ = "0.2.
|
|
21
|
+
__version__ = "0.2.3"
|
|
22
22
|
|
|
23
23
|
|
|
24
24
|
class RowTuple(NamedTuple):
|
|
@@ -455,6 +455,31 @@ class Match(BaseModel):
|
|
|
455
455
|
"""
|
|
456
456
|
return self.teams.home == team or self.teams.away == team
|
|
457
457
|
|
|
458
|
+
def involves_any(self, teams: list[str]) -> bool:
|
|
459
|
+
"""Returns ``True`` if any of ``teams`` is involved in this match.
|
|
460
|
+
|
|
461
|
+
:param teams: Teams to query
|
|
462
|
+
:type team: list[str]
|
|
463
|
+
:returns: ``True`` if any of ``teams`` are involved in this match, i.e.
|
|
464
|
+
either as the home team or the away team
|
|
465
|
+
:rtype: bool
|
|
466
|
+
"""
|
|
467
|
+
return any(self.involves(team) for team in teams)
|
|
468
|
+
|
|
469
|
+
def h2h(self, team1: str, team2: str) -> bool:
|
|
470
|
+
"""Returns ``True`` if the match is a head to head between these two teams.
|
|
471
|
+
|
|
472
|
+
:param team1: First team
|
|
473
|
+
:type team1: str
|
|
474
|
+
:param team2: Second team
|
|
475
|
+
:type team2: str
|
|
476
|
+
:returns: `True` if the match is between the two teams, `False` otherwise
|
|
477
|
+
:rtype: bool
|
|
478
|
+
"""
|
|
479
|
+
return (self.teams.home == team1 and self.teams.away == team2) or (
|
|
480
|
+
self.teams.home == team2 and self.teams.away == team1
|
|
481
|
+
)
|
|
482
|
+
|
|
458
483
|
def events(self) -> list[Event]:
|
|
459
484
|
"""Returns all events in this match in chronological order.
|
|
460
485
|
|
|
@@ -464,13 +489,57 @@ class Match(BaseModel):
|
|
|
464
489
|
e = self.goals + self.cards + self.substitutions
|
|
465
490
|
return sorted(e, key=attrgetter("time"))
|
|
466
491
|
|
|
467
|
-
def players(
|
|
468
|
-
|
|
469
|
-
|
|
492
|
+
def players(
|
|
493
|
+
self, team: Optional[str] = None, teams: Optional[list[str]] = None
|
|
494
|
+
) -> list[BasePlayer]:
|
|
495
|
+
"""Get all players involved in this match.
|
|
496
|
+
|
|
497
|
+
If `team` is provided return only players from the team specified.
|
|
498
|
+
If `teams` is provided return only players from one of the teams specified.
|
|
499
|
+
|
|
500
|
+
:param team: Return only players from this team (default=None)
|
|
501
|
+
:type team: str
|
|
502
|
+
:param teams: Return only players from these teams (default=None)
|
|
503
|
+
:type team: list[str]
|
|
504
|
+
:returns: Players involved in the match
|
|
505
|
+
:rtype: list[:class:`BasePlayer`]
|
|
506
|
+
"""
|
|
507
|
+
# Manage team param
|
|
508
|
+
if not teams:
|
|
509
|
+
if team:
|
|
510
|
+
teams = [team]
|
|
511
|
+
|
|
512
|
+
# Get players from lineups
|
|
513
|
+
if teams:
|
|
514
|
+
# Neither team - just return empty list
|
|
515
|
+
if self.teams.home not in teams and self.teams.away not in teams:
|
|
516
|
+
return []
|
|
517
|
+
|
|
518
|
+
# Add lineups
|
|
519
|
+
p = []
|
|
520
|
+
if self.teams.home in teams:
|
|
521
|
+
p += self.lineups.home.players()
|
|
522
|
+
if self.teams.away in teams:
|
|
523
|
+
p += self.lineups.away.players()
|
|
524
|
+
else:
|
|
525
|
+
p = self.lineups.players()
|
|
526
|
+
|
|
527
|
+
# Add players from events
|
|
470
528
|
for event in self.events():
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
529
|
+
add = False
|
|
530
|
+
if not teams:
|
|
531
|
+
add = True
|
|
532
|
+
elif event.event_type == "goal" and event.goal_type == "O":
|
|
533
|
+
if event.team == self.teams.home and self.teams.away in teams:
|
|
534
|
+
add = True
|
|
535
|
+
elif event.team == self.teams.away and self.teams.home in teams:
|
|
536
|
+
add = True
|
|
537
|
+
else:
|
|
538
|
+
add = event.team in teams
|
|
539
|
+
if add:
|
|
540
|
+
for player in event.players():
|
|
541
|
+
if player not in p:
|
|
542
|
+
p.append(player)
|
|
474
543
|
return p
|
|
475
544
|
|
|
476
545
|
def delete_event(self, event: Event) -> bool:
|
|
@@ -817,7 +886,7 @@ class League(BaseModel):
|
|
|
817
886
|
:param split: Split point of this league (default=0)
|
|
818
887
|
:type split: int
|
|
819
888
|
:param players: Players who feature in this league
|
|
820
|
-
:type players: dict[
|
|
889
|
+
:type players: dict[str, :class:`Player`]
|
|
821
890
|
"""
|
|
822
891
|
|
|
823
892
|
league_id: PositiveInt
|
|
@@ -846,23 +915,45 @@ class League(BaseModel):
|
|
|
846
915
|
season = year1 if year1 == year2 else f"{year1}/{year2 % 100}"
|
|
847
916
|
return f"{self.name} {season}"
|
|
848
917
|
|
|
849
|
-
def matches(
|
|
918
|
+
def matches(
|
|
919
|
+
self,
|
|
920
|
+
team: Optional[str] = None,
|
|
921
|
+
teams: Optional[list[str]] = None,
|
|
922
|
+
h2h: Optional[tuple[str, str]] = None,
|
|
923
|
+
) -> list[Match]:
|
|
850
924
|
"""Matches in this league.
|
|
851
925
|
|
|
852
|
-
If
|
|
853
|
-
|
|
926
|
+
If `team` is given, return only matches involving this team.
|
|
927
|
+
If `teams` is given, return only matches involving one of these teams.
|
|
928
|
+
If `h2h` is given, return only matches between these two teams.
|
|
854
929
|
|
|
855
930
|
:param team: Get matches for this team (default=None)
|
|
856
931
|
:type team: str
|
|
932
|
+
:param teams: Get matches involving any of these teams (default=None)
|
|
933
|
+
:type teams: list[str]
|
|
934
|
+
:param h2h: Get matches between these two teams (eefault=None)
|
|
935
|
+
:type h2h: tuple[str, str]
|
|
857
936
|
:returns: Matches sorted by date and then home team
|
|
858
937
|
:rtype: list[:class:`Match`]
|
|
859
938
|
"""
|
|
939
|
+
# fn is the function that determines whether to include this match
|
|
940
|
+
if team:
|
|
941
|
+
fn = lambda m: m.involves(team)
|
|
942
|
+
elif teams:
|
|
943
|
+
fn = lambda m: m.involves_any(teams)
|
|
944
|
+
elif h2h:
|
|
945
|
+
fn = lambda m: m.h2h(*h2h)
|
|
946
|
+
else:
|
|
947
|
+
fn = lambda _: True
|
|
948
|
+
|
|
949
|
+
# Extract matches that pass the fn test
|
|
860
950
|
_matches = []
|
|
861
951
|
for m in self.rounds.values():
|
|
862
952
|
for match in m:
|
|
863
|
-
if
|
|
953
|
+
if fn(match):
|
|
864
954
|
_matches.append(match)
|
|
865
955
|
|
|
956
|
+
# Sort and return
|
|
866
957
|
_matches.sort(key=attrgetter("teams.home"))
|
|
867
958
|
_matches.sort(key=attrgetter("date"))
|
|
868
959
|
return _matches
|
|
@@ -1046,6 +1137,34 @@ class League(BaseModel):
|
|
|
1046
1137
|
|
|
1047
1138
|
return list(teams)
|
|
1048
1139
|
|
|
1140
|
+
def match_players(
|
|
1141
|
+
self,
|
|
1142
|
+
team: Optional[str] = None,
|
|
1143
|
+
teams: Optional[list[str]] = None,
|
|
1144
|
+
h2h: Optional[tuple[str, str]] = None,
|
|
1145
|
+
) -> list[BasePlayer]:
|
|
1146
|
+
"""Get all players involved in at least one match in this league.
|
|
1147
|
+
|
|
1148
|
+
If `team` is given return only players who have featured for this team.
|
|
1149
|
+
If `teams` is given return only players who have featured for one of these teams.
|
|
1150
|
+
If `h2h` is given return only players who featured in a match between these two teams.
|
|
1151
|
+
|
|
1152
|
+
:param team: Get players who played for this team (default=None)
|
|
1153
|
+
:type team: str
|
|
1154
|
+
:param teams: Get players who played for any of these teams (default=None)
|
|
1155
|
+
:type teams: list[str]
|
|
1156
|
+
:param h2h: Get players who played in a match between these two teams (default=None)
|
|
1157
|
+
:type h2h: tuple[str, str]
|
|
1158
|
+
:returns: All players involved in a match
|
|
1159
|
+
:rtype: list[:class:`BasePlayer`]
|
|
1160
|
+
"""
|
|
1161
|
+
players = []
|
|
1162
|
+
for match in self.matches(team=team, teams=teams, h2h=h2h):
|
|
1163
|
+
for p in match.players(team=team, teams=teams):
|
|
1164
|
+
if p not in players:
|
|
1165
|
+
players.append(p)
|
|
1166
|
+
return players
|
|
1167
|
+
|
|
1049
1168
|
def table(
|
|
1050
1169
|
self,
|
|
1051
1170
|
played: int = 0,
|
|
@@ -257,6 +257,27 @@ class TestMatch:
|
|
|
257
257
|
assert match.involves(away.name)
|
|
258
258
|
assert not match.involves(other.name)
|
|
259
259
|
|
|
260
|
+
def test_involves_any(self, ilc_fake):
|
|
261
|
+
home = ilc_fake.team()
|
|
262
|
+
away = ilc_fake.team()
|
|
263
|
+
other = ilc_fake.team()
|
|
264
|
+
match = ilc_fake.match(home=home, away=away)
|
|
265
|
+
assert match.involves_any([home.name])
|
|
266
|
+
assert match.involves_any([away.name])
|
|
267
|
+
assert match.involves_any([home.name, away.name])
|
|
268
|
+
assert match.involves_any([other.name, away.name])
|
|
269
|
+
assert not match.involves_any([other.name])
|
|
270
|
+
|
|
271
|
+
def test_h2h(self, ilc_fake):
|
|
272
|
+
home = ilc_fake.team()
|
|
273
|
+
away = ilc_fake.team()
|
|
274
|
+
other = ilc_fake.team()
|
|
275
|
+
match = ilc_fake.match(home=home, away=away)
|
|
276
|
+
assert match.h2h(home.name, away.name)
|
|
277
|
+
assert match.h2h(away.name, home.name)
|
|
278
|
+
assert not match.h2h(home.name, home.name)
|
|
279
|
+
assert not match.h2h(other.name, home.name)
|
|
280
|
+
|
|
260
281
|
def test_events_returns_all_events(self, ilc_fake):
|
|
261
282
|
match = ilc_fake.match()
|
|
262
283
|
assert len(match.events()) == len(match.goals) + len(match.cards) + len(
|
|
@@ -373,6 +394,77 @@ class TestMatch:
|
|
|
373
394
|
match.lineups = Lineups()
|
|
374
395
|
assert match.players()
|
|
375
396
|
|
|
397
|
+
def test_players_from_team(self, ilc_fake):
|
|
398
|
+
match = ilc_fake.match()
|
|
399
|
+
team = match.teams.home
|
|
400
|
+
players = match.players(team=team)
|
|
401
|
+
for player in match.lineups.home.starting:
|
|
402
|
+
assert player[1] in players
|
|
403
|
+
for player in match.lineups.away.starting:
|
|
404
|
+
assert player[1] not in players
|
|
405
|
+
|
|
406
|
+
def test_team_players_from_events(self, ilc_fake):
|
|
407
|
+
match = ilc_fake.match()
|
|
408
|
+
match.lineups = Lineups()
|
|
409
|
+
team = match.teams.home
|
|
410
|
+
players = match.players(team=team)
|
|
411
|
+
for event in match.events():
|
|
412
|
+
if event.team == team and not (
|
|
413
|
+
event.event_type == "goal" and event.goal_type == "O"
|
|
414
|
+
):
|
|
415
|
+
for player in event.players():
|
|
416
|
+
assert player in players
|
|
417
|
+
|
|
418
|
+
def test_returns_players_from_teams(self, ilc_fake):
|
|
419
|
+
match = ilc_fake.match()
|
|
420
|
+
players = match.players(teams=[match.teams.home, match.teams.away])
|
|
421
|
+
for player in match.lineups.home.starting:
|
|
422
|
+
assert player[1] in players
|
|
423
|
+
for player in match.lineups.away.starting:
|
|
424
|
+
assert player[1] in players
|
|
425
|
+
|
|
426
|
+
def test_returns_only_players_from_specified_teams(self, ilc_fake):
|
|
427
|
+
match = ilc_fake.match()
|
|
428
|
+
players = match.players(teams=[match.teams.home, "Non-existent United"])
|
|
429
|
+
for player in match.lineups.home.starting:
|
|
430
|
+
assert player[1] in players
|
|
431
|
+
for player in match.lineups.away.starting:
|
|
432
|
+
assert player[1] not in players
|
|
433
|
+
|
|
434
|
+
def test_returns_no_players_if_teams_arent_in_the_match(self, ilc_fake):
|
|
435
|
+
match = ilc_fake.match()
|
|
436
|
+
players = match.players(teams=["Non-existent United"])
|
|
437
|
+
assert not players
|
|
438
|
+
|
|
439
|
+
def test_own_goal_scorer_to_correct_team(self, ilc_fake):
|
|
440
|
+
home = ilc_fake.team()
|
|
441
|
+
away = ilc_fake.team()
|
|
442
|
+
match = ilc_fake.match(home=home, away=away)
|
|
443
|
+
home_players = [player[1] for player in match.lineups.home.starting]
|
|
444
|
+
away_players = [player[1] for player in match.lineups.away.starting]
|
|
445
|
+
match.cards = []
|
|
446
|
+
match.substitutions = []
|
|
447
|
+
|
|
448
|
+
# Generate an own goal for the home team
|
|
449
|
+
match.goals = [
|
|
450
|
+
ilc_fake.goal(
|
|
451
|
+
team=home,
|
|
452
|
+
goal_type="O",
|
|
453
|
+
players=(home_players, away_players),
|
|
454
|
+
)
|
|
455
|
+
]
|
|
456
|
+
match.lineups = Lineups()
|
|
457
|
+
|
|
458
|
+
# There should be one away player returned
|
|
459
|
+
assert not match.players(team=match.teams.home)
|
|
460
|
+
players = match.players(team=match.teams.away)
|
|
461
|
+
assert len(players) == 1
|
|
462
|
+
assert players[0] in away_players
|
|
463
|
+
|
|
464
|
+
def test_invalid_team_returns_empty_list(self, ilc_fake):
|
|
465
|
+
match = ilc_fake.match()
|
|
466
|
+
assert not match.players(team="ABCDEFG")
|
|
467
|
+
|
|
376
468
|
def test_str_gives_score(self, ilc_fake):
|
|
377
469
|
match = ilc_fake.match()
|
|
378
470
|
assert " - ".join((str(match.score.home), str(match.score.away))) in str(match)
|
|
@@ -486,11 +578,23 @@ class TestLeague:
|
|
|
486
578
|
previous = match
|
|
487
579
|
|
|
488
580
|
def test_matches_filtered_by_team(self, fake_league):
|
|
489
|
-
team = fake_league.teams
|
|
581
|
+
team = random.choice(fake_league.teams)
|
|
490
582
|
matches = fake_league.matches(team=team)
|
|
491
583
|
for match in matches:
|
|
492
584
|
assert match.teams.home == team or match.teams.away == team
|
|
493
585
|
|
|
586
|
+
def test_matches_filtered_by_teams(self, fake_league):
|
|
587
|
+
teams = random.sample(fake_league.teams, k=3)
|
|
588
|
+
matches = fake_league.matches(teams=teams)
|
|
589
|
+
for match in matches:
|
|
590
|
+
assert any(team in (match.teams.home, match.teams.away) for team in teams)
|
|
591
|
+
|
|
592
|
+
def test_matches_filtered_by_h2h(self, fake_league):
|
|
593
|
+
teams = tuple(random.sample(fake_league.teams, k=2))
|
|
594
|
+
matches = fake_league.matches(h2h=teams)
|
|
595
|
+
for match in matches:
|
|
596
|
+
assert all(team in (match.teams.home, match.teams.away) for team in teams)
|
|
597
|
+
|
|
494
598
|
def test_events_returns_correct_players_events(self, fake_league):
|
|
495
599
|
player = None
|
|
496
600
|
for match in fake_league.matches():
|
|
@@ -674,6 +778,44 @@ class TestLeague:
|
|
|
674
778
|
for t1, t2 in itertools.permutations(league.teams, r=2):
|
|
675
779
|
assert len(league.head_to_head((t1, t2))) == 2
|
|
676
780
|
|
|
781
|
+
def test_match_players_includes_all_players(self, fake_league):
|
|
782
|
+
players = fake_league.match_players()
|
|
783
|
+
# Select a random player from a random match
|
|
784
|
+
# and check he is in the players list
|
|
785
|
+
match = random.choice(fake_league.matches())
|
|
786
|
+
player = random.choice(match.players())
|
|
787
|
+
assert player in players
|
|
788
|
+
|
|
789
|
+
def test_match_players_includes_no_duplicates(self, fake_league):
|
|
790
|
+
players = fake_league.match_players()
|
|
791
|
+
ids = {player.player_id for player in players}
|
|
792
|
+
assert len(ids) == len(players)
|
|
793
|
+
|
|
794
|
+
def test_match_players_returns_for_team(self, fake_league):
|
|
795
|
+
team = random.choice(fake_league.teams)
|
|
796
|
+
players = fake_league.match_players(team=team)
|
|
797
|
+
matches = fake_league.matches(team=team)
|
|
798
|
+
match = random.choice(matches)
|
|
799
|
+
# All players featuring for team in this match
|
|
800
|
+
# should be in the player list
|
|
801
|
+
lineup = match.lineups.home if team == match.teams.home else match.lineups.away
|
|
802
|
+
for player in lineup.starting:
|
|
803
|
+
assert player[1] in players
|
|
804
|
+
for player in lineup.subs:
|
|
805
|
+
assert player[1] in players
|
|
806
|
+
|
|
807
|
+
def test_match_players_returns_for_teams(self, fake_league):
|
|
808
|
+
match = random.choice(fake_league.matches())
|
|
809
|
+
players = fake_league.match_players(teams=[match.teams.home, match.teams.away])
|
|
810
|
+
for player in match.players():
|
|
811
|
+
assert player in players
|
|
812
|
+
|
|
813
|
+
def test_match_players_returns_for_h2h(self, fake_league):
|
|
814
|
+
match = random.choice(fake_league.matches())
|
|
815
|
+
players = fake_league.match_players(h2h=(match.teams.home, match.teams.away))
|
|
816
|
+
for player in match.players():
|
|
817
|
+
assert player in players
|
|
818
|
+
|
|
677
819
|
|
|
678
820
|
class TestLeagueTable:
|
|
679
821
|
def test_league_table_is_correct_size(self, fake_league):
|