From 5a906c14546fa3856308d740bcf21fa95da5933c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20H=C3=B6rist?= Date: Fri, 21 Sep 2018 15:34:51 +0200 Subject: [PATCH] Move HtmlTextView test into test folder --- gajim/htmltextview.py | 186 -------------------------------------- test/gtk/htmltextview.py | 188 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 188 insertions(+), 186 deletions(-) create mode 100644 test/gtk/htmltextview.py diff --git a/gajim/htmltextview.py b/gajim/htmltextview.py index 0bf958ab4..ffed884af 100644 --- a/gajim/htmltextview.py +++ b/gajim/htmltextview.py @@ -44,10 +44,6 @@ from gi.repository import Gtk from gi.repository import Gdk from gi.repository import GdkPixbuf -if __name__ == '__main__': - from gajim.common import configpaths - configpaths.init() - from gajim.common import app from gajim.common import helpers from gajim.common.i18n import _ @@ -1086,185 +1082,3 @@ class HtmlTextView(Gtk.TextView): self.add_child_at_anchor(emoji, anchor) buffer_.delete_mark(start_mark) buffer_.delete_mark(end_mark) - -change_cursor = None - -if __name__ == '__main__': - from gajim.conversation_textview import ConversationTextview - from gajim.gui_interface import Interface - - Interface() - - # create fake app.plugin_manager.gui_extension_point method for tests - def extension_point(*args): - pass - def gui_extension_point(*args): - pass - app.plugin_manager = Interface() - app.plugin_manager.extension_point = extension_point - app.plugin_manager.gui_extension_point = gui_extension_point - - htmlview = ConversationTextview(None) - - def on_textview_motion_notify_event(widget, event): - """ - Change the cursor to a hand when we are over a mail or an url - """ - global change_cursor - w = htmlview.tv.get_window(Gtk.TextWindowType.TEXT) - device = w.get_display().get_device_manager().get_client_pointer() - pointer = w.get_device_position(device) - x = pointer[1] - y = pointer[2] - tags = htmlview.tv.get_iter_at_location(x, y)[1].get_tags() - if change_cursor: - w.set_cursor(get_cursor('XTERM')) - change_cursor = None - for tag in tags: - try: - if tag.is_anchor: - w.set_cursor(get_cursor('HAND2')) - change_cursor = tag - except Exception: - pass - - htmlview.tv.connect('motion_notify_event', on_textview_motion_notify_event) - - def handler(texttag, widget, event, iter_, kind): - if event.type == Gdk.EventType.BUTTON_PRESS: - pass - - htmlview.tv.hyperlink_handler = htmlview.hyperlink_handler - - htmlview.print_real_text(None, xhtml='
' - 'Hello
\n' - '
\n' - 'World\n' - '
\n') - htmlview.print_real_text(None, xhtml='
') - htmlview.print_real_text(None, xhtml=''' - -

a:b - Google - -


- ''') - htmlview.print_real_text(None, xhtml=''' - -

- O - MG, - I'm green - with envy! -

- - ''') - htmlview.print_real_text(None, xhtml='
') - htmlview.print_real_text(None, xhtml=''' - - http://test.com/ testing links autolinkifying - - ''') - htmlview.print_real_text(None, xhtml='
') - htmlview.print_real_text(None, xhtml=''' - -

As Emerson said in his essay Self-Reliance:

-

- "A foolish consistency is the hobgoblin of little minds." -

- - ''') - htmlview.print_real_text(None, xhtml='
') - htmlview.print_real_text(None, xhtml=''' - -

- Hey, are you licensed to Jabber? -

-

- A License to Jabber -

- - ''') - htmlview.print_real_text(None, xhtml='
') - htmlview.print_real_text(None, xhtml=''' - -
def fac(n):
-def faciter(n,acc):
-    if n==0: return acc
-    return faciter(n-1, acc*n)
-if n<0: raise ValueError('Must be non-negative')
-return faciter(n,1)
- - ''') - htmlview.print_real_text(None, xhtml='
') - htmlview.print_real_text(None, xhtml=''' - -
    -
  1. One
  2. -
  3. Two is nested:
      -
    • One
    • -
    • Two
    • -
    • Three
    • -
    • Four
    • -
  4. -
  5. Three
- - ''') - htmlview.print_real_text(None, xhtml='
') - htmlview.print_real_text(None, xhtml=''' - -

- - xmpp link - :

-
- -

- examples@example.org wrote: -

-

this cite - bla bla bla, smile- :-) …

-
-
-

some text

-
-
-

-

#232/1

- - ''') - htmlview.print_real_text(None, xhtml='
') - htmlview.print_real_text(None, xhtml=''' - -
-Larry - - ''') - htmlview.tv.show() - sw = Gtk.ScrolledWindow() - sw.set_property('hscrollbar-policy', Gtk.PolicyType.AUTOMATIC) - sw.set_property('vscrollbar-policy', Gtk.PolicyType.AUTOMATIC) - sw.set_property('border-width', 0) - sw.add(htmlview.tv) - sw.show() - frame = Gtk.Frame() - frame.set_shadow_type(Gtk.ShadowType.IN) - frame.show() - frame.add(sw) - win = Gtk.Window() - win.add(frame) - win.set_default_size(400, 300) - win.show_all() - win.connect('destroy', lambda win: Gtk.main_quit()) - Gtk.main() diff --git a/test/gtk/htmltextview.py b/test/gtk/htmltextview.py new file mode 100644 index 000000000..4e0a48db9 --- /dev/null +++ b/test/gtk/htmltextview.py @@ -0,0 +1,188 @@ +import sys +import os +from unittest.mock import MagicMock + +sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..'))) + +from gi.repository import Gtk, Gdk + +from gajim.common import app +from gajim.common import configpaths +configpaths.init() +from gajim.common import caps_cache + +from gajim.gtk.util import get_cursor +from gajim.conversation_textview import ConversationTextview +from gajim.gui_interface import Interface + + +caps_cache.capscache = MagicMock() +app.plugin_manager = MagicMock() +app.logger = MagicMock() +app.interface = Interface() + +change_cursor = None +htmlview = ConversationTextview(None) + +def on_textview_motion_notify_event(widget, event): + """ + Change the cursor to a hand when we are over a mail or an url + """ + global change_cursor + w = htmlview.tv.get_window(Gtk.TextWindowType.TEXT) + device = w.get_display().get_device_manager().get_client_pointer() + pointer = w.get_device_position(device) + x = pointer[1] + y = pointer[2] + tags = htmlview.tv.get_iter_at_location(x, y)[1].get_tags() + if change_cursor: + w.set_cursor(get_cursor('XTERM')) + change_cursor = None + for tag in tags: + try: + if tag.is_anchor: + w.set_cursor(get_cursor('HAND2')) + change_cursor = tag + except Exception: + pass + +htmlview.tv.connect('motion_notify_event', on_textview_motion_notify_event) + +def handler(texttag, widget, event, iter_, kind): + if event.type == Gdk.EventType.BUTTON_PRESS: + pass + +htmlview.tv.hyperlink_handler = htmlview.hyperlink_handler + +htmlview.print_real_text(None, xhtml='
' +'Hello
\n' + '
\n' +'World\n' + '
\n') +htmlview.print_real_text(None, xhtml='
') +htmlview.print_real_text(None, xhtml=''' + +

a:b + Google + +


+''') +htmlview.print_real_text(None, xhtml=''' + +

+ O + MG, + I'm green + with envy! +

+ + ''') +htmlview.print_real_text(None, xhtml='
') +htmlview.print_real_text(None, xhtml=''' + + http://test.com/ testing links autolinkifying + + ''') +htmlview.print_real_text(None, xhtml='
') +htmlview.print_real_text(None, xhtml=''' + +

As Emerson said in his essay Self-Reliance:

+

+ "A foolish consistency is the hobgoblin of little minds." +

+ + ''') +htmlview.print_real_text(None, xhtml='
') +htmlview.print_real_text(None, xhtml=''' + +

+ Hey, are you licensed to Jabber? +

+

+ A License to Jabber +

+ + ''') +htmlview.print_real_text(None, xhtml='
') +htmlview.print_real_text(None, xhtml=''' + +
def fac(n):
+def faciter(n,acc):
+if n==0: return acc
+return faciter(n-1, acc*n)
+if n<0: raise ValueError('Must be non-negative')
+return faciter(n,1)
+ + ''') +htmlview.print_real_text(None, xhtml='
') +htmlview.print_real_text(None, xhtml=''' + +
    +
  1. One
  2. +
  3. Two is nested:
      +
    • One
    • +
    • Two
    • +
    • Three
    • +
    • Four
    • +
  4. +
  5. Three
+ + ''') +htmlview.print_real_text(None, xhtml='
') +htmlview.print_real_text(None, xhtml=''' + +

+ + xmpp link + :

+
+ +

+ examples@example.org wrote: +

+

this cite - bla bla bla, smile- :-) …

+
+
+

some text

+
+
+

+

#232/1

+ +''') +htmlview.print_real_text(None, xhtml='
') +htmlview.print_real_text(None, xhtml=''' + +
+Larry + +''') +htmlview.tv.show() +sw = Gtk.ScrolledWindow() +sw.set_property('hscrollbar-policy', Gtk.PolicyType.AUTOMATIC) +sw.set_property('vscrollbar-policy', Gtk.PolicyType.AUTOMATIC) +sw.set_property('border-width', 0) +sw.add(htmlview.tv) +sw.show() +frame = Gtk.Frame() +frame.set_shadow_type(Gtk.ShadowType.IN) +frame.show() +frame.add(sw) +win = Gtk.Window() +win.add(frame) +win.set_default_size(400, 300) +win.show_all() +win.connect('destroy', lambda win: Gtk.main_quit()) +Gtk.main()