Skip to content

Commit

Permalink
Fix inheritances
Browse files Browse the repository at this point in the history
  • Loading branch information
fornellas authored and fabriziocucci committed Apr 21, 2020
1 parent 653b92f commit e04f65c
Showing 1 changed file with 40 additions and 15 deletions.
55 changes: 40 additions & 15 deletions testslide/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,12 @@
from contextlib import redirect_stdout, redirect_stderr


class BaseFormatter(object):
##
## Base
##


class BaseFormatter:
"""
Formatter base class. To be paired with Runner, to process / output example
execution results.
Expand All @@ -41,14 +46,6 @@ def __init__(
self.start_time = psutil.Process(os.getpid()).create_time()
self.end_time = None
self.duration_secs = None
if self.import_secs and self.import_secs > 1 and self._import_secs_warn:
self.print_yellow(
"Warning: Importing test modules alone took %.1fs! To remove this slow "
"down remove object construction from module level. If not possible, "
"consider using/ lazy_import(). Try using --import-profiler to profile "
"your imports." % (self.import_secs)
)
self._import_secs_warn = False

# Example Discovery

Expand Down Expand Up @@ -148,11 +145,12 @@ def dsl_function(self, example, code):
pass


class QuietFormatter(BaseFormatter):
pass
##
## Mixins
##


class ColorFormatter(BaseFormatter):
class ColorFormatterMixin(BaseFormatter):
def _print_attrs(self, attrs, *values, **kwargs):
stream = kwargs.get("file", sys.stdout)
if stream.isatty() or self.force_color:
Expand Down Expand Up @@ -181,6 +179,19 @@ def print_cyan(self, *values, **kwargs):
self._print_attrs("36", *values, **kwargs)


class SlowImportWarningMixin(ColorFormatterMixin):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
if self.import_secs and self.import_secs > 1 and self._import_secs_warn:
self.print_yellow(
"Warning: Importing test modules alone took %.1fs! To remove this slow "
"down remove object construction from module level. If not possible, "
"consider using/ lazy_import(). Try using --import-profiler to profile "
"your imports." % (self.import_secs)
)
self._import_secs_warn = False


class DSLDebugMixin:
def get_dsl_debug_indent(self, example):
return ""
Expand Down Expand Up @@ -237,7 +248,16 @@ def dsl_function(self, example, code):
self._dsl_print(example, "function", code)


class ProgressFormatter(DSLDebugMixin, ColorFormatter):
##
## Formatters
##


class QuietFormatter(BaseFormatter):
pass


class ProgressFormatter(DSLDebugMixin, SlowImportWarningMixin, ColorFormatterMixin):
"""
Simple formatter that outputs "." when an example passes or "F" w
"""
Expand All @@ -264,7 +284,7 @@ def finish(self, not_executed_examples):
print("")


class DocumentFormatter(DSLDebugMixin, ColorFormatter):
class DocumentFormatter(DSLDebugMixin, SlowImportWarningMixin, ColorFormatterMixin):
def get_dsl_debug_indent(self, example):
return " " * (example.context.depth + 1)

Expand Down Expand Up @@ -379,7 +399,7 @@ def finish(self, not_executed_examples):
self.print_cyan(" Not executed: ", len(not_executed_examples))


class LongFormatter(DSLDebugMixin, ColorFormatter):
class LongFormatter(DSLDebugMixin, SlowImportWarningMixin, ColorFormatterMixin):
def get_dsl_debug_indent(self, example):
return " "

Expand Down Expand Up @@ -505,6 +525,11 @@ def finish(self, not_executed_examples):
self.print_cyan(" Not executed: ", len(not_executed_examples))


##
## Runner
##


class Runner(object):
"""
Execute examples contained in given contexts.
Expand Down

0 comments on commit e04f65c

Please sign in to comment.