From dcdacf47e05078a041f40fcf4e540b7e6c765661 Mon Sep 17 00:00:00 2001 From: Kimberly Pennington Date: Mon, 4 Sep 2017 09:26:16 -0600 Subject: [PATCH] moved impact_included method inside Axe class --- axe_selenium_python/axe.py | 37 ++++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/axe_selenium_python/axe.py b/axe_selenium_python/axe.py index 73289cd..6bee4eb 100644 --- a/axe_selenium_python/axe.py +++ b/axe_selenium_python/axe.py @@ -8,22 +8,6 @@ _DEFAULT_SCRIPT = os.path.join(os.path.dirname(__file__), 'src', 'axe.min.js') -def impact_included(rule, impact): - if impact == 'minor' or impact is None: - return True - elif impact == 'moderate': - if rule['impact'] != 'minor': - return True - elif impact == 'severe': - if rule['impact'] == 'severe' or rule['impact'] == 'critical': - return True - elif impact == 'critical': - if rule['impact'] == 'critical': - return True - else: - return False - - class Axe(object): def __init__(self, selenium, script_url=_DEFAULT_SCRIPT): @@ -75,10 +59,29 @@ def run(self, context=None, options=None, impact=None): """ self.inject() data = self.execute(context, options) - violations = dict((rule['id'], rule) for rule in data['violations'] if impact_included(rule, impact)) + violations = dict((rule['id'], rule) for rule in data['violations'] if self.impact_included(rule, impact)) return violations + def impact_included(rule, impact): + """ + Function to filter for violations iwht specified impact level, and all + violations with a higher impact level. + """ + if impact == 'minor' or impact is None: + return True + elif impact == 'moderate': + if rule['impact'] != 'minor': + return True + elif impact == 'severe': + if rule['impact'] == 'severe' or rule['impact'] == 'critical': + return True + elif impact == 'critical': + if rule['impact'] == 'critical': + return True + else: + return False + def report(self, violations): """ Return readable report of accessibility violations found.