Skip to content

Commit 8f02bb1

Browse files
committed
Make platform and group IDs resolution case-insensitive
1 parent 642288b commit 8f02bb1

File tree

4 files changed

+59
-28
lines changed

4 files changed

+59
-28
lines changed

changelog.md

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
> [!IMPORTANT]
66
> This version is not released yet and is under active development.
77
8+
- Make resolution of platform and group IDs case-insensitive.
89
- Drop supports for Python 3.10.
910

1011
## [2.1.0 (2025-02-20)](https://github.com/kdeldycke/extra-platforms/compare/v2.0.0...v2.1.0)

extra_platforms/group.py

+5
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,11 @@ def _extract_platforms(other: _TNestedSources) -> Iterator[Platform]:
124124
yield other
125125
elif isinstance(other, Group):
126126
yield from other.platforms
127+
elif isinstance(other, str):
128+
# Prevent circular import.
129+
from .operations import platforms_from_ids
130+
131+
yield platforms_from_ids(other)
127132
elif isinstance(other, Iterable):
128133
for item in flatten_iter(other):
129134
yield from Group._extract_platforms(item)

extra_platforms/operations.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def platforms_from_ids(*platform_ids: str) -> set[Platform]:
4848
If you want to reduce the returned set and removes as much overlaps as
4949
possible, you can use the ``extra_platforms.reduce()`` function on the results.
5050
"""
51-
ids = frozenset(platform_ids)
51+
ids = frozenset((s.lower() for s in platform_ids))
5252
unrecognized_ids = ids - ALL_IDS
5353
if unrecognized_ids:
5454
raise ValueError(f"Unrecognized IDs: {', '.join(sorted(unrecognized_ids))}")
@@ -69,7 +69,7 @@ def groups_from_ids(*group_ids: str) -> set[Group]:
6969
If you want to reduce the returned set and removes as much overlaps as
7070
possible, you can use the ``extra_platforms.reduce()`` function on the results.
7171
"""
72-
ids = frozenset(group_ids)
72+
ids = frozenset((s.lower() for s in group_ids))
7373
unrecognized_ids = ids - ALL_GROUP_IDS
7474
if unrecognized_ids:
7575
raise ValueError(

tests/test_operations.py

+51-26
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616

1717
from __future__ import annotations
1818

19+
from random import choice
20+
from typing import Iterable
21+
1922
import pytest
2023

2124
from extra_platforms import (
@@ -108,32 +111,54 @@ def test_unique_ids():
108111
assert ALL_GROUP_IDS.isdisjoint(ALL_PLATFORM_IDS)
109112

110113

111-
def test_platforms_from_ids():
112-
for platform_id in ALL_PLATFORM_IDS:
113-
platforms = platforms_from_ids(platform_id)
114-
assert platforms
115-
assert len(platforms) == 1
116-
platform = platforms.pop()
117-
assert platform.id == platform_id
118-
assert platform in ALL_PLATFORMS.platforms
119-
120-
for group_id in ALL_GROUP_IDS:
121-
platforms = platforms_from_ids(group_id)
122-
assert platforms
123-
assert len(platforms) >= 1
124-
groups = groups_from_ids(group_id)
125-
assert len(groups) == 1
126-
group = groups.pop()
127-
assert platforms == set(group.platforms)
128-
129-
130-
def test_groups_from_ids():
131-
for group_id in ALL_GROUP_IDS:
132-
groups = groups_from_ids(group_id)
133-
assert len(groups) == 1
134-
group = groups.pop()
135-
assert group.id == group_id
136-
assert group in ALL_GROUPS
114+
def randomize_case(strings: Iterable[str]) -> set[str]:
115+
test_strings = set()
116+
for string in strings:
117+
test_strings.add(string)
118+
for str_func in (
119+
str.upper,
120+
str.lower,
121+
str.title,
122+
str.capitalize,
123+
str.casefold,
124+
str.swapcase,
125+
):
126+
test_strings.add(str_func(string))
127+
test_strings.add(
128+
"".join(choice((str.upper, str.lower))(char) for char in string)
129+
)
130+
return test_strings
131+
132+
133+
@pytest.mark.parametrize("platform_id", randomize_case(ALL_PLATFORM_IDS))
134+
def test_platforms_from_ids(platform_id):
135+
platforms = platforms_from_ids(platform_id)
136+
assert platforms
137+
assert len(platforms) == 1
138+
platform = platforms.pop()
139+
assert platform.id == platform_id.lower()
140+
assert platform in ALL_PLATFORMS.platforms
141+
142+
143+
@pytest.mark.parametrize("group_id", randomize_case(ALL_GROUP_IDS))
144+
def test_platforms_from_ids_group_resolve(group_id):
145+
"""platforms_from_ids() can also resolve group IDs."""
146+
platforms = platforms_from_ids(group_id)
147+
assert platforms
148+
assert len(platforms) >= 1
149+
groups = groups_from_ids(group_id)
150+
assert len(groups) == 1
151+
group = groups.pop()
152+
assert platforms == set(group.platforms)
153+
154+
155+
@pytest.mark.parametrize("group_id", randomize_case(ALL_GROUP_IDS))
156+
def test_groups_from_ids(group_id):
157+
groups = groups_from_ids(group_id)
158+
assert len(groups) == 1
159+
group = groups.pop()
160+
assert group.id == group_id.lower()
161+
assert group in ALL_GROUPS
137162

138163

139164
@pytest.mark.parametrize(

0 commit comments

Comments
 (0)