Skip to content

Commit 04e5fe4

Browse files
author
Matt Brandt
authored
Merge pull request #163 from terrameijar/develop
Added results filename to write to if user does not specify path
2 parents 6acfd23 + 0e02862 commit 04e5fe4

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

axe_selenium_python/axe.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,14 +98,15 @@ def write_results(self, data, name=None):
9898
Write JSON to file with the specified name.
9999
100100
:param name: Path to the file to be written to. If no path is passed
101-
a new file will be created.
101+
a new JSON file "results.json" will be created in the
102+
current working directory.
102103
:param output: JSON object.
103104
"""
104105

105106
if name:
106107
filepath = os.path.abspath(name)
107108
else:
108-
filepath = os.path.join(os.path.getcwd(), name)
109+
filepath = os.path.join(os.path.getcwd(), "results.json")
109110

110111
with open(filepath, "w", encoding="utf8") as f:
111112
try:

axe_selenium_python/tests/test_axe.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# You can obtain one at http://mozilla.org/MPL/2.0/.
44

55
import json
6-
from os import getenv, path
6+
from os import getcwd, getenv, path
77

88
import pytest
99
from selenium import webdriver
@@ -76,3 +76,17 @@ def test_write_results_to_file(tmpdir, mocker):
7676
actual_file_contents = json.loads(f.read())
7777

7878
assert data == actual_file_contents
79+
80+
81+
def test_write_results_without_filepath(mocker):
82+
axe = Axe(mocker.MagicMock())
83+
data = {"testKey": "testValue"}
84+
cwd = getcwd()
85+
filename = path.join(cwd, "results.json")
86+
87+
axe.write_results(data, filename)
88+
with open(filename) as f:
89+
actual_file_contents = json.loads(f.read())
90+
91+
assert data == actual_file_contents
92+
assert path.dirname(filename) == cwd

0 commit comments

Comments
 (0)