Skip to content

Commit 42e0b4d

Browse files
committed
test: Make CompletionResult a sequence
This should make pytest make niceer diffs when asserts fail, specifically telling you what index the first not equal items were at.
1 parent 9153f95 commit 42e0b4d

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

test/t/conftest.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import sys
88
import tempfile
99
import time
10+
from collections.abc import Sequence
1011
from enum import Enum
1112
from pathlib import Path
1213
from types import TracebackType
@@ -753,7 +754,7 @@ def diff_env(before: List[str], after: List[str], ignore: str):
753754
assert not diff, "Environment should not be modified"
754755

755756

756-
class CompletionResult(Iterable[str]):
757+
class CompletionResult(Sequence[str]):
757758
"""
758759
Class to hold completion results.
759760
"""
@@ -773,6 +774,9 @@ def startswith(self, prefix: str) -> bool:
773774
def _items(self) -> List[str]:
774775
return sorted([x.strip() for x in self.output.strip().splitlines()])
775776

777+
def __getitem__(self, i) -> str:
778+
return self._items()[i]
779+
776780
def __eq__(self, expected: object) -> bool:
777781
"""
778782
Returns True if completion contains expected items, and no others.
@@ -788,7 +792,7 @@ def __eq__(self, expected: object) -> bool:
788792
expiter = expected
789793
return self._items() == sorted(expiter)
790794

791-
def __contains__(self, item: str) -> bool:
795+
def __contains__(self, item: object) -> bool:
792796
return item in self._items()
793797

794798
def __iter__(self) -> Iterator[str]:

0 commit comments

Comments
 (0)