Skip to content

Commit

Permalink
Merge pull request Webperf-se#681 from Webperf-se/w3c-css-sources
Browse files Browse the repository at this point in the history
Include what urls was tested in CSS Test in Data object
  • Loading branch information
7h3Rabbit authored Oct 26, 2024
2 parents 41e791f + 42d1d91 commit 4649201
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
17 changes: 14 additions & 3 deletions tests/css_validator_w3c.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ def run_test(global_translation, url):
'style_element': [],
'style_attribute': [],
'style_files': []
}
},
'sources': []
}

for html_entry in data['htmls']:
Expand All @@ -59,6 +60,14 @@ def run_test(global_translation, url):
rating += tmp_rating
all_link_resources.extend(tmp_all_link_resources)

for resource_url in all_link_resources:
for entry in data['all']:
if resource_url == entry['url']:
result_dict['sources'].append({
'url': resource_url,
'index': entry['index']
})

# 4 Check if website inlcuded css files in other ways
for link_resource in all_link_resources:
data_resource_info_to_remove = None
Expand Down Expand Up @@ -123,8 +132,10 @@ def handle_html_markup_entry(entry, global_translation, url, local_translation,
local_translation,
f'- `style=""` in: {name}')

# 2.3 GET ERRORS FROM SERVICE
# 2.4 CALCULATE SCORE
if 'has_style_elements' in result_dict or\
'has_style_attributes' in result_dict:
all_link_resources.append(req_url)

# 3 FIND ALL <LINK> (rel=\"stylesheet\")
(link_resources, errors) = get_errors_for_link_tags(html, url)
if len(link_resources) > 0:
Expand Down
13 changes: 9 additions & 4 deletions tests/w3c_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ def identify_files(filename):
"""

data = {
'all': [],
'htmls': [],
'elements': [],
'attributes': [],
Expand Down Expand Up @@ -187,22 +188,26 @@ def identify_files(filename):
True,
timedelta(minutes=get_config('general.cache.max-age'))):
set_cache_file(req_url, res['content']['text'], True)
data['htmls'].append({
obj = {
'url': req_url,
'content': res['content']['text'],
'index': req_index
})
}
data['all'].append(obj)
data['htmls'].append(obj)
elif 'css' in res['content']['mimeType']:
if not has_cache_file(
req_url,
True,
timedelta(minutes=get_config('general.cache.max-age'))):
set_cache_file(req_url, res['content']['text'], True)
data['resources'].append({
obj = {
'url': req_url,
'content': res['content']['text'],
'index': req_index
})
}
data['all'].append(obj)
data['resources'].append(obj)
req_index += 1

return data
Expand Down

0 comments on commit 4649201

Please sign in to comment.