Skip to content

Commit

Permalink
Merge pull request #342 from cockroacher/i331
Browse files Browse the repository at this point in the history
pylint of issue #331
  • Loading branch information
7h3Rabbit authored Mar 25, 2024
2 parents 184a9aa + 994f373 commit c79f5b4
Showing 1 changed file with 46 additions and 7 deletions.
53 changes: 46 additions & 7 deletions tests/w3c_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,25 @@


def get_errors(test_type, params):
"""
This function takes a test type and parameters as input and
returns any errors found during the test.
The function checks if the test type is 'css' or 'html' and
sets the test arguments accordingly.
It then checks if a document URL is provided in the parameters.
If the URL does not start with 'https://' or 'http://', it raises a ValueError.
It then checks if the file is cached and if not, it caches the file.
It then runs a command using the vnu.jar validator and returns any errors found.
Parameters:
test_type (str): The type of the test to be run. It can be 'css' or 'html'.
params (dict): A dictionary containing the parameters for the test.
It should contain a 'doc' key with the URL of the document to be tested.
Returns:
list: A list of dictionaries where each dictionary represents an error message.
"""

url = ''
arg = ''
Expand All @@ -31,20 +50,20 @@ def get_errors(test_type, params):
url = params['doc']

if 'https://' not in url and 'http://' not in url:
raise Exception(
'Tested url must start with \'https://\' or \'http://\': {0}'.format(url))
raise ValueError(
f'Tested url must start with \'https://\' or \'http://\': {url}')

file_path = get_cache_path(url, True)
if is_html:
html_file_ending_fix = file_path.replace('.cache', '.cache.html')
if has_cache_file(url, True, CACHE_TIME_DELTA) and not os.path.exists(html_file_ending_fix):
if has_cache_file(url, True, CACHE_TIME_DELTA) \
and not os.path.exists(html_file_ending_fix):
os.rename(file_path, html_file_ending_fix)
file_path = html_file_ending_fix

arg = '--exit-zero-always{1} --stdout --format json --errors-only {0}'.format(
file_path, test_arg)
arg = f'--exit-zero-always{test_arg} --stdout --format json --errors-only {file_path}'

command = "java -jar vnu.jar {0}".format(arg)
command = f'java -jar vnu.jar {arg}'
process = subprocess.Popen(command.split(), stdout=subprocess.PIPE)
output, _ = process.communicate(timeout=REQUEST_TIMEOUT * 10)

Expand All @@ -55,14 +74,34 @@ def get_errors(test_type, params):
return errors

def identify_files(filename):
"""
This function takes a filename as input and identifies different types of files in the HAR data.
The function reads the HAR data from the file, iterates over the entries,
and categorizes them into HTML and CSS files.
It also checks if the file is already cached and if not, it caches the file.
Parameters:
filename (str): The name of the file containing the HAR data.
Returns:
dict: A dictionary containing categorized file data.
The dictionary has four keys - 'htmls', 'elements', 'attributes', and 'resources'.
Each key maps to a list of dictionaries where each dictionary contains:
- 'url',
- 'content'
- 'index'
of the file.
"""

data = {
'htmls': [],
'elements': [],
'attributes': [],
'resources': []
}

with open(filename) as json_input_file:
with open(filename, encoding='utf-8') as json_input_file:
har_data = json.load(json_input_file)

if 'log' in har_data:
Expand Down

0 comments on commit c79f5b4

Please sign in to comment.