class RunResults(object): """Encapsulates the results of a single Boom run. Contains a dictionary of status codes to lists of request durations, a list of exception instances raised during the run, the total time of the run and an animated progress bar. """ def __init__(self, num=1, quiet=False): self.status_code_counter = defaultdict(list) self.errors = [] self.total_time = None if num is not None: self._progress_bar = AnimatedProgressBar( end=num, width=65) else: self._progress_bar = None self.quiet = quiet def incr(self): if self.quiet: return if self._progress_bar is not None: self._progress_bar + 1 self._progress_bar.show_progress() else: sys.stdout.write('.') sys.stdout.flush()
def show_progress(self): if hasattr(self.stdout, 'isatty') and self.stdout.isatty(): self.stdout.write('\r') else: self.stdout.write('\n') self.stdout.write(str(self)) self.stdout.flush() if __name__ == '__main__': p = AnimatedProgressBar(end=100, width=80) while True: p + 5 p.show_progress() time.sleep(0.1) if p.progress == 100: break print # new line ########NEW FILE######## __FILENAME__ = test_boom import unittest2 as unittest import subprocess import sys import shlex import StringIO import json