22# License, v. 2.0. If a copy of the MPL was not distributed with this file,
33# You can obtain one at http://mozilla.org/MPL/2.0/.
44
5- import os
6- import re
7- import sys
8- import time
9-
5+ from os import path
106import pytest
117
128
139@pytest .mark .nondestructive
14- def test_rules (axe ):
10+ def test_get_rules (axe ):
1511 """Assert number of rule tests matches number of available rules."""
1612 axe .inject ()
1713 rules = axe .get_rules ()
@@ -27,39 +23,28 @@ def test_execute(axe):
2723
2824
2925@pytest .mark .nondestructive
30- def test_write_results (base_url , axe ):
31- """Write JSON results to file."""
32- # get string of current python version
33- version = 'v' + str (sys .version_info [0 ]) + '_' + \
34- str (sys .version_info [1 ]) + '_' + str (sys .version_info [2 ])
35- # strip protocol and dots
36- filename = re .sub ('(http:\/\/|https:\/\/|\.php|\.asp|\.html)' , '' , base_url )
37- # replace slashes with underscores
38- filename = re .sub ('(\/|\.)' , '_' , filename )
39- # create filename "examplecom-datetime-python-version.json"
40- filename += '-' + time .strftime ('%m-%d-%y-%X' ) + '-' + version + '.json'
41-
42- axe .inject ()
43- data = axe .execute ()
44- axe .write_results (filename , data )
45- # check that file exists and is not empty
46- assert os .path .exists (filename ) and os .path .getsize (filename ) > 0 , \
47- 'Output file not found.'
48-
49-
50- @pytest .mark .nondestructive
51- def test_violations (axe ):
52- """Assert that no violations were found."""
26+ def test_run (base_url , axe ):
27+ """Assert that run method returns results."""
5328 violations = axe .run ()
54-
55- report = axe .report (violations )
56- assert len (violations ) == 0 , report
29+ assert violations is not None
5730
5831
5932@pytest .mark .nondestructive
6033def test_report (axe ):
61- """Test that report exists"""
34+ """Test that report exists. """
6235 violations = axe .run ()
6336
6437 report = axe .report (violations )
6538 assert report is not None , report
39+
40+
41+ @pytest .mark .nondestructive
42+ def test_write_results (base_url , axe ):
43+ """Assert that write results method creates a file."""
44+ axe .inject ()
45+ data = axe .execute ()
46+ filename = 'results.json'
47+ axe .write_results (filename , data )
48+ # check that file exists and is not empty
49+ assert path .exists (filename ), 'Output file not found.'
50+ assert path .getsize (filename ) > 0 , 'File contains no data.'
0 commit comments