Skip to content

Commit

Permalink
sketch out runners
Browse files Browse the repository at this point in the history
  • Loading branch information
tswicegood committed Jan 28, 2012
1 parent ba7d51e commit 680fc8e
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 0 deletions.
14 changes: 14 additions & 0 deletions maxixe/gherkin.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,18 @@ def __init__(self, description, scenario):
self.description = description
self.scenario = scenario

@property
def successful(self):
return False

@property
def skipped(self):
return False

@property
def failed(self):
return False

@property
def has_run(self):
return False
Expand All @@ -18,6 +30,8 @@ def has_run(self):
def runnable(self):
return utils.has_matching_step(self)

def run(self):
pass

class Scenario(object):
def __init__(self, name, feature):
Expand Down
68 changes: 68 additions & 0 deletions maxixe/runners/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
from clint.textui import indent, puts


# TODO: move this to the correct home
class TextReporter(object):
def __init__(self):
self.current_indent = 2

def indent(self):
self.current_indent += 2

def dedent(self):
self.current_indent -= 2

def start_feature(self, feature):
with indent(self.current_indent):
puts("Feature: %s" % feature.name)
with indent(self.current_indent + 2):
puts(feature.description)
print ""
self.indent()

def stop_feature(self, feature):
self.dedent()

def start_scenario(self, scenario):
with indent(self.current_indent):
puts("Scenario: %s" % scenario.name)
self.indent()

def stop_scenario(self, scenario):
print ""
self.dedent()

def start_step(self, step):
pass

def stop_step(self, step):
with indent(self.current_indent):
if step.successful:
suffix = "OK!"
elif step.skipped:
suffix = "SKIPPED"
elif step.failed:
suffix = "FAILED"
else:
suffix = "UNKNOWN"
puts("%s [%s]" % (step.description, suffix))


class Runner(object):
def __init__(self, reporter):
self.reporter = reporter

def run(self, feature):
self.reporter.start_feature(feature)
for scenario in feature.scenarios:
self.run_scenario(scenario)
self.reporter.stop_feature(feature)

def run_scenario(self, scenario):
self.reporter.start_scenario(scenario)
continue_running = True
for step in scenario.steps:
self.reporter.start_step(step)
step.run()
self.reporter.stop_step(step)
self.reporter.stop_scenario(scenario)

0 comments on commit 680fc8e

Please sign in to comment.