This is an automated email from the ASF dual-hosted git repository.

brondsem pushed a commit to branch db/8566
in repository https://gitbox.apache.org/repos/asf/allura.git

commit 9f3688a7383302f3fe9e08073b44132eea57b719
Author: Dave Brondsema <[email protected]>
AuthorDate: Wed Jul 10 17:17:14 2024 -0400

    [#8566] fix some test warnings
---
 Allura/allura/lib/markdown_extensions.py                    | 13 +++++++++----
 Allura/allura/scripts/trac_export.py                        |  2 +-
 Allura/allura/tests/functional/test_admin.py                |  8 ++++----
 Allura/allura/tests/functional/test_auth.py                 |  2 +-
 .../forgediscussion/tests/functional/test_forum.py          |  8 ++++----
 5 files changed, 19 insertions(+), 14 deletions(-)

diff --git a/Allura/allura/lib/markdown_extensions.py 
b/Allura/allura/lib/markdown_extensions.py
index b6d423d58..3e63e16f1 100644
--- a/Allura/allura/lib/markdown_extensions.py
+++ b/Allura/allura/lib/markdown_extensions.py
@@ -18,13 +18,14 @@
 from __future__ import annotations
 import re
 import logging
+import warnings
 from typing import List
 import xml.etree.ElementTree as etree
 
 from urllib.parse import urljoin
 
 from tg import config
-from bs4 import BeautifulSoup
+from bs4 import BeautifulSoup, MarkupResemblesLocatorWarning
 import html5lib
 import html5lib.serializer
 import html5lib.filters.alphabeticalattributes
@@ -474,9 +475,13 @@ class 
RelativeLinkRewriter(markdown.postprocessors.Postprocessor):
     def __init__(self, make_absolute=False):
         self._make_absolute = make_absolute
 
-    def run(self, text):
-        soup = BeautifulSoup(text,
-                             'html5lib')  # 'html.parser' parser gives weird 
</li> behaviour with test_macro_members
+    def run(self, text: str):
+        with warnings.catch_warnings():
+            # sometimes short snippets of code (especially escaped html) can 
trigger this
+            warnings.filterwarnings('ignore', 
category=MarkupResemblesLocatorWarning)
+
+            soup = BeautifulSoup(text,
+                                 'html5lib')  # 'html.parser' parser gives 
weird </li> behaviour with test_macro_members
 
         if self._make_absolute:
             rewrite = self._rewrite_abs
diff --git a/Allura/allura/scripts/trac_export.py 
b/Allura/allura/scripts/trac_export.py
index ce9d2c9e2..c9f5a0e70 100644
--- a/Allura/allura/scripts/trac_export.py
+++ b/Allura/allura/scripts/trac_export.py
@@ -210,7 +210,7 @@ class TracExport:
             d['size'] = int(self.match_pattern(SIZE_PATTERN, size_s))
             timestamp_s = attach.find('a', {'class': 'timeline'})['title']
             d['date'] = self.trac2z_date(self.match_pattern(TIMESTAMP_PATTERN, 
timestamp_s))
-            d['by'] = attach.find(text=re.compile('added by')).nextSibling.text
+            d['by'] = attach.find(string=re.compile('added 
by')).nextSibling.text
             d['description'] = ''
             # Skip whitespace
             while attach.nextSibling and isinstance(attach.nextSibling, 
NavigableString):
diff --git a/Allura/allura/tests/functional/test_admin.py 
b/Allura/allura/tests/functional/test_admin.py
index 62d7111d8..d0d6ee260 100644
--- a/Allura/allura/tests/functional/test_admin.py
+++ b/Allura/allura/tests/functional/test_admin.py
@@ -596,8 +596,8 @@ class TestProjectAdmin(TestController):
     def test_log_permission(self):
         r = self.app.get('/admin/wiki/permissions')
         select = r.html.find('select', {'name': 'card-0.new'})
-        opt_admin = select.find(text='Admin').parent
-        opt_developer = select.find(text='Developer').parent
+        opt_admin = select.find(string='Admin').parent
+        opt_developer = select.find(string='Developer').parent
         assert opt_admin.name == 'option'
         assert opt_developer.name == 'option'
 
@@ -627,8 +627,8 @@ class TestProjectAdmin(TestController):
         r = self.app.get('/test-subproject/admin/permissions/')
         assert len(r.html.findAll('input', {'name': 'card-0.value'})) == 0
         select = r.html.find('select', {'name': 'card-0.new'})
-        opt_admin = select.find(text='Admin').parent
-        opt_developer = select.find(text='Developer').parent
+        opt_admin = select.find(string='Admin').parent
+        opt_developer = select.find(string='Developer').parent
         assert opt_admin.name == 'option'
         assert opt_developer.name == 'option'
         with audits('updated "admin" permissions: "" => "Admin,Developer"'):
diff --git a/Allura/allura/tests/functional/test_auth.py 
b/Allura/allura/tests/functional/test_auth.py
index 868dbc26f..e9e8fd898 100644
--- a/Allura/allura/tests/functional/test_auth.py
+++ b/Allura/allura/tests/functional/test_auth.py
@@ -2041,7 +2041,7 @@ class TestOAuth(TestController):
         )
         ThreadLocalODMSession.flush_all()
         r = self.app.post('/rest/oauth/do_authorize', params={'yes': '1', 
'oauth_token': 'api_key_reqtok_12345'})
-        assert r.html.find(text=re.compile('^PIN: ')) is not None
+        assert r.html.find(string=re.compile('^PIN: ')) is not None
 
     def test_do_authorize_cb(self):
         user = M.User.by_username('test-admin')
diff --git a/ForgeDiscussion/forgediscussion/tests/functional/test_forum.py 
b/ForgeDiscussion/forgediscussion/tests/functional/test_forum.py
index 78cf7d8ff..6665fa784 100644
--- a/ForgeDiscussion/forgediscussion/tests/functional/test_forum.py
+++ b/ForgeDiscussion/forgediscussion/tests/functional/test_forum.py
@@ -525,9 +525,9 @@ class TestForum(TestController):
     def _set_anon_allowed(self):
         r = self.app.get('/admin/discussion/permissions')
         select = r.html.find('select', {'name': 'card-3.new'})
-        opt_anon = select.find(text='*anonymous').parent
-        opt_auth = select.find(text='*authenticated').parent
-        opt_admin = select.find(text='Admin').parent
+        opt_anon = select.find(string='*anonymous').parent
+        opt_auth = select.find(string='*authenticated').parent
+        opt_admin = select.find(string='Admin').parent
         r = self.app.post('/admin/discussion/update', params={
             'card-0.id': 'admin',
             'card-0.value': opt_admin['value'],
@@ -726,7 +726,7 @@ class TestForum(TestController):
         return rows
 
     def check_announcement_table(self, response, topic_name):
-        assert response.html.find(text='Announcements')
+        assert response.html.find(string='Announcements')
         rows = self.get_table_rows(response, 'announcements')
         assert len(rows) == 1
         cell = rows[0].findAll('td', {'class': 'topic'})

Reply via email to