Skip to content

Commit 8783872

Browse files
authored
test: bypass html validation pending rework at template level (ietf-tools#3748)
1 parent 0024cc9 commit 8783872

2 files changed

Lines changed: 147 additions & 147 deletions

File tree

ietf/utils/test_runner.py

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
import datetime
4747
import gzip
4848
import unittest
49-
import subprocess
49+
#import subprocess
5050
import factory.random
5151
from fnmatch import fnmatch
5252

@@ -630,24 +630,24 @@ def setup_test_environment(self, **kwargs):
630630
except socket.error:
631631
pass
632632

633-
try:
634-
settings.VNU = subprocess.Popen(
635-
[
636-
"java",
637-
"-jar",
638-
"/vnu.jar",
639-
"-Dnu.validator.servlet.bind-address=127.0.0.1",
640-
"nu.validator.servlet.Main",
641-
"8888",
642-
],
643-
stdout=subprocess.DEVNULL,
644-
)
645-
print(" Starting Nu Html Checker (v.Nu) for HTML5 validation")
646-
except OSError:
647-
print(
648-
" Could not start Nu Html Checker (v.Nu), skipping most HTML5 validation"
649-
)
650-
settings.VNU = None
633+
# try:
634+
# settings.VNU = subprocess.Popen(
635+
# [
636+
# "java",
637+
# "-jar",
638+
# "/vnu.jar",
639+
# "-Dnu.validator.servlet.bind-address=127.0.0.1",
640+
# "nu.validator.servlet.Main",
641+
# "8888",
642+
# ],
643+
# stdout=subprocess.DEVNULL,
644+
# )
645+
# print(" Starting Nu Html Checker (v.Nu) for HTML5 validation")
646+
# except OSError:
647+
# print(
648+
# " Could not start Nu Html Checker (v.Nu), skipping most HTML5 validation"
649+
# )
650+
# settings.VNU = None
651651

652652
if os.path.exists(settings.UTILS_TEST_RANDOM_STATE_FILE):
653653
print(" Loading factory-boy random state from %s" % settings.UTILS_TEST_RANDOM_STATE_FILE)
@@ -665,8 +665,8 @@ def setup_test_environment(self, **kwargs):
665665

666666
def teardown_test_environment(self, **kwargs):
667667
self.smtpd_driver.stop()
668-
if settings.VNU:
669-
settings.VNU.terminate()
668+
# if settings.VNU:
669+
# settings.VNU.terminate()
670670
if self.check_coverage:
671671
latest_coverage_file = os.path.join(self.root_dir, settings.TEST_COVERAGE_LATEST_FILE)
672672
coverage_latest = {}

ietf/utils/test_utils.py

Lines changed: 126 additions & 126 deletions
Original file line numberDiff line numberDiff line change
@@ -41,18 +41,18 @@
4141
import requests_mock
4242
import shutil
4343
import sys
44-
import subprocess
44+
# import subprocess
4545

4646
from urllib.parse import unquote
4747
from unittest.util import strclass
4848
from bs4 import BeautifulSoup
4949
from contextlib import contextmanager
5050
from pathlib import Path
5151
from tempfile import NamedTemporaryFile
52-
from tidylib import tidy_document
52+
# from tidylib import tidy_document
5353

5454
import django.test
55-
from django.test.client import Client
55+
# from django.test.client import Client
5656
from django.conf import settings
5757
from django.utils.text import slugify
5858

@@ -156,128 +156,128 @@ def test_redirect_with_lazy_reverse(self):
156156
self.assertRedirects(response, "/ipr/", status_code=301)
157157

158158

159-
class VerifyingClient(Client):
160-
def __init__(self, test):
161-
super(VerifyingClient, self).__init__()
162-
self.test = test
163-
164-
def handle_error(self, path, source, errors):
165-
file_name = "error" + re.sub("/", "-", path)
166-
if not file_name.endswith("-"):
167-
file_name += "-"
168-
file_name += "source.html"
169-
with open(file_name, "w") as src:
170-
src.write(source)
171-
print("\nHTML validation error for URL path", path)
172-
print("HTML source saved to", file_name)
173-
print("See AssertionError below for error location in HTML source.")
174-
self.test.maxDiff = None
175-
self.test.assertEqual("", errors)
176-
177-
def get(self, path, *args, skip_verify=False, **extra):
178-
"""GET request
179-
180-
Performs verification of HTML responses unless skip_verify is True.
181-
"""
182-
r = super(VerifyingClient, self).get(path, *args, **extra)
183-
184-
if (
185-
skip_verify
186-
or r.status_code >= 300
187-
or not r["content-type"].lower().startswith("text/html")
188-
):
189-
return r
190-
source = r.content.decode()
191-
192-
if settings.VNU:
193-
# First, run through https://validator.github.io/validator/
194-
result = subprocess.run(
195-
["java", "-jar", "/vnu.jar", "nu.validator.client.HttpClient", "-"],
196-
input=r.content,
197-
stdout=subprocess.PIPE,
198-
stderr=subprocess.DEVNULL,
199-
)
200-
errors = result.stdout.decode()
201-
202-
if errors:
203-
msg = ""
204-
for err in errors.splitlines():
205-
# TODO: check if some can be removed after validating database templates
206-
if (
207-
re.match(r'.*Attribute "required" not allowed', err)
208-
or re.match(
209-
r'.*The "type" attribute is unnecessary for JavaScript', err
210-
)
211-
or re.match(
212-
r'.*Element "option" without attribute "label" must not be empty',
213-
err,
214-
)
215-
or re.match(r".*The character encoding was not declared", err)
216-
or re.match(r".*Consider avoiding viewport values", err)
217-
or re.match(
218-
r'.*The value of the "for" attribute of the "label" element must be the ID of a non-hidden form control',
219-
err,
220-
)
221-
or re.match(r".*is not in Unicode Normalization Form C", err)
222-
):
223-
continue
224-
# ignore some errors about obsolete HTML coming from the database
225-
if re.match(
226-
r"/meeting/\d+/proceedings/overview/", path
227-
) and re.match(
228-
r'.*The "\w+" attribute on the "\w+" element is obsolete', err
229-
):
230-
continue
231-
# ignore some errors coming from outdated but still-needed iframes
232-
if re.match(r"/meeting/\d+/week-view", path) and re.match(
233-
r".*Start tag seen without seeing a doctype first", err
234-
):
235-
continue
236-
pos = re.match(r'".*":((\d+)\.(\d+)-(\d+)\.(\d+):.*)', err)
237-
if not pos:
238-
self.handle_error(path, source, err)
239-
return r
240-
msg += pos.group(1).strip(" .") + ":\n"
241-
for line in source.splitlines()[
242-
int(pos.group(2)) - 1 : int(pos.group(4))
243-
]:
244-
msg += line.strip() + "\n"
245-
246-
if msg:
247-
self.handle_error(path, source, msg)
248-
return r
249-
250-
# Next, run through https://www.html-tidy.org/
251-
document, errors = tidy_document(
252-
r.content,
253-
options={
254-
# this is causing way too many generic warnings:
255-
# "accessibility-check": 1,
256-
},
257-
)
258-
259-
errors = "\n".join(
260-
[
261-
e
262-
# TODO: check if some can be removed after validating database templates
263-
for e in errors.splitlines()
264-
# FIXME: django-bootstrap5 incorrectly sets a "required"
265-
# proprietary attribute on some <div>s; remove those errors
266-
if not re.match(r'.*proprietary attribute "required"', e)
267-
# FIXME: some secretariat templates have this issue, ignore
268-
and not re.match(r".*id and name attribute value mismatch", e)
269-
# FIXME: bootstrap-icons and close buttons render as empty, remove those errors.
270-
# Also, django seems to generate some empty tags, so remove those, too.
271-
and not re.match(r".*trimming empty <(i|em|button|span|optgroup)>", e)
272-
# FIXME: some old pages only work correctly in quirks mode :-(
273-
and not re.match(r".*missing <!DOCTYPE> declaration", e)
274-
]
275-
)
276-
277-
if errors:
278-
self.handle_error(path, source, errors)
279-
280-
return r
159+
# class VerifyingClient(Client):
160+
# def __init__(self, test):
161+
# super(VerifyingClient, self).__init__()
162+
# self.test = test
163+
164+
# def handle_error(self, path, source, errors):
165+
# file_name = "error" + re.sub("/", "-", path)
166+
# if not file_name.endswith("-"):
167+
# file_name += "-"
168+
# file_name += "source.html"
169+
# with open(file_name, "w") as src:
170+
# src.write(source)
171+
# print("\nHTML validation error for URL path", path)
172+
# print("HTML source saved to", file_name)
173+
# print("See AssertionError below for error location in HTML source.")
174+
# self.test.maxDiff = None
175+
# self.test.assertEqual("", errors)
176+
177+
# def get(self, path, *args, skip_verify=False, **extra):
178+
# """GET request
179+
180+
# Performs verification of HTML responses unless skip_verify is True.
181+
# """
182+
# r = super(VerifyingClient, self).get(path, *args, **extra)
183+
184+
# if (
185+
# skip_verify
186+
# or r.status_code >= 300
187+
# or not r["content-type"].lower().startswith("text/html")
188+
# ):
189+
# return r
190+
# source = r.content.decode()
191+
192+
# if settings.VNU:
193+
# # First, run through https://validator.github.io/validator/
194+
# result = subprocess.run(
195+
# ["java", "-jar", "/vnu.jar", "nu.validator.client.HttpClient", "-"],
196+
# input=r.content,
197+
# stdout=subprocess.PIPE,
198+
# stderr=subprocess.DEVNULL,
199+
# )
200+
# errors = result.stdout.decode()
201+
202+
# if errors:
203+
# msg = ""
204+
# for err in errors.splitlines():
205+
# # TODO: check if some can be removed after validating database templates
206+
# if (
207+
# re.match(r'.*Attribute "required" not allowed', err)
208+
# or re.match(
209+
# r'.*The "type" attribute is unnecessary for JavaScript', err
210+
# )
211+
# or re.match(
212+
# r'.*Element "option" without attribute "label" must not be empty',
213+
# err,
214+
# )
215+
# or re.match(r".*The character encoding was not declared", err)
216+
# or re.match(r".*Consider avoiding viewport values", err)
217+
# or re.match(
218+
# r'.*The value of the "for" attribute of the "label" element must be the ID of a non-hidden form control',
219+
# err,
220+
# )
221+
# or re.match(r".*is not in Unicode Normalization Form C", err)
222+
# ):
223+
# continue
224+
# # ignore some errors about obsolete HTML coming from the database
225+
# if re.match(
226+
# r"/meeting/\d+/proceedings/overview/", path
227+
# ) and re.match(
228+
# r'.*The "\w+" attribute on the "\w+" element is obsolete', err
229+
# ):
230+
# continue
231+
# # ignore some errors coming from outdated but still-needed iframes
232+
# if re.match(r"/meeting/\d+/week-view", path) and re.match(
233+
# r".*Start tag seen without seeing a doctype first", err
234+
# ):
235+
# continue
236+
# pos = re.match(r'".*":((\d+)\.(\d+)-(\d+)\.(\d+):.*)', err)
237+
# if not pos:
238+
# self.handle_error(path, source, err)
239+
# return r
240+
# msg += pos.group(1).strip(" .") + ":\n"
241+
# for line in source.splitlines()[
242+
# int(pos.group(2)) - 1 : int(pos.group(4))
243+
# ]:
244+
# msg += line.strip() + "\n"
245+
246+
# if msg:
247+
# self.handle_error(path, source, msg)
248+
# return r
249+
250+
# # Next, run through https://www.html-tidy.org/
251+
# document, errors = tidy_document(
252+
# r.content,
253+
# options={
254+
# # this is causing way too many generic warnings:
255+
# # "accessibility-check": 1,
256+
# },
257+
# )
258+
259+
# errors = "\n".join(
260+
# [
261+
# e
262+
# # TODO: check if some can be removed after validating database templates
263+
# for e in errors.splitlines()
264+
# # FIXME: django-bootstrap5 incorrectly sets a "required"
265+
# # proprietary attribute on some <div>s; remove those errors
266+
# if not re.match(r'.*proprietary attribute "required"', e)
267+
# # FIXME: some secretariat templates have this issue, ignore
268+
# and not re.match(r".*id and name attribute value mismatch", e)
269+
# # FIXME: bootstrap-icons and close buttons render as empty, remove those errors.
270+
# # Also, django seems to generate some empty tags, so remove those, too.
271+
# and not re.match(r".*trimming empty <(i|em|button|span|optgroup)>", e)
272+
# # FIXME: some old pages only work correctly in quirks mode :-(
273+
# and not re.match(r".*missing <!DOCTYPE> declaration", e)
274+
# ]
275+
# )
276+
277+
# if errors:
278+
# self.handle_error(path, source, errors)
279+
280+
# return r
281281

282282

283283
class TestCase(django.test.TestCase):
@@ -399,7 +399,7 @@ def setUp(self):
399399
self.requests_mock = requests_mock.Mocker()
400400
self.requests_mock.start()
401401

402-
self.client = VerifyingClient(self) # Set up the HTML verifier
402+
# self.client = VerifyingClient(self) # Set up the HTML verifier
403403

404404
# Replace settings paths with temporary directories.
405405
self._ietf_temp_dirs = {} # trashed during tearDown, DO NOT put paths you care about in this

0 commit comments

Comments
 (0)