Skip to content

Commit

Permalink
Merge pull request Webperf-se#355 from cockroacher/i328
Browse files Browse the repository at this point in the history
pylint issue Webperf-se#328
  • Loading branch information
7h3Rabbit authored Apr 1, 2024
2 parents e77e3ff + ceb8055 commit da08232
Show file tree
Hide file tree
Showing 22 changed files with 653 additions and 403 deletions.
3 changes: 1 addition & 2 deletions default.py
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,6 @@ def try_load_language(self, arg):
Raises:
SystemExit: This function ends the program if the specified language is not available.
"""
lang_code = 'en'
available_languages = []
locale_dirs = os.listdir('locales')
found_lang = False
Expand All @@ -395,7 +394,7 @@ def try_load_language(self, arg):
self.lang_code = arg
found_lang = True

self.load_language(lang_code)
self.load_language(self.lang_code)

if not found_lang:
# Not translateable
Expand Down
8 changes: 2 additions & 6 deletions tests/a11y_lighthouse.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
# -*- coding: utf-8 -*-
from datetime import datetime
import gettext
from tests.lighthouse_base import run_test as lighthouse_base_run_test
from tests.utils import get_config_or_default
from tests.utils import get_config_or_default, get_translation

# DEFAULTS
GOOGLEPAGESPEEDAPIKEY = get_config_or_default('googlePageSpeedApiKey')
Expand All @@ -11,10 +10,7 @@

def run_test(global_translation, lang_code, url, strategy='mobile', category='accessibility'):

language = gettext.translation(
'a11y_lighthouse', localedir='locales', languages=[lang_code])
language.install()
local_translation = language.gettext
local_translation = get_translation('a11y_lighthouse', lang_code)

print(local_translation('TEXT_RUNNING_TEST'))

Expand Down
9 changes: 2 additions & 7 deletions tests/a11y_pa11y.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@
import subprocess
from datetime import datetime
import json
import gettext
from tests.utils import get_config_or_default
from tests.utils import get_config_or_default, get_translation
from models import Rating
_ = gettext.gettext

review_show_improvements_only = get_config_or_default('review_show_improvements_only')
request_timeout = get_config_or_default('http_request_timeout')
Expand All @@ -16,10 +14,7 @@ def run_test(global_translation, lang_code, url):
"""

language = gettext.translation(
'a11y_pa11y', localedir='locales', languages=[lang_code])
language.install()
local_translation = language.gettext
local_translation = get_translation('a11y_pa11y', lang_code)

print(local_translation('TEXT_RUNNING_TEST'))

Expand Down
9 changes: 2 additions & 7 deletions tests/a11y_statement.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@
from datetime import datetime, timedelta
import time
import urllib.parse
import gettext
from bs4 import BeautifulSoup
from models import Rating
from tests.utils import get_http_content, get_config_or_default
_ = gettext.gettext
from tests.utils import get_http_content, get_config_or_default, get_translation

