Skip to content

Commit 7a18647

Browse files
committed
Make tag exclusions per platform
1 parent b1b83f5 commit 7a18647

File tree

1 file changed

+43
-35
lines changed
  • graalpython/com.oracle.graal.python.test/src

1 file changed

+43
-35
lines changed

graalpython/com.oracle.graal.python.test/src/runner.py

Lines changed: 43 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ def out_tell():
224224
T = typing.TypeVar('T')
225225

226226

227-
def partition_list(l: list[T], fn: typing.Callable[[T], bool]):
227+
def partition_list(l: list[T], fn: typing.Callable[[T], bool]) -> tuple[list[T], list[T]]:
228228
a = []
229229
b = []
230230
for item in l:
@@ -486,7 +486,7 @@ def generate_tags(self, append=False):
486486
def update_tags(test_file: 'TestFile', results: list[TestResult], tag_platform: str,
487487
untag_failed=False, untag_skipped=False, untag_missing=False):
488488
current = read_tags(test_file, allow_exclusions=True)
489-
exclusions, current = partition_list(current, lambda t: isinstance(t, TagExclusion))
489+
exclusions, current = partition_list(current, lambda t: t.is_exclusion)
490490
status_by_id = {r.test_id.normalized(): r.status for r in results}
491491
tag_by_id = {}
492492
for tag in current:
@@ -510,7 +510,15 @@ def update_tags(test_file: 'TestFile', results: list[TestResult], tag_platform:
510510
tag_by_id[test_id] = Tag.for_key(test_id, tag_platform)
511511

512512
for exclusion in exclusions:
513-
tag_by_id.pop(exclusion.test_id, None)
513+
if tag := tag_by_id.get(exclusion.test_id):
514+
if exclusion.keys:
515+
tag = tag.without_keys(exclusion.keys)
516+
else:
517+
tag = None
518+
if not tag:
519+
del tag_by_id[exclusion.test_id]
520+
else:
521+
tag_by_id[exclusion.test_id] = tag
514522

515523
tags = set(tag_by_id.values()) | set(exclusions)
516524
write_tags(test_file, tags)
@@ -1191,31 +1199,31 @@ def collect(all_specifiers: list[TestSpecifier], *, use_tags=False, ignore=None,
11911199
class Tag:
11921200
test_id: TestId
11931201
keys: frozenset[str]
1202+
is_exclusion: bool
1203+
comment: str | None = False
11941204

11951205
@classmethod
1196-
def for_key(cls, test_id, key):
1197-
return Tag(test_id, frozenset({key}))
1198-
1199-
def with_key(self, key: str):
1200-
return Tag(self.test_id, self.keys | {key})
1201-
1202-
def without_key(self, key: str):
1203-
if key not in self.keys:
1204-
return self
1205-
keys = self.keys - {key}
1206-
if keys:
1207-
return Tag(self.test_id, keys)
1206+
def for_key(cls, test_id, key) -> 'Tag':
1207+
return Tag(test_id, frozenset({key}), is_exclusion=False)
12081208

1209-
def __str__(self):
1210-
return f'{self.test_id.test_name} @ {",".join(sorted(self.keys))}'
1209+
def with_key(self, key: str) -> 'Tag':
1210+
return Tag(self.test_id, self.keys | {key}, is_exclusion=self.is_exclusion)
12111211

1212+
def without_key(self, key: str) -> 'Tag | None':
1213+
return self.without_keys({key})
12121214

1213-
@dataclass(frozen=True)
1214-
class TagExclusion(Tag):
1215-
comment: str | None
1215+
def without_keys(self, keys: set[str]) -> 'Tag | None':
1216+
keys = self.keys - keys
1217+
if keys:
1218+
if keys == self.keys:
1219+
return self
1220+
return Tag(self.test_id, keys, is_exclusion=self.is_exclusion)
12161221

12171222
def __str__(self):
1218-
s = f'!{self.test_id.test_name}'
1223+
s = ''
1224+
if self.is_exclusion:
1225+
s += '!'
1226+
s += self.test_id.test_name
12191227
if self.keys:
12201228
s += f' @ {",".join(sorted(self.keys))}'
12211229
if self.comment:
@@ -1241,21 +1249,21 @@ def read_tags(test_file: TestFile, allow_exclusions=False) -> list[Tag]:
12411249
test, _, keys = line.partition('@')
12421250
test = test.strip()
12431251
keys = keys.strip()
1252+
is_exclusion = False
12441253
if test.startswith('!'):
1245-
if allow_exclusions:
1246-
test = test.removeprefix('!')
1247-
tags.append(TagExclusion(
1248-
TestId(test_path, test),
1249-
frozenset(keys.split(',')) if keys else frozenset(),
1250-
comment,
1251-
))
1252-
else:
1253-
if not keys:
1254-
log(f'WARNING: invalid tag {test}: missing platform keys')
1255-
tags.append(Tag(
1256-
TestId(test_path, test),
1257-
frozenset(keys.split(',')),
1258-
))
1254+
is_exclusion = True
1255+
test = test.removeprefix('!')
1256+
1257+
if not keys and not is_exclusion:
1258+
log(f'WARNING: invalid tag {test}: missing platform keys')
1259+
tag = Tag(
1260+
TestId(test_path, test),
1261+
frozenset(keys.split(',') if keys else frozenset()),
1262+
is_exclusion=is_exclusion,
1263+
comment=comment,
1264+
)
1265+
if not is_exclusion or allow_exclusions:
1266+
tags.append(tag)
12591267
comment = None
12601268
return tags
12611269

0 commit comments

Comments
 (0)