Skip to content

Commit

Permalink
started custom action unused action report.
Browse files Browse the repository at this point in the history
  • Loading branch information
heynemann committed May 10, 2010
1 parent 8b80454 commit b40f34f
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
3 changes: 3 additions & 0 deletions pyccuracy/actions/__init__.py
Expand Up @@ -133,3 +133,6 @@ def assert_element_is_not_visible(self, context, selector, message):
if self.is_element_visible(context, selector):
raise self.failed(message + "(Resolved to Element %s)" % selector)

@classmethod
def all(cls):
return ACTIONS
26 changes: 25 additions & 1 deletion pyccuracy/core.py
Expand Up @@ -23,6 +23,7 @@
from pyccuracy.airspeed import Template

from pyccuracy import Page, ActionBase
from pyccuracy.actions import MetaActionBase
from pyccuracy.common import Settings, Context, locate, Status
from pyccuracy.story_runner import *
from pyccuracy.parsers import FileParser, ActionNotFoundError
Expand Down Expand Up @@ -78,6 +79,16 @@ def run_tests(self, context=None, fso=None, **kwargs):
else:
return None

if len(self.parser.used_actions) != len(ActionBase.all()):
unused_actions = []
for action in ActionBase.all():
if action.__class__.__name__ in ('ActionBase', 'MetaActionBase'):
continue
if action not in self.parser.used_actions:
unused_actions.append(action.__class__.__name__)
if unused_actions:
self.print_unused_actions_warning(unused_actions)

if not fixture.stories:
results = Result(fixture)
self.print_results(context.settings.default_culture, results)
Expand Down Expand Up @@ -110,10 +121,23 @@ def run_tests(self, context=None, fso=None, **kwargs):
self.print_results(context.settings.default_culture, results)
return results


def print_unused_actions_warning(self, unused_actions):
template = """${YELLOW}WARNING!
------------
The following actions are never used:
*%s
------------
${NORMAL}
"""
ctrl = TerminalController()
print ctrl.render(template % "\n *".join(unused_actions))

def print_lxml_import_error(self):
template = """${RED}REPORT ERROR
------------
Sorry, but you need to install lxml (python-lxml in aptitude)
Sorry, but you need to install lxml (python-lxml in aptitude or easy_install lxml)
before using the report feature in pyccuracy.
If you do not need a report use the -R=false parameter.
${NORMAL}
Expand Down
5 changes: 5 additions & 0 deletions pyccuracy/parsers.py
Expand Up @@ -42,6 +42,7 @@ def __init__(self, language=None, file_object=None, action_registry=None):
self.file_object = file_object and file_object or FSO()
self.action_registry = action_registry and action_registry or ActionRegistry
self.language = language
self.used_actions = []

def get_stories(self, settings):
if not self.language:
Expand Down Expand Up @@ -113,6 +114,10 @@ def parse_story_file(self, story_file_path, settings):

if not action:
self.raise_action_not_found_for_line(line, current_scenario, story_file_path)

if not action in self.used_actions:
self.used_actions.append(action)

instance = action()
if kwargs:
args = []
Expand Down

0 comments on commit b40f34f

Please sign in to comment.