review_show_improvements_only = get_config_or_default('review_show_improvements_only')
checked_urls = {}
Expand All @@ -20,10 +18,7 @@ def run_test(global_translation, lang_code, url):
"""

language = gettext.translation(
'a11y_statement', localedir='locales', languages=[lang_code])
language.install()
local_translation = language.gettext
local_translation = get_translation('a11y_statement', lang_code)

print(local_translation('TEXT_RUNNING_TEST'))

Expand Down
9 changes: 2 additions & 7 deletions tests/best_practice_lighthouse.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
# -*- coding: utf-8 -*-
from datetime import datetime
import gettext
from tests.lighthouse_base import run_test as lighthouse_base_run_test
from tests.utils import get_config_or_default
_local = gettext.gettext
from tests.utils import get_config_or_default, get_translation

# DEFAULTS
googlePageSpeedApiKey = get_config_or_default('googlePageSpeedApiKey')
Expand All @@ -12,10 +10,7 @@


def run_test(global_translation, lang_code, url, strategy='mobile', category='best-practices'):
language = gettext.translation(
'best_practice_lighthouse', localedir='locales', languages=[lang_code])
language.install()
local_translation = language.gettext
local_translation = get_translation('best_practice_lighthouse', lang_code)

print(local_translation('TEXT_RUNNING_TEST'))

Expand Down
10 changes: 2 additions & 8 deletions tests/css_validator_w3c.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# -*- coding: utf-8 -*-
from datetime import datetime
import gettext
import os
import re
import sys
Expand All @@ -9,12 +8,10 @@
from bs4 import BeautifulSoup
from models import Rating

from tests.utils import get_friendly_url_name, get_http_content, set_cache_file, get_config_or_default
from tests.utils import get_friendly_url_name, get_http_content, get_translation, set_cache_file, get_config_or_default
from tests.w3c_base import get_errors, identify_files
from tests.sitespeed_base import get_result

_local = gettext.gettext

# DEFAULTS
REQUEST_TIMEOUT = get_config_or_default('http_request_timeout')
USERAGENT = get_config_or_default('useragent')
Expand All @@ -37,10 +34,7 @@ def run_test(global_translation, lang_code, url):

rating = Rating(global_translation, REVIEW_SHOW_IMPROVEMENTS_ONLY)

language = gettext.translation(
'css_validator_w3c', localedir='locales', languages=[lang_code])
language.install()
local_translation = language.gettext
local_translation = get_translation('css_validator_w3c', lang_code)

print(local_translation('TEXT_RUNNING_TEST'))

Expand Down
10 changes: 3 additions & 7 deletions tests/email_validator.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# -*- coding: utf-8 -*-
import re
import gettext
import smtplib
from datetime import datetime
import socket
Expand All @@ -15,8 +14,8 @@
import dns
from models import Rating
from tests.utils import dns_lookup, get_best_country_code, \
get_http_content, is_country_code_in_eu_or_on_exception_list, get_config_or_default
_local = gettext.gettext
get_http_content, get_translation, \
is_country_code_in_eu_or_on_exception_list, get_config_or_default

# DEFAULTS
request_timeout = get_config_or_default('http_request_timeout')
Expand Down Expand Up @@ -133,10 +132,7 @@ def run_test(global_translation, lang_code, url):
# rating = Rating(global_translation, review_show_improvements_only)
result_dict = {}

language = gettext.translation(
'email_validator', localedir='locales', languages=[lang_code])
language.install()
local_translation = language.gettext
local_translation = get_translation('email_validator', lang_code)

print(local_translation('TEXT_RUNNING_TEST'))

Expand Down
8 changes: 2 additions & 6 deletions tests/energy_efficiency.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
# -*- coding: utf-8 -*-
from datetime import datetime
import gettext
import tests.energy_efficiency_carbon_percentiles as energy_efficiency_carbon_percentiles
import tests.energy_efficiency_carbon_percentiles2022 as energy_efficiency_carbon_percentiles_2022
from tests.performance_lighthouse import run_test as lighthouse_perf_run_test
from models import Rating
_local = gettext.gettext
from tests.utils import get_translation

# Code below is built from: https://gitlab.com/wholegrain/carbon-api-2-0

Expand Down Expand Up @@ -82,10 +81,7 @@ def run_test(global_translation, lang_code, url):
https://gitlab.com/wholegrain/carbon-api-2-0
"""

language = gettext.translation(
'energy_efficiency_websitecarbon', localedir='locales', languages=[lang_code])
language.install()
local_translation = language.gettext
local_translation = get_translation('energy_efficiency_websitecarbon', lang_code)

print(local_translation("TEXT_RUNNING_TEST"))

Expand Down
26 changes: 10 additions & 16 deletions tests/energy_efficiency_websitecarbon.py
Original file line number Diff line number Diff line change
@@ -1,33 +1,26 @@
# -*- coding: utf-8 -*-
from models import Rating
from datetime import datetime
import json
from decimal import Decimal
from models import Rating
from tests.utils import get_http_content, get_translation

from tests.utils import *
import gettext
_local = gettext.gettext


def run_test(global_translation, langCode, url):
def run_test(global_translation, lang_code, url):
"""
Analyzes URL with Website Carbon Calculator API.
API documentation: https://api.websitecarbon.com
https://gitlab.com/wholegrain/carbon-api-2-0
"""

language = gettext.translation(
'energy_efficiency_websitecarbon', localedir='locales', languages=[langCode])
language.install()
_local = language.gettext
local_translation = get_translation('energy_efficiency_websitecarbon', lang_code)

print(local_translation("TEXT_RUNNING_TEST"))

print(global_translation('TEXT_TEST_START').format(
datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')))
datetime.now().strftime('%Y-%m-%d %H:%M:%S')))

result_json = get_http_content(
'https://api.websitecarbon.com/site?url={0}'.format(url))
f'https://api.websitecarbon.com/site?url={url}')
result_dict = json.loads(result_json)

# print(result_json)
Expand All @@ -45,8 +38,9 @@ def run_test(global_translation, langCode, url):

# handicap points
co2_with_handicap = float(co2) - 0.8
points = 5 - co2_with_handicap

points = float("{0:.2f}".format(5 - co2_with_handicap))
points = float("{points:.2f}")

# print(points)

Expand All @@ -68,10 +62,10 @@ def run_test(global_translation, langCode, url):
elif 'true' in green.lower():
review += local_translation("TEXT_GREEN_ENERGY_TRUE")

rating = Rating(_)
rating = Rating(global_translation)
rating.set_overall(points, review)

print(global_translation('TEXT_TEST_END').format(
datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S')))
datetime.now().strftime('%Y-%m-%d %H:%M:%S')))

