(
native: str,
big: Str,
needle: Optional[str] = None,
check_iterators: bool = False,
)
| 834 | |
| 835 | |
| 836 | def check_identical( |
| 837 | native: str, |
| 838 | big: Str, |
| 839 | needle: Optional[str] = None, |
| 840 | check_iterators: bool = False, |
| 841 | ): |
| 842 | if needle is None: |
| 843 | part_offset = randint(0, len(native) - 1) |
| 844 | part_length = randint(1, len(native) - part_offset) |
| 845 | needle = native[part_offset:part_length] |
| 846 | |
| 847 | present_in_native: bool = needle in native |
| 848 | present_in_big = needle in big |
| 849 | assert present_in_native == present_in_big |
| 850 | assert native.find(needle) == big.find(needle) |
| 851 | assert native.rfind(needle) == big.rfind(needle) |
| 852 | assert native.count(needle) == big.count(needle) |
| 853 | |
| 854 | # Check that the `start` and `stop` positions are correctly inferred |
| 855 | len_half = len(native) // 2 |
| 856 | len_quarter = len(native) // 4 |
| 857 | assert native.find(needle, len_half) == big.find(needle, len_half) |
| 858 | assert native.find(needle, len_quarter, 3 * len_quarter) == big.find(needle, len_quarter, 3 * len_quarter) |
| 859 | |
| 860 | # Check splits and other sequence operations |
| 861 | native_strings = native.split(needle) |
| 862 | big_strings: Strs = big.split(needle) |
| 863 | assert len(native_strings) == len(big_strings) |
| 864 | |
| 865 | if check_iterators: |
| 866 | for i in range(len(native_strings)): |
| 867 | assert len(native_strings[i]) == len(big_strings[i]) |
| 868 | assert ( |
| 869 | native_strings[i] == big_strings[i] |
| 870 | ), f"Mismatch between `{native_strings[i]}` and `{str(big_strings[i])}`" |
| 871 | assert [c for c in native_strings[i]] == [c for c in big_strings[i]] |
| 872 | |
| 873 | is_equal_strings(native_strings, big_strings) |
| 874 | |
| 875 | |
| 876 | @pytest.mark.parametrize("repetitions", range(1, 10)) |
no test coverage detected
searching dependent graphs…