Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions axe_selenium_python/axe.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,15 @@ 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.
"""

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:
Expand Down
16 changes: 15 additions & 1 deletion axe_selenium_python/tests/test_axe.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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