|
| 1 | +def assert_value_equality(results, expected_values): |
| 2 | + """Assert equality between two objects. |
| 3 | +
|
| 4 | + *results* must be a list of results as returned by `.find()` methods. |
| 5 | +
|
| 6 | + If *expected_values* is a list, then value equality and ordering will be checked. |
| 7 | + If *expected_values* is a set, value equality and container length will be checked. |
| 8 | + Otherwise, the value of the results will be compared to the expected values. |
| 9 | + """ |
| 10 | + |
| 11 | + left_values = [result.value for result in results] |
| 12 | + if isinstance(expected_values, list): |
| 13 | + assert left_values == expected_values |
| 14 | + elif isinstance(expected_values, set): |
| 15 | + assert len(left_values) == len(expected_values) |
| 16 | + assert set(left_values) == expected_values |
| 17 | + else: |
| 18 | + assert results.value == expected_values |
| 19 | + |
| 20 | + |
| 21 | +def assert_full_path_equality(results, expected_full_paths): |
| 22 | + """Assert equality between two objects. |
| 23 | +
|
| 24 | + *results* must be a list of results as returned by `.find()` methods. |
| 25 | +
|
| 26 | + If *expected_full_paths* is a list, then path equality and ordering will be checked. |
| 27 | + If *expected_full_paths* is a set, then path equality and length will be checked. |
| 28 | + Otherwise, the full path of the result will be compared to the expected full path. |
| 29 | + """ |
| 30 | + |
| 31 | + full_paths = [str(result.full_path) for result in results] |
| 32 | + if isinstance(expected_full_paths, list): |
| 33 | + assert full_paths == expected_full_paths, full_paths |
| 34 | + elif isinstance(expected_full_paths, set): |
| 35 | + assert len(full_paths) == len(expected_full_paths) |
| 36 | + assert set(full_paths) == expected_full_paths |
| 37 | + else: |
| 38 | + assert str(results.full_path) == expected_full_paths |
0 commit comments