Skip to content

Commit

Permalink
1.6.1dev: fix functional tests failing when tidylib is loaded from /u…
Browse files Browse the repository at this point in the history
…sr/lib on macOS

git-svn-id: http://trac.edgewall.org/intertrac/log:/branches/1.6-stable@17845 af82e41b-90c4-0310-8c96-b1721e28e2e2
  • Loading branch information
jomae committed Sep 30, 2024
1 parent f2a2cc7 commit 63245dc
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 14 deletions.
20 changes: 13 additions & 7 deletions contrib/make_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,19 @@ def _pytidylib_version():
info = 'not installed'
else:
import ctypes
cdll = tidy._tidy
fn = cdll.tidyLibraryVersion
fn.restype = ctypes.c_char_p
libver = fn()
if isinstance(libver, bytes):
libver = str(libver, 'utf-8')
info = '%s %s' % (libver, cdll._name)
try:
cdll = tidy._tidy
try:
fn = cdll.tidyLibraryVersion
fn.restype = ctypes.c_char_p
libver = fn()
if isinstance(libver, bytes):
libver = str(libver, 'utf-8')
except Exception as e:
libver = repr(e)
info = '%s %s' % (libver, cdll._name)
except Exception as e:
info = repr(e)
return '%s (%s)' % (version, info) if info else version

def _pysqlite3_version():
Expand Down
18 changes: 11 additions & 7 deletions trac/tests/functional/better_twill.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,16 @@
except ImportError:
selenium = None


_tidy_options = {
'escape-scripts': 0,
'drop-empty-elements': 0,
}
_curr = locale.setlocale(locale.LC_ALL, None)
try:
import tidylib
tidylib.tidy_document('<!DOCTYPE html><html><body></body></html>')
tidylib.tidy_document('<!DOCTYPE html><html><body></body></html>',
_tidy_options)
except ImportError:
print("SKIP: validation of HTML output in functional tests"
" (no tidylib installed)")
Expand All @@ -52,6 +58,9 @@
print("SKIP: validation of HTML output in functional tests"
" (no tidy dynamic library installed: %s)" % e)
tidy_document = None
except ValueError as e:
print("SKIP: validation of HTML output in functional tests (%r)" % e)
tidy_document = None
else:
if _curr == locale.setlocale(locale.LC_ALL, None):
tidy_document = tidylib.tidy_document
Expand Down Expand Up @@ -562,19 +571,14 @@ def _urljoin(self, url):
url = urljoin(self.get_url(), url)
return url

_tidy_options = {
'escape-scripts': 0,
'drop-empty-elements': 0,
}

_doctype_re = re.compile(r'\s*<!DOCTYPE\b'.encode('ascii'))

def _validate_html(self, source):
if not tidy_document:
return
if not self._doctype_re.match(source):
return
corrected, errors = tidy_document(source, self._tidy_options)
corrected, errors = tidy_document(source, _tidy_options)
if errors:
errors = errors.splitlines()
url = self.write_source(source)
Expand Down

0 comments on commit 63245dc

Please sign in to comment.