diff --git a/dirty_equals/_base.py b/dirty_equals/_base.py index 9481a8f..e447619 100644 --- a/dirty_equals/_base.py +++ b/dirty_equals/_base.py @@ -277,8 +277,10 @@ def __init__(self, expected_value: Any, *more_expected_values: Any): assert 1 == IsOneOf(1, 2, 3) assert 4 != IsOneOf(1, 2, 3) + # check that a list either contain 1 or is empty assert [1, 2, 3] == Contains(1) | IsOneOf([]) assert [] == Contains(1) | IsOneOf([]) + ``` """ self.expected_values: Tuple[Any, ...] = (expected_value,) + more_expected_values super().__init__(*self.expected_values) diff --git a/tests/test_docs.py b/tests/test_docs.py index eeb9a26..cb325b4 100644 --- a/tests/test_docs.py +++ b/tests/test_docs.py @@ -29,6 +29,12 @@ def _import_execute(module_name: str, source: str, rewrite_assertions: bool = Fa def extract_code_chunks(path: Path, text: str, offset: int): rel_path = path.relative_to(ROOT_DIR) + fences = len(re.findall(r'^```', text, flags=re.M)) + if fences % 2 != 0: + raise ValueError( + f'{rel_path}:{offset} has an odd number of code fences (```), might be missing a closing fence' + ) + for m_code in re.finditer(r'^```(.*?)$\n(.*?)^```', text, flags=re.M | re.S): prefix = m_code.group(1).lower() if not prefix.startswith(('py', '{.py')) or 'test="false"' in prefix: