| 49 | |
| 50 | # Represents a single test result (row set) |
| 51 | class QueryTestResult(object): |
| 52 | def __init__(self, result_list, column_types, column_labels, order_matters): |
| 53 | self.column_types = column_types |
| 54 | self.result_list = result_list |
| 55 | # The order of the result set might be different if running with multiple nodes. |
| 56 | # Unless there is an ORDER BY clause, the results should be sorted for comparison. |
| 57 | test_results = result_list |
| 58 | if not order_matters: |
| 59 | test_results = sorted(result_list) |
| 60 | self.rows = [ResultRow(row, column_types, column_labels) for row in test_results] |
| 61 | |
| 62 | def __eq__(self, other): |
| 63 | if not isinstance(other, self.__class__): |
| 64 | return False |
| 65 | return self.column_types == other.column_types and self.rows == other.rows |
| 66 | |
| 67 | def __hash__(self): |
| 68 | # This is not intended to be hashed. If that is happening, then something is wrong. |
| 69 | # The regexes in ResultRow make it difficult to implement this correctly. |
| 70 | assert False |
| 71 | |
| 72 | def __ne__(self, other): |
| 73 | return not self.__eq__(other) |
| 74 | |
| 75 | def __str__(self): |
| 76 | return '\n'.join(['%s' % row for row in self.rows]) |
| 77 | |
| 78 | def separate_rows(self): |
| 79 | """Returns rows that are literal rows and rows that are not literals (e.g. regex) |
| 80 | in two lists.""" |
| 81 | literal_rows = [] |
| 82 | non_literal_rows = [] |
| 83 | for row in self.rows: |
| 84 | if row.regex is None: |
| 85 | literal_rows.append(row) |
| 86 | else: |
| 87 | non_literal_rows.append(row) |
| 88 | return (literal_rows, non_literal_rows) |
| 89 | |
| 90 | |
| 91 | # Represents a row in a result set |
no outgoing calls