Skip to content
Closed
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
2 changes: 1 addition & 1 deletion axe_selenium_python/axe.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,5 +100,5 @@ def write_results(self, data, name="results.json"):
:param name: Name of file to be written to.
:param output: JSON object.
"""
with open(name, "r", encoding="utf8") as f:
with open(name, "w", encoding="utf8") as f:
f.write(json.dumps(data, indent=4))
24 changes: 24 additions & 0 deletions axe_selenium_python/tests/test_axe.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

from os import path, getenv

import json
import pytest
from unittest import mock
from selenium import webdriver

from ..axe import Axe
Expand Down Expand Up @@ -62,3 +64,25 @@ def _perform_axe_run(driver):
axe.inject()
data = axe.execute()
return data


@pytest.fixture
def tempdir():
import tempfile
import shutil
new_dir = tempfile.mkdtemp()
yield new_dir
shutil.rmtree(new_dir)


def test_write_results_to_file(tempdir):
axe = Axe(mock.MagicMock())
data = json.dumps({"testKey": "testValue"})
filename = path.join(tempdir, "results.json")

axe.write_results(data=data, name=filename)

with open(filename) as f:
actual_file_contents = json.loads(f.read())

assert data == actual_file_contents