Checks whether the given data contains the given lines. Data may be specified as a single string containing text lines separated by newline characters. Lines may be specified in any of the following forms: * Single string containing text lines sep
(self, data, lines, expected)
| 892 | self.__wait_for_time_change(path, touch=True, last_build_time=True) |
| 893 | |
| 894 | def __expect_lines(self, data, lines, expected): |
| 895 | """ |
| 896 | Checks whether the given data contains the given lines. |
| 897 | |
| 898 | Data may be specified as a single string containing text lines |
| 899 | separated by newline characters. |
| 900 | |
| 901 | Lines may be specified in any of the following forms: |
| 902 | * Single string containing text lines separated by newlines - the |
| 903 | given lines are searched for in the given data without any extra |
| 904 | data lines between them. |
| 905 | * Container of strings containing text lines separated by newlines |
| 906 | - the given lines are searched for in the given data with extra |
| 907 | data lines allowed between lines belonging to different strings. |
| 908 | * Container of strings containing text lines separated by newlines |
| 909 | and containers containing strings - the same as above with the |
| 910 | internal containers containing strings being interpreted as if |
| 911 | all their content was joined together into a single string |
| 912 | separated by newlines. |
| 913 | |
| 914 | A newline at the end of any multi-line lines string is interpreted as |
| 915 | an expected extra trailig empty line. |
| 916 | """ |
| 917 | # str.splitlines() trims at most one trailing newline while we want the |
| 918 | # trailing newline to indicate that there should be an extra empty line |
| 919 | # at the end. |
| 920 | splitlines = lambda x : (x + "\n").splitlines() |
| 921 | |
| 922 | if data is None: |
| 923 | data = [] |
| 924 | elif data.__class__ is str: |
| 925 | data = splitlines(data) |
| 926 | |
| 927 | if lines.__class__ is str: |
| 928 | lines = [splitlines(lines)] |
| 929 | else: |
| 930 | expanded = [] |
| 931 | for x in lines: |
| 932 | if x.__class__ is str: |
| 933 | x = splitlines(x) |
| 934 | expanded.append(x) |
| 935 | lines = expanded |
| 936 | |
| 937 | if _contains_lines(data, lines) != bool(expected): |
| 938 | output = [] |
| 939 | if expected: |
| 940 | output = ["Did not find expected lines:"] |
| 941 | else: |
| 942 | output = ["Found unexpected lines:"] |
| 943 | first = True |
| 944 | for line_sequence in lines: |
| 945 | if line_sequence: |
| 946 | if first: |
| 947 | first = False |
| 948 | else: |
| 949 | output.append("...") |
| 950 | output.extend(" > " + line for line in line_sequence) |
| 951 | output.append("in output:") |
no test coverage detected