From 05f21fbfb9fe75e9098c63cb07bf68b356fa3bd7 Mon Sep 17 00:00:00 2001 From: Kimberly Date: Tue, 23 Oct 2018 10:42:47 -0600 Subject: [PATCH] updated write_results method to create a path object to support recent changes, updated readme to match --- README.rst | 5 +++-- axe_selenium_python/axe.py | 10 ++++++---- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/README.rst b/README.rst index cd885b5..b9568b5 100755 --- a/README.rst +++ b/README.rst @@ -47,7 +47,8 @@ Usage .. code-block:: python - import pytest + import pytest + import os from selenium import webdriver from axe_selenium_python import Axe @@ -60,7 +61,7 @@ Usage # Run axe accessibility checks. results = axe.execute() # Write results to file - axe.write_results('a11y.json', results) + axe.write_results(results, 'a11y.json') driver.close() # Assert no violations are found assert len(results["violations"]) == 0, axe.report(results["violations"]) diff --git a/axe_selenium_python/axe.py b/axe_selenium_python/axe.py index fe9760b..c8bc6ef 100755 --- a/axe_selenium_python/axe.py +++ b/axe_selenium_python/axe.py @@ -3,11 +3,11 @@ # file, You can obtain one at http://mozilla.org/MPL/2.0/. import json +import os from io import open -from os import path -_DEFAULT_SCRIPT = path.join( - path.dirname(__file__), "node_modules", "axe-core", "axe.min.js" +_DEFAULT_SCRIPT = os.path.join( + os.path.dirname(__file__), "node_modules", "axe-core", "axe.min.js" ) @@ -100,7 +100,9 @@ def write_results(self, data, name="results.json"): :param name: Name of file to be written to. :param output: JSON object. """ - with open(name, "w", encoding="utf8") as f: + filepath = os.path.join(os.getcwd(), name) + + with open(filepath, "w", encoding="utf8") as f: try: f.write(unicode(json.dumps(data, indent=4))) except NameError: