This class holds information about the outcome of a search run.
| 813 | |
| 814 | |
| 815 | class SearchResults(object): |
| 816 | '''This class holds information about the outcome of a search run.''' |
| 817 | |
| 818 | def __init__(self, |
| 819 | query_count, |
| 820 | queries_resulted_in_data_count, |
| 821 | mismatch_count, |
| 822 | query_timeout_count, |
| 823 | known_error_count, |
| 824 | test_crash_count, |
| 825 | run_time_in_seconds, |
| 826 | count_effective_dml_statements, |
| 827 | count_rows_affected_by_dml |
| 828 | ): |
| 829 | # Approx number of queries run, some queries may have been ignored |
| 830 | self.query_count = query_count |
| 831 | self.queries_resulted_in_data_count = queries_resulted_in_data_count |
| 832 | # Number of queries that had an error or result mismatch |
| 833 | self.mismatch_count = mismatch_count |
| 834 | self.query_timeout_count = query_timeout_count |
| 835 | self.known_error_count = known_error_count |
| 836 | self.test_crash_count = test_crash_count |
| 837 | self.run_time_in_seconds = run_time_in_seconds |
| 838 | # number of DML statements that actually modified tables |
| 839 | self.count_effective_dml_statements = count_effective_dml_statements |
| 840 | # total number of rows modified by DML statemnts |
| 841 | self.count_rows_affected_by_dml = count_rows_affected_by_dml |
| 842 | |
| 843 | def __str__(self): |
| 844 | '''Returns the string representation of the results.''' |
| 845 | mins, secs = divmod(self.run_time_in_seconds, 60) |
| 846 | hours, mins = divmod(mins, 60) |
| 847 | hours = int(hours) |
| 848 | mins = int(mins) |
| 849 | if hours: |
| 850 | run_time = '%s hour and %s minutes' % (hours, mins) |
| 851 | else: |
| 852 | secs = int(secs) |
| 853 | run_time = '%s seconds' % secs |
| 854 | if mins: |
| 855 | run_time = '%s mins and ' % mins + run_time |
| 856 | summary_params = self.__dict__ |
| 857 | summary_params['run_time'] = run_time |
| 858 | return ( |
| 859 | '%(mismatch_count)s mismatches found after running %(query_count)s queries in ' |
| 860 | '%(run_time)s.\n' |
| 861 | '%(queries_resulted_in_data_count)s of %(query_count)s queries produced results.' |
| 862 | '\n' |
| 863 | '%(count_effective_dml_statements)s of %(query_count)s statements modified a ' |
| 864 | 'total of %(count_rows_affected_by_dml)s rows\n' |
| 865 | '%(test_crash_count)s crashes occurred.\n' |
| 866 | '%(known_error_count)s queries were excluded from the mismatch count because ' |
| 867 | 'they are known errors.\n' |
| 868 | '%(query_timeout_count)s queries timed out and were excluded from all counts.') \ |
| 869 | % summary_params |
| 870 | |
| 871 | |
| 872 | if __name__ == '__main__': |