Welcome to mirror list, hosted at ThFree Co, Russian Federation.

dev.gajim.org/gajim/gajim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorlovetox <philipp@hoerist.com>2022-08-11 21:26:47 +0300
committerlovetox <philipp@hoerist.com>2022-08-11 21:26:47 +0300
commit4a30ee3f2e15e43bd08536c145f5ad0f906f3a17 (patch)
treef1740ebc34e314c0c5e5c6d5f60c7b51fa26d09b /test
parent36578a37723183b7c7d75f7c6e8176018a3fc188 (diff)
refactor: Regex: Remove unused code
- Add licence header - Fix tests
Diffstat (limited to 'test')
-rw-r--r--test/no_gui/test_regex.py56
1 files changed, 32 insertions, 24 deletions
diff --git a/test/no_gui/test_regex.py b/test/no_gui/test_regex.py
index cab31831e..a4acded48 100644
--- a/test/no_gui/test_regex.py
+++ b/test/no_gui/test_regex.py
@@ -1,36 +1,44 @@
+from typing import Any
+
import unittest
-from gajim import gui
-gui.init('gtk')
-import gajim.common.regex as regex
+from gajim.common.styling import URI_RX
+from gajim.common.styling import ADDRESS_RX
-class Test(unittest.TestCase):
- def test_links_regexp_entire(self):
- def assert_matches_all(str_):
- m = regex.BASIC_REGEX.match(str_)
- # the match should equal the string
- str_span = (0, len(str_))
- self.assertEqual(m.span(), str_span)
+TEST_URIS = [
+ 'http://google.com/',
+ 'http://google.com',
+ 'http://www.google.ca/search?q=xmpp',
+ 'http://tools.ietf.org/html/draft-saintandre-rfc3920bis-05#section-12.3',
+ 'http://en.wikipedia.org/wiki/Protocol_(computing)',
+ 'http://en.wikipedia.org/wiki/Protocol_%28computing%29',
+]
- # these entire strings should be parsed as links
- assert_matches_all('http://google.com/')
- assert_matches_all('http://google.com')
- assert_matches_all('http://www.google.ca/search?q=xmpp')
+ADDRESSES = [
+ 'mailto:test@example.org',
+ 'xmpp:example-node@example.com',
+ # 'xmpp:example-node@example.com/some-resource', FIXME
+ 'xmpp:example-node@example.com?message',
+]
- assert_matches_all('http://tools.ietf.org/html/draft-saintandre-rfc3920bis-05#section-12.3')
- assert_matches_all('http://en.wikipedia.org/wiki/Protocol_(computing)')
- assert_matches_all(
- 'http://en.wikipedia.org/wiki/Protocol_%28computing%29')
+class Test(unittest.TestCase):
+ def test_links_regexp_entire(self):
+ def assert_matches_all(regex: Any, uri_str: str) -> None:
+ m = regex.match(uri_str)
+ if m is None:
+ raise AssertionError('Failed: %s' % uri_str)
+
+ str_span = (0, len(uri_str))
+ self.assertEqual(m.span(), str_span, uri_str)
- assert_matches_all('mailto:test@example.org')
+ for uri in TEST_URIS:
+ assert_matches_all(URI_RX, uri)
- assert_matches_all('xmpp:example-node@example.com')
- assert_matches_all('xmpp:example-node@example.com/some-resource')
- assert_matches_all('xmpp:example-node@example.com?message')
- assert_matches_all('xmpp://guest@example.com/support@example.com?message')
+ for addr in ADDRESSES:
+ assert_matches_all(ADDRESS_RX, addr)
-if __name__ == "__main__":
+if __name__ == '__main__':
unittest.main()