-
Notifications
You must be signed in to change notification settings - Fork 184
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add per-aircraft datalink configuration.
- Loading branch information
Showing
7 changed files
with
107 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
from __future__ import annotations | ||
|
||
from dataclasses import dataclass | ||
from typing import Any | ||
|
||
|
||
@dataclass(frozen=True) | ||
class DatalinkConfig: | ||
max_team_members: int | ||
max_donors: int | ||
|
||
@staticmethod | ||
def from_data(data: dict[str, Any]) -> DatalinkConfig | None: | ||
try: | ||
data = data["datalink"] | ||
except KeyError: | ||
return None | ||
return DatalinkConfig(int(data["max_team_members"]), int(data["max_donors"])) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -78,3 +78,6 @@ laser_codes: | |
digit: 1 | ||
- id: LaserCode1 | ||
digit: 0 | ||
datalink: | ||
max_team_members: 8 | ||
max_donors: 4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import pytest | ||
|
||
from game.dcs.datalinkconfig import DatalinkConfig | ||
|
||
|
||
def test_from_data_no_data() -> None: | ||
assert DatalinkConfig.from_data({}) is None | ||
|
||
|
||
def test_from_data_bad_data() -> None: | ||
with pytest.raises(KeyError): | ||
DatalinkConfig.from_data( | ||
{ | ||
"datalink": { | ||
"max_team_members": 4, | ||
} | ||
} | ||
) | ||
with pytest.raises(KeyError): | ||
DatalinkConfig.from_data( | ||
{ | ||
"datalink": { | ||
"max_donors": 4, | ||
} | ||
} | ||
) | ||
with pytest.raises(ValueError): | ||
DatalinkConfig.from_data( | ||
{ | ||
"datalink": { | ||
"max_team_members": 4, | ||
"max_donors": "a", | ||
} | ||
} | ||
) | ||
with pytest.raises(ValueError): | ||
DatalinkConfig.from_data( | ||
{ | ||
"datalink": { | ||
"max_team_members": "a", | ||
"max_donors": 4, | ||
} | ||
} | ||
) | ||
|
||
|
||
def test_from_data() -> None: | ||
assert DatalinkConfig.from_data( | ||
{ | ||
"datalink": { | ||
"max_team_members": 4, | ||
"max_donors": 8, | ||
} | ||
} | ||
) == DatalinkConfig(max_team_members=4, max_donors=8) |