return (rating, result_dict)
9 changes: 2 additions & 7 deletions tests/frontend_quality_yellow_lab_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@
import time
from datetime import datetime
import json
import gettext
import requests
from tests.utils import get_config_or_default, get_http_content
from tests.utils import get_config_or_default, get_http_content, get_translation
from models import Rating
_local = gettext.gettext

# DEFAULTS
REQUEST_TIMEOUT = get_config_or_default('http_request_timeout')
Expand All @@ -25,10 +23,7 @@ def run_test(global_translation, lang_code, url, device='phone'):
Devices might be; phone, tablet, desktop
"""

language = gettext.translation(
'frontend_quality_yellow_lab_tools', localedir='locales', languages=[lang_code])
language.install()
local_translation = language.gettext
local_translation = get_translation('frontend_quality_yellow_lab_tools', lang_code)

rating = Rating(global_translation, REVIEW_SHOW_IMPROVEMENTS_ONLY)

Expand Down
9 changes: 2 additions & 7 deletions tests/html_validator_w3c.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@
import os
from datetime import datetime
import re
import gettext
from models import Rating
from tests.utils import get_config_or_default, get_friendly_url_name, set_cache_file
from tests.utils import get_config_or_default, get_friendly_url_name, get_translation, set_cache_file
from tests.w3c_base import get_errors, identify_files
from tests.sitespeed_base import get_result
_local = gettext.gettext

# DEFAULTS
REQUEST_TIMEOUT = get_config_or_default('http_request_timeout')
Expand All @@ -28,10 +26,7 @@ def run_test(global_translation, lang_code, url):
points = 0.0
review = ''

language = gettext.translation(
'html_validator_w3c', localedir='locales', languages=[lang_code])
language.install()
local_translation = language.gettext
local_translation = get_translation('html_validator_w3c', lang_code)

print(local_translation('TEXT_RUNNING_TEST'))

Expand Down
9 changes: 2 additions & 7 deletions tests/http_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# https://docs.python.org/3/library/urllib.parse.html
import urllib
from models import Rating
from tests.utils import change_url_to_test_url, dns_lookup, merge_dicts, get_config_or_default
from tests.utils import change_url_to_test_url, dns_lookup, get_translation, merge_dicts, get_config_or_default
from tests.sitespeed_base import get_result
import dns.name
import dns.query
Expand All @@ -23,8 +23,6 @@
import dns.rdatatype
import hashlib
import base64
import gettext
_local = gettext.gettext


# DEFAULTS
Expand All @@ -50,10 +48,7 @@ def run_test(global_translation, lang_code, url):

result_dict = {}

language = gettext.translation(
'http_validator', localedir='locales', languages=[lang_code])
language.install()
local_translation = language.gettext
local_translation = get_translation('http_validator', lang_code)

if USE_CSP_ONLY:
print(local_translation('TEXT_RUNNING_TEST_CSP_ONLY'))
Expand Down
9 changes: 2 additions & 7 deletions tests/page_not_found.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@
import sys
from datetime import datetime
import urllib # https://docs.python.org/3/library/urllib.parse.html
import gettext
import requests
from bs4 import BeautifulSoup
from models import Rating
from tests.utils import get_config_or_default, get_guid, get_http_content
_ = gettext.gettext
from tests.utils import get_config_or_default, get_guid, get_http_content, get_translation

# DEFAULTS
REQUEST_TIMEOUT = get_config_or_default('http_request_timeout')
Expand Down Expand Up @@ -39,10 +37,7 @@ def run_test(global_translation, lang_code, org_url):
rating = Rating(global_translation)
result_dict = {}

language = gettext.translation(
'page_not_found', localedir='locales', languages=[lang_code])
language.install()
local_translation = language.gettext
local_translation = get_translation('page_not_found', lang_code)

print(local_translation('TEXT_RUNNING_TEST'))

Expand Down
9 changes: 2 additions & 7 deletions tests/performance_lighthouse.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
# -*- coding: utf-8 -*-
from datetime import datetime
import gettext
from tests.lighthouse_base import run_test as lighthouse_base_run_test
from tests.utils import get_config_or_default
_local = gettext.gettext
from tests.utils import get_config_or_default, get_translation

# DEFAULTS
googlePageSpeedApiKey = get_config_or_default('googlePageSpeedApiKey')
Expand All @@ -22,10 +20,7 @@ def run_test(global_translation, lang_code, url, silance=False):
seo = https://www.googleapis.com/pagespeedonline/v5/runPagespeed?category=seo&strategy=mobile&url=YOUR-SITE&key=YOUR-KEY
"""

language = gettext.translation(
'performance_lighthouse', localedir='locales', languages=[lang_code])
language.install()
local_translation = language.gettext
local_translation = get_translation('performance_lighthouse', lang_code)

if not silance:
print(local_translation('TEXT_RUNNING_TEST'))
Expand Down
Loading

0 comments on commit da08232

Please sign in to comment.