From ac3d797dff2a84c9882c6595002886b06a024f40 Mon Sep 17 00:00:00 2001 From: Vuyisile Ndlovu Date: Fri, 26 Oct 2018 10:56:19 +0200 Subject: [PATCH 1/7] Allows write_results to take a path --- axe_selenium_python/axe.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/axe_selenium_python/axe.py b/axe_selenium_python/axe.py index c8bc6ef..e08cd71 100755 --- a/axe_selenium_python/axe.py +++ b/axe_selenium_python/axe.py @@ -93,17 +93,19 @@ def report(self, violations): string += "\n\n\n" return string - def write_results(self, data, name="results.json"): + def write_results(self, data, name): """ Write JSON to file with the specified name. :param name: Name of file to be written to. :param output: JSON object. """ - filepath = os.path.join(os.getcwd(), name) + filepath = os.path.abspath(name) with open(filepath, "w", encoding="utf8") as f: try: f.write(unicode(json.dumps(data, indent=4))) except NameError: f.write(json.dumps(data, indent=4)) + except FileNotFoundError as fnf_error: + print(fnf_error) \ No newline at end of file From c42aa7dae39bee206616a9b1ecac11cf12ef4b4b Mon Sep 17 00:00:00 2001 From: Vuyisile Ndlovu Date: Fri, 26 Oct 2018 11:02:51 +0200 Subject: [PATCH 2/7] fixed pep8 issues --- axe_selenium_python/axe.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/axe_selenium_python/axe.py b/axe_selenium_python/axe.py index e08cd71..07da0fb 100755 --- a/axe_selenium_python/axe.py +++ b/axe_selenium_python/axe.py @@ -108,4 +108,4 @@ def write_results(self, data, name): except NameError: f.write(json.dumps(data, indent=4)) except FileNotFoundError as fnf_error: - print(fnf_error) \ No newline at end of file + print(fnf_error) From df1552f88923265a94662cca2c9c4f5950267e71 Mon Sep 17 00:00:00 2001 From: Vuyisile Ndlovu Date: Wed, 31 Oct 2018 08:43:16 +0200 Subject: [PATCH 3/7] Fixed default arguments and updated path handling logic --- axe_selenium_python/axe.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/axe_selenium_python/axe.py b/axe_selenium_python/axe.py index 07da0fb..0622d68 100755 --- a/axe_selenium_python/axe.py +++ b/axe_selenium_python/axe.py @@ -93,19 +93,22 @@ def report(self, violations): string += "\n\n\n" return string - def write_results(self, data, name): + def write_results(self, data, name=None): """ Write JSON to file with the specified name. - :param name: Name of file to be written to. + :param name: Path to the file to be written to. If no path is passed + a new file will be created. :param output: JSON object. """ - filepath = os.path.abspath(name) + + if name: + filepath = os.path.abspath(name) + else: + filepath = os.path.join(os.path.getcwd(), name) with open(filepath, "w", encoding="utf8") as f: try: f.write(unicode(json.dumps(data, indent=4))) except NameError: f.write(json.dumps(data, indent=4)) - except FileNotFoundError as fnf_error: - print(fnf_error) From b036ab3663cbd7d3d31f7b648d8232f2f8e2b03d Mon Sep 17 00:00:00 2001 From: Vuyisile Ndlovu Date: Thu, 8 Nov 2018 13:15:15 +0200 Subject: [PATCH 4/7] Added filename to write results to --- axe_selenium_python/axe.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/axe_selenium_python/axe.py b/axe_selenium_python/axe.py index 05b2a1b..9f30c26 100755 --- a/axe_selenium_python/axe.py +++ b/axe_selenium_python/axe.py @@ -105,7 +105,7 @@ def write_results(self, data, name=None): if name: filepath = os.path.abspath(name) else: - filepath = os.path.join(os.path.getcwd(), name) + filepath = os.path.join(os.path.getcwd(), "results.json") with open(filepath, "w", encoding="utf8") as f: try: From c96eb0c185fdedafe77ec2a11ff248bce3b714cd Mon Sep 17 00:00:00 2001 From: Vuyisile Ndlovu Date: Thu, 8 Nov 2018 16:13:19 +0200 Subject: [PATCH 5/7] Added test for writing results without filepath --- axe_selenium_python/tests/test_axe.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/axe_selenium_python/tests/test_axe.py b/axe_selenium_python/tests/test_axe.py index 692b1b7..a6d53e9 100755 --- a/axe_selenium_python/tests/test_axe.py +++ b/axe_selenium_python/tests/test_axe.py @@ -3,7 +3,7 @@ # You can obtain one at http://mozilla.org/MPL/2.0/. import json -from os import getenv, path +from os import getcwd, getenv, path import pytest from selenium import webdriver @@ -76,3 +76,17 @@ def test_write_results_to_file(tmpdir, mocker): actual_file_contents = json.loads(f.read()) assert data == actual_file_contents + + +def test_write_results_without_filepath(mocker): + axe = Axe(mocker.MagicMock()) + data = {"testKey": "testValue"} + cwd = getcwd() + filename = path.join(cwd, "results.json") + + axe.write_results(data, filename) + with open(filename) as f: + actual_file_contents = json.loads(f.read()) + + assert data == actual_file_contents + assert path.dirname(filename) == cwd From 89500bc18f57c814606505ee108d3f25e69fb365 Mon Sep 17 00:00:00 2001 From: Vuyisile Ndlovu Date: Fri, 9 Nov 2018 08:04:27 +0200 Subject: [PATCH 6/7] Updated write_results docstring --- axe_selenium_python/axe.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/axe_selenium_python/axe.py b/axe_selenium_python/axe.py index 9f30c26..f7fdc12 100755 --- a/axe_selenium_python/axe.py +++ b/axe_selenium_python/axe.py @@ -98,7 +98,8 @@ def write_results(self, data, name=None): Write JSON to file with the specified name. :param name: Path to the file to be written to. If no path is passed - a new file will be created. + a new JSON file "results.json" will be created in the + current working directory. :param output: JSON object. """ From 0e028627431fcd206c09d596553aa485b04427e8 Mon Sep 17 00:00:00 2001 From: Vuyisile Ndlovu Date: Thu, 15 Nov 2018 10:13:01 +0200 Subject: [PATCH 7/7] Fixed flake8 error --- axe_selenium_python/axe.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/axe_selenium_python/axe.py b/axe_selenium_python/axe.py index f7fdc12..b2fae3d 100755 --- a/axe_selenium_python/axe.py +++ b/axe_selenium_python/axe.py @@ -98,7 +98,7 @@ def write_results(self, data, name=None): Write JSON to file with the specified name. :param name: Path to the file to be written to. If no path is passed - a new JSON file "results.json" will be created in the + a new JSON file "results.json" will be created in the current working directory. :param output: JSON object. """