def timer_should_be_lesser_then(self, expected_time, timer_name="Global"): if timer_name not in self.TIMERS_DICTIONARY: message = "Time '%s' is not started." % timer_name raise AssertionError(message) else: delta = get_current_time_for_timers() - self.TIMERS_DICTIONARY[timer_name] delta = Time._convert_time_to_seconds(self, delta) expected_time = Time._convert_time_to_seconds(self, expected_time) if delta > expected_time: message = "Timer '%s' is above expected time. Actual time %s > %s expected time " % (timer_name, delta, expected_time) raise AssertionError(message) return delta
def timer_should_be_lesser_then(self, expected_time, timer_name="Global"): if timer_name not in self.TIMERS_DICTIONARY: message = "Time '%s' is not started." % timer_name raise AssertionError(message) else: delta = get_current_time_for_timers( ) - self.TIMERS_DICTIONARY[timer_name] delta = Time._convert_time_to_seconds(self, delta) expected_time = Time._convert_time_to_seconds(self, expected_time) if delta > expected_time: message = "Timer '%s' is above expected time. Actual time %s > %s expected time " % ( timer_name, delta, expected_time) raise AssertionError(message) return delta
def timer_log(self, timer_name="Global", log_level="INFO", result_format="number", exclude_millis="True"): current_time = get_current_time_for_timers() if timer_name not in self.TIMERS_DICTIONARY: message = "Time '%s' is not started." % timer_name raise AssertionError(message) else: delta = Time(current_time - self.TIMERS_DICTIONARY[timer_name]).convert( result_format, millis=is_falsy(exclude_millis)) msg = "Timer \"%s\" current results is %s" % ( timer_name, Time(current_time - self.TIMERS_DICTIONARY[timer_name]).convert( "verbose", millis=is_falsy(exclude_millis))) logger.write(msg, log_level) return delta
def timer_stop(self, timer_name="Global", result_format="number", exclude_millis="True"): current_time = get_current_time_for_timers() if timer_name not in self.TIMERS_DICTIONARY: message = "Time '%s' is not started." % timer_name raise AssertionError(message) else: delta = Time(current_time - self.TIMERS_DICTIONARY[timer_name]).convert( result_format, millis=is_falsy(exclude_millis)) del self.TIMERS_DICTIONARY[timer_name] return delta
def _add_results_to_log_file(self, results): current_time = get_current_time_for_timers() total_time_verbose = Time(current_time - self.start_time).convert("verbose") if results: data = "[\n" for i in range(len(results)): data += "(" for j in range(len(results[i])): data += str(results[i][j]) if j != (len(results[i]) - 1): data += "\t," data += ")\n" data += "]" else: data = "" final_string = "/* Response of statement in :" + total_time_verbose + " , data below " + data + " */\n" self._append_to_file(final_string)