Converted test_webelem to pytest

This commit is contained in:
Bruno Oliveira 2015-04-03 18:36:35 -03:00
parent f57223f7eb
commit 7442e30f29

View File

@ -21,15 +21,14 @@
"""Tests for the webelement utils.""" """Tests for the webelement utils."""
import unittest
from unittest import mock from unittest import mock
import collections.abc import collections.abc
from PyQt5.QtCore import QRect, QPoint from PyQt5.QtCore import QRect, QPoint
from PyQt5.QtWebKit import QWebElement from PyQt5.QtWebKit import QWebElement
import pytest
from qutebrowser.browser import webelem from qutebrowser.browser import webelem
from qutebrowser.test import stubs
def get_webelem(geometry=None, frame=None, null=False, visibility='', def get_webelem(geometry=None, frame=None, null=False, visibility='',
@ -87,17 +86,17 @@ def get_webelem(geometry=None, frame=None, null=False, visibility='',
return wrapped return wrapped
class WebElementWrapperTests(unittest.TestCase): class TestWebElementWrapper(object):
"""Test WebElementWrapper.""" """Test WebElementWrapper."""
def test_nullelem(self): def test_nullelem(self):
"""Test __init__ with a null element.""" """Test __init__ with a null element."""
with self.assertRaises(webelem.IsNullError): with pytest.raises(webelem.IsNullError):
get_webelem(null=True) get_webelem(null=True)
class IsVisibleInvalidTests(unittest.TestCase): class TestIsVisibleInvalid(object):
"""Tests for is_visible with invalid elements. """Tests for is_visible with invalid elements.
@ -105,7 +104,8 @@ class IsVisibleInvalidTests(unittest.TestCase):
frame: The FakeWebFrame we're using to test. frame: The FakeWebFrame we're using to test.
""" """
def setUp(self): @pytest.fixture(autouse=True)
def setup(self, stubs):
self.frame = stubs.FakeWebFrame(QRect(0, 0, 100, 100)) self.frame = stubs.FakeWebFrame(QRect(0, 0, 100, 100))
def test_nullelem(self): def test_nullelem(self):
@ -116,15 +116,15 @@ class IsVisibleInvalidTests(unittest.TestCase):
""" """
elem = get_webelem() elem = get_webelem()
elem._elem.isNull.return_value = True elem._elem.isNull.return_value = True
with self.assertRaises(webelem.IsNullError): with pytest.raises(webelem.IsNullError):
elem.is_visible(self.frame) elem.is_visible(self.frame)
def test_invalid_invisible(self): def test_invalid_invisible(self):
"""Test elements with an invalid geometry which are invisible.""" """Test elements with an invalid geometry which are invisible."""
elem = get_webelem(QRect(0, 0, 0, 0), self.frame) elem = get_webelem(QRect(0, 0, 0, 0), self.frame)
self.assertFalse(elem.geometry().isValid()) assert not elem.geometry().isValid()
self.assertEqual(elem.geometry().x(), 0) assert elem.geometry().x() == 0
self.assertFalse(elem.is_visible(self.frame)) assert not elem.is_visible(self.frame)
def test_invalid_visible(self): def test_invalid_visible(self):
"""Test elements with an invalid geometry which are visible. """Test elements with an invalid geometry which are visible.
@ -133,11 +133,11 @@ class IsVisibleInvalidTests(unittest.TestCase):
which *are* visible, but don't have a valid geometry. which *are* visible, but don't have a valid geometry.
""" """
elem = get_webelem(QRect(10, 10, 0, 0), self.frame) elem = get_webelem(QRect(10, 10, 0, 0), self.frame)
self.assertFalse(elem.geometry().isValid()) assert not elem.geometry().isValid()
self.assertTrue(elem.is_visible(self.frame)) assert elem.is_visible(self.frame)
class IsVisibleScrollTests(unittest.TestCase): class TestIsVisibleScroll(object):
"""Tests for is_visible when the frame is scrolled. """Tests for is_visible when the frame is scrolled.
@ -145,22 +145,23 @@ class IsVisibleScrollTests(unittest.TestCase):
frame: The FakeWebFrame we're using to test. frame: The FakeWebFrame we're using to test.
""" """
def setUp(self): @pytest.fixture(autouse=True)
def setup(self, stubs):
self.frame = stubs.FakeWebFrame(QRect(0, 0, 100, 100), self.frame = stubs.FakeWebFrame(QRect(0, 0, 100, 100),
scroll=QPoint(10, 10)) scroll=QPoint(10, 10))
def test_invisible(self): def test_invisible(self):
"""Test elements which should be invisible due to scrolling.""" """Test elements which should be invisible due to scrolling."""
elem = get_webelem(QRect(5, 5, 4, 4), self.frame) elem = get_webelem(QRect(5, 5, 4, 4), self.frame)
self.assertFalse(elem.is_visible(self.frame)) assert not elem.is_visible(self.frame)
def test_visible(self): def test_visible(self):
"""Test elements which still should be visible after scrolling.""" """Test elements which still should be visible after scrolling."""
elem = get_webelem(QRect(10, 10, 1, 1), self.frame) elem = get_webelem(QRect(10, 10, 1, 1), self.frame)
self.assertTrue(elem.is_visible(self.frame)) assert elem.is_visible(self.frame)
class IsVisibleCssTests(unittest.TestCase): class TestIsVisibleCss(object):
"""Tests for is_visible with CSS attributes. """Tests for is_visible with CSS attributes.
@ -168,33 +169,34 @@ class IsVisibleCssTests(unittest.TestCase):
frame: The FakeWebFrame we're using to test. frame: The FakeWebFrame we're using to test.
""" """
def setUp(self): @pytest.fixture(autouse=True)
def setup(self, stubs):
self.frame = stubs.FakeWebFrame(QRect(0, 0, 100, 100)) self.frame = stubs.FakeWebFrame(QRect(0, 0, 100, 100))
def test_visibility_visible(self): def test_visibility_visible(self):
"""Check that elements with "visibility = visible" are visible.""" """Check that elements with "visibility = visible" are visible."""
elem = get_webelem(QRect(0, 0, 10, 10), self.frame, elem = get_webelem(QRect(0, 0, 10, 10), self.frame,
visibility='visible') visibility='visible')
self.assertTrue(elem.is_visible(self.frame)) assert elem.is_visible(self.frame)
def test_visibility_hidden(self): def test_visibility_hidden(self):
"""Check that elements with "visibility = hidden" are not visible.""" """Check that elements with "visibility = hidden" are not visible."""
elem = get_webelem(QRect(0, 0, 10, 10), self.frame, elem = get_webelem(QRect(0, 0, 10, 10), self.frame,
visibility='hidden') visibility='hidden')
self.assertFalse(elem.is_visible(self.frame)) assert not elem.is_visible(self.frame)
def test_display_inline(self): def test_display_inline(self):
"""Check that elements with "display = inline" are visible.""" """Check that elements with "display = inline" are visible."""
elem = get_webelem(QRect(0, 0, 10, 10), self.frame, display='inline') elem = get_webelem(QRect(0, 0, 10, 10), self.frame, display='inline')
self.assertTrue(elem.is_visible(self.frame)) assert elem.is_visible(self.frame)
def test_display_none(self): def test_display_none(self):
"""Check that elements with "display = none" are not visible.""" """Check that elements with "display = none" are not visible."""
elem = get_webelem(QRect(0, 0, 10, 10), self.frame, display='none') elem = get_webelem(QRect(0, 0, 10, 10), self.frame, display='none')
self.assertFalse(elem.is_visible(self.frame)) assert not elem.is_visible(self.frame)
class IsVisibleIframeTests(unittest.TestCase): class TestIsVisibleIframe(object):
"""Tests for is_visible with a child frame. """Tests for is_visible with a child frame.
@ -204,7 +206,8 @@ class IsVisibleIframeTests(unittest.TestCase):
elem1-elem4: FakeWebElements to test. elem1-elem4: FakeWebElements to test.
""" """
def setUp(self): @pytest.fixture(autouse=True)
def setup(self, stubs):
"""Set up the following base situation. """Set up the following base situation.
0, 0 300, 0 0, 0 300, 0
@ -236,64 +239,64 @@ class IsVisibleIframeTests(unittest.TestCase):
def test_not_scrolled(self): def test_not_scrolled(self):
"""Test base situation.""" """Test base situation."""
self.assertTrue(self.frame.geometry().contains(self.iframe.geometry())) assert self.frame.geometry().contains(self.iframe.geometry())
self.assertTrue(self.elem1.is_visible(self.frame)) assert self.elem1.is_visible(self.frame)
self.assertTrue(self.elem2.is_visible(self.frame)) assert self.elem2.is_visible(self.frame)
self.assertFalse(self.elem3.is_visible(self.frame)) assert not self.elem3.is_visible(self.frame)
self.assertTrue(self.elem4.is_visible(self.frame)) assert self.elem4.is_visible(self.frame)
def test_iframe_scrolled(self): def test_iframe_scrolled(self):
"""Scroll iframe down so elem3 gets visible and elem1/elem2 not.""" """Scroll iframe down so elem3 gets visible and elem1/elem2 not."""
self.iframe.scrollPosition.return_value = QPoint(0, 100) self.iframe.scrollPosition.return_value = QPoint(0, 100)
self.assertFalse(self.elem1.is_visible(self.frame)) assert not self.elem1.is_visible(self.frame)
self.assertFalse(self.elem2.is_visible(self.frame)) assert not self.elem2.is_visible(self.frame)
self.assertTrue(self.elem3.is_visible(self.frame)) assert self.elem3.is_visible(self.frame)
self.assertTrue(self.elem4.is_visible(self.frame)) assert self.elem4.is_visible(self.frame)
def test_mainframe_scrolled_iframe_visible(self): def test_mainframe_scrolled_iframe_visible(self):
"""Scroll mainframe down so iframe is partly visible but elem1 not.""" """Scroll mainframe down so iframe is partly visible but elem1 not."""
self.frame.scrollPosition.return_value = QPoint(0, 50) self.frame.scrollPosition.return_value = QPoint(0, 50)
geom = self.frame.geometry().translated(self.frame.scrollPosition()) geom = self.frame.geometry().translated(self.frame.scrollPosition())
self.assertFalse(geom.contains(self.iframe.geometry())) assert not geom.contains(self.iframe.geometry())
self.assertTrue(geom.intersects(self.iframe.geometry())) assert geom.intersects(self.iframe.geometry())
self.assertFalse(self.elem1.is_visible(self.frame)) assert not self.elem1.is_visible(self.frame)
self.assertTrue(self.elem2.is_visible(self.frame)) assert self.elem2.is_visible(self.frame)
self.assertFalse(self.elem3.is_visible(self.frame)) assert not self.elem3.is_visible(self.frame)
self.assertTrue(self.elem4.is_visible(self.frame)) assert self.elem4.is_visible(self.frame)
def test_mainframe_scrolled_iframe_invisible(self): def test_mainframe_scrolled_iframe_invisible(self):
"""Scroll mainframe down so iframe is invisible.""" """Scroll mainframe down so iframe is invisible."""
self.frame.scrollPosition.return_value = QPoint(0, 110) self.frame.scrollPosition.return_value = QPoint(0, 110)
geom = self.frame.geometry().translated(self.frame.scrollPosition()) geom = self.frame.geometry().translated(self.frame.scrollPosition())
self.assertFalse(geom.contains(self.iframe.geometry())) assert not geom.contains(self.iframe.geometry())
self.assertFalse(geom.intersects(self.iframe.geometry())) assert not geom.intersects(self.iframe.geometry())
self.assertFalse(self.elem1.is_visible(self.frame)) assert not self.elem1.is_visible(self.frame)
self.assertFalse(self.elem2.is_visible(self.frame)) assert not self.elem2.is_visible(self.frame)
self.assertFalse(self.elem3.is_visible(self.frame)) assert not self.elem3.is_visible(self.frame)
self.assertTrue(self.elem4.is_visible(self.frame)) assert self.elem4.is_visible(self.frame)
class IsWritableTests(unittest.TestCase): class TestIsWritable(object):
"""Check is_writable.""" """Check is_writable."""
def test_writable(self): def test_writable(self):
"""Test a normal element.""" """Test a normal element."""
elem = get_webelem() elem = get_webelem()
self.assertTrue(elem.is_writable()) assert elem.is_writable()
def test_disabled(self): def test_disabled(self):
"""Test a disabled element.""" """Test a disabled element."""
elem = get_webelem(attributes=['disabled']) elem = get_webelem(attributes=['disabled'])
self.assertFalse(elem.is_writable()) assert not elem.is_writable()
def test_readonly(self): def test_readonly(self):
"""Test a readonly element.""" """Test a readonly element."""
elem = get_webelem(attributes=['readonly']) elem = get_webelem(attributes=['readonly'])
self.assertFalse(elem.is_writable()) assert not elem.is_writable()
class JavascriptEscapeTests(unittest.TestCase): class TestJavascriptEscape(object):
"""Check javascript_escape. """Check javascript_escape.
@ -301,33 +304,30 @@ class JavascriptEscapeTests(unittest.TestCase):
STRINGS: A list of (input, output) tuples. STRINGS: A list of (input, output) tuples.
""" """
STRINGS = ( @pytest.mark.parametrize('before, after', [
('foo\\bar', r'foo\\bar'), ('foo\\bar', r'foo\\bar'),
('foo\nbar', r'foo\nbar'), ('foo\nbar', r'foo\nbar'),
("foo'bar", r"foo\'bar"), ("foo'bar", r"foo\'bar"),
('foo"bar', r'foo\"bar'), ('foo"bar', r'foo\"bar'),
) ])
def test_fake_escape(self, before, after):
def test_fake_escape(self):
"""Test javascript escaping.""" """Test javascript escaping."""
for before, after in self.STRINGS: assert webelem.javascript_escape(before) == after
with self.subTest(before=before):
self.assertEqual(webelem.javascript_escape(before), after)
class GetChildFramesTests(unittest.TestCase): class TestGetChildFrames(object):
"""Check get_child_frames.""" """Check get_child_frames."""
def test_single_frame(self): def test_single_frame(self, stubs):
"""Test get_child_frames with a single frame without children.""" """Test get_child_frames with a single frame without children."""
frame = stubs.FakeChildrenFrame() frame = stubs.FakeChildrenFrame()
children = webelem.get_child_frames(frame) children = webelem.get_child_frames(frame)
self.assertEqual(len(children), 1) assert len(children) == 1
self.assertIs(children[0], frame) assert children[0] is frame
frame.childFrames.assert_called_once_with() frame.childFrames.assert_called_once_with()
def test_one_level(self): def test_one_level(self, stubs):
r"""Test get_child_frames with one level of children. r"""Test get_child_frames with one level of children.
o parent o parent
@ -338,15 +338,15 @@ class GetChildFramesTests(unittest.TestCase):
child2 = stubs.FakeChildrenFrame() child2 = stubs.FakeChildrenFrame()
parent = stubs.FakeChildrenFrame([child1, child2]) parent = stubs.FakeChildrenFrame([child1, child2])
children = webelem.get_child_frames(parent) children = webelem.get_child_frames(parent)
self.assertEqual(len(children), 3) assert len(children) == 3
self.assertIs(children[0], parent) assert children[0] is parent
self.assertIs(children[1], child1) assert children[1] is child1
self.assertIs(children[2], child2) assert children[2] is child2
parent.childFrames.assert_called_once_with() parent.childFrames.assert_called_once_with()
child1.childFrames.assert_called_once_with() child1.childFrames.assert_called_once_with()
child2.childFrames.assert_called_once_with() child2.childFrames.assert_called_once_with()
def test_multiple_levels(self): def test_multiple_levels(self, stubs):
r"""Test get_child_frames with multiple levels of children. r"""Test get_child_frames with multiple levels of children.
o root o root
@ -360,189 +360,190 @@ class GetChildFramesTests(unittest.TestCase):
stubs.FakeChildrenFrame(second[2:4])] stubs.FakeChildrenFrame(second[2:4])]
root = stubs.FakeChildrenFrame(first) root = stubs.FakeChildrenFrame(first)
children = webelem.get_child_frames(root) children = webelem.get_child_frames(root)
self.assertEqual(len(children), 7) assert len(children) == 7
self.assertIs(children[0], root) assert children[0] is root
for frame in [root] + first + second: for frame in [root] + first + second:
with self.subTest(frame=frame):
frame.childFrames.assert_called_once_with() frame.childFrames.assert_called_once_with()
class IsEditableTests(unittest.TestCase): class TestIsEditable(object):
"""Tests for is_editable.""" """Tests for is_editable."""
def setUp(self): @pytest.yield_fixture(autouse=True)
def setup(self):
old_config = webelem.config
webelem.config = None webelem.config = None
yield
webelem.config = old_config
@pytest.yield_fixture
def stub_config(self, stubs):
config = stubs.ConfigStub({'input': {'insert-mode-on-plugins': True}})
with mock.patch('qutebrowser.browser.webelem.config', new=config):
yield config
def test_input_plain(self): def test_input_plain(self):
"""Test with plain input element.""" """Test with plain input element."""
elem = get_webelem(tagname='input') elem = get_webelem(tagname='input')
self.assertTrue(elem.is_editable()) assert elem.is_editable()
def test_input_text(self): def test_input_text(self):
"""Test with text input element.""" """Test with text input element."""
elem = get_webelem(tagname='input', attributes={'type': 'text'}) elem = get_webelem(tagname='input', attributes={'type': 'text'})
self.assertTrue(elem.is_editable()) assert elem.is_editable()
def test_input_text_caps(self): def test_input_text_caps(self):
"""Test with text input element with caps attributes.""" """Test with text input element with caps attributes."""
elem = get_webelem(tagname='INPUT', attributes={'TYPE': 'TEXT'}) elem = get_webelem(tagname='INPUT', attributes={'TYPE': 'TEXT'})
self.assertTrue(elem.is_editable()) assert elem.is_editable()
def test_input_email(self): def test_input_email(self):
"""Test with email input element.""" """Test with email input element."""
elem = get_webelem(tagname='input', attributes={'type': 'email'}) elem = get_webelem(tagname='input', attributes={'type': 'email'})
self.assertTrue(elem.is_editable()) assert elem.is_editable()
def test_input_url(self): def test_input_url(self):
"""Test with url input element.""" """Test with url input element."""
elem = get_webelem(tagname='input', attributes={'type': 'url'}) elem = get_webelem(tagname='input', attributes={'type': 'url'})
self.assertTrue(elem.is_editable()) assert elem.is_editable()
def test_input_tel(self): def test_input_tel(self):
"""Test with tel input element.""" """Test with tel input element."""
elem = get_webelem(tagname='input', attributes={'type': 'tel'}) elem = get_webelem(tagname='input', attributes={'type': 'tel'})
self.assertTrue(elem.is_editable()) assert elem.is_editable()
def test_input_number(self): def test_input_number(self):
"""Test with number input element.""" """Test with number input element."""
elem = get_webelem(tagname='input', attributes={'type': 'number'}) elem = get_webelem(tagname='input', attributes={'type': 'number'})
self.assertTrue(elem.is_editable()) assert elem.is_editable()
def test_input_password(self): def test_input_password(self):
"""Test with password input element.""" """Test with password input element."""
elem = get_webelem(tagname='input', attributes={'type': 'password'}) elem = get_webelem(tagname='input', attributes={'type': 'password'})
self.assertTrue(elem.is_editable()) assert elem.is_editable()
def test_input_search(self): def test_input_search(self):
"""Test with search input element.""" """Test with search input element."""
elem = get_webelem(tagname='input', attributes={'type': 'search'}) elem = get_webelem(tagname='input', attributes={'type': 'search'})
self.assertTrue(elem.is_editable()) assert elem.is_editable()
def test_input_button(self): def test_input_button(self):
"""Button should not be editable.""" """Button should not be editable."""
elem = get_webelem(tagname='input', attributes={'type': 'button'}) elem = get_webelem(tagname='input', attributes={'type': 'button'})
self.assertFalse(elem.is_editable()) assert not elem.is_editable()
def test_input_checkbox(self): def test_input_checkbox(self):
"""Checkbox should not be editable.""" """Checkbox should not be editable."""
elem = get_webelem(tagname='input', attributes={'type': 'checkbox'}) elem = get_webelem(tagname='input', attributes={'type': 'checkbox'})
self.assertFalse(elem.is_editable()) assert not elem.is_editable()
def test_textarea(self): def test_textarea(self):
"""Test textarea element.""" """Test textarea element."""
elem = get_webelem(tagname='textarea') elem = get_webelem(tagname='textarea')
self.assertTrue(elem.is_editable()) assert elem.is_editable()
def test_select(self): def test_select(self):
"""Test selectbox.""" """Test selectbox."""
elem = get_webelem(tagname='select') elem = get_webelem(tagname='select')
self.assertFalse(elem.is_editable()) assert not elem.is_editable()
def test_input_disabled(self): def test_input_disabled(self):
"""Test disabled input element.""" """Test disabled input element."""
elem = get_webelem(tagname='input', attributes={'disabled': None}) elem = get_webelem(tagname='input', attributes={'disabled': None})
self.assertFalse(elem.is_editable()) assert not elem.is_editable()
def test_input_readonly(self): def test_input_readonly(self):
"""Test readonly input element.""" """Test readonly input element."""
elem = get_webelem(tagname='input', attributes={'readonly': None}) elem = get_webelem(tagname='input', attributes={'readonly': None})
self.assertFalse(elem.is_editable()) assert not elem.is_editable()
def test_textarea_disabled(self): def test_textarea_disabled(self):
"""Test disabled textarea element.""" """Test disabled textarea element."""
elem = get_webelem(tagname='textarea', attributes={'disabled': None}) elem = get_webelem(tagname='textarea', attributes={'disabled': None})
self.assertFalse(elem.is_editable()) assert not elem.is_editable()
def test_textarea_readonly(self): def test_textarea_readonly(self):
"""Test readonly textarea element.""" """Test readonly textarea element."""
elem = get_webelem(tagname='textarea', attributes={'readonly': None}) elem = get_webelem(tagname='textarea', attributes={'readonly': None})
self.assertFalse(elem.is_editable()) assert not elem.is_editable()
@mock.patch('qutebrowser.browser.webelem.config', new=stubs.ConfigStub( def test_embed_true(self, stub_config):
{'input': {'insert-mode-on-plugins': True}}))
def test_embed_true(self):
"""Test embed-element with insert-mode-on-plugins true.""" """Test embed-element with insert-mode-on-plugins true."""
stub_config.data['input']['insert-mode-on-plugins'] = True
elem = get_webelem(tagname='embed') elem = get_webelem(tagname='embed')
self.assertTrue(elem.is_editable()) assert elem.is_editable()
@mock.patch('qutebrowser.browser.webelem.config', new=stubs.ConfigStub( def test_applet_true(self, stub_config):
{'input': {'insert-mode-on-plugins': True}}))
def test_applet_true(self):
"""Test applet-element with insert-mode-on-plugins true.""" """Test applet-element with insert-mode-on-plugins true."""
stub_config.data['input']['insert-mode-on-plugins'] = True
elem = get_webelem(tagname='applet') elem = get_webelem(tagname='applet')
self.assertTrue(elem.is_editable()) assert elem.is_editable()
@mock.patch('qutebrowser.browser.webelem.config', new=stubs.ConfigStub( def test_embed_false(self, stub_config):
{'input': {'insert-mode-on-plugins': False}}))
def test_embed_false(self):
"""Test embed-element with insert-mode-on-plugins false.""" """Test embed-element with insert-mode-on-plugins false."""
stub_config.data['input']['insert-mode-on-plugins'] = False
elem = get_webelem(tagname='embed') elem = get_webelem(tagname='embed')
self.assertFalse(elem.is_editable()) assert not elem.is_editable()
@mock.patch('qutebrowser.browser.webelem.config', new=stubs.ConfigStub( def test_applet_false(self, stub_config):
{'input': {'insert-mode-on-plugins': False}}))
def test_applet_false(self):
"""Test applet-element with insert-mode-on-plugins false.""" """Test applet-element with insert-mode-on-plugins false."""
stub_config.data['input']['insert-mode-on-plugins'] = False
elem = get_webelem(tagname='applet') elem = get_webelem(tagname='applet')
self.assertFalse(elem.is_editable()) assert not elem.is_editable()
def test_object_no_type(self): def test_object_no_type(self):
"""Test object-element without type.""" """Test object-element without type."""
elem = get_webelem(tagname='object') elem = get_webelem(tagname='object')
self.assertFalse(elem.is_editable()) assert not elem.is_editable()
def test_object_image(self): def test_object_image(self):
"""Test object-element with image type.""" """Test object-element with image type."""
elem = get_webelem(tagname='object', attributes={'type': 'image/gif'}) elem = get_webelem(tagname='object', attributes={'type': 'image/gif'})
self.assertFalse(elem.is_editable()) assert not elem.is_editable()
@mock.patch('qutebrowser.browser.webelem.config', new=stubs.ConfigStub( def test_object_application(self, stub_config):
{'input': {'insert-mode-on-plugins': True}}))
def test_object_application(self):
"""Test object-element with application type.""" """Test object-element with application type."""
stub_config.data['input']['insert-mode-on-plugins'] = True
elem = get_webelem(tagname='object', elem = get_webelem(tagname='object',
attributes={'type': 'application/foo'}) attributes={'type': 'application/foo'})
self.assertTrue(elem.is_editable()) assert elem.is_editable()
@mock.patch('qutebrowser.browser.webelem.config', new=stubs.ConfigStub( def test_object_application_false(self, stub_config):
{'input': {'insert-mode-on-plugins': False}}))
def test_object_application_false(self):
"""Test object-element with application type but not ...-on-plugins.""" """Test object-element with application type but not ...-on-plugins."""
stub_config.data['input']['insert-mode-on-plugins'] = False
elem = get_webelem(tagname='object', elem = get_webelem(tagname='object',
attributes={'type': 'application/foo'}) attributes={'type': 'application/foo'})
self.assertFalse(elem.is_editable()) assert not elem.is_editable()
@mock.patch('qutebrowser.browser.webelem.config', new=stubs.ConfigStub( def test_object_classid(self, stub_config):
{'input': {'insert-mode-on-plugins': True}}))
def test_object_classid(self):
"""Test object-element with classid.""" """Test object-element with classid."""
stub_config.data['input']['insert-mode-on-plugins'] = True
elem = get_webelem(tagname='object', elem = get_webelem(tagname='object',
attributes={'type': 'foo', 'classid': 'foo'}) attributes={'type': 'foo', 'classid': 'foo'})
self.assertTrue(elem.is_editable()) assert elem.is_editable()
@mock.patch('qutebrowser.browser.webelem.config', new=stubs.ConfigStub( def test_object_classid_false(self, stub_config):
{'input': {'insert-mode-on-plugins': False}}))
def test_object_classid_false(self):
"""Test object-element with classid but not insert-mode-on-plugins.""" """Test object-element with classid but not insert-mode-on-plugins."""
stub_config.data['input']['insert-mode-on-plugins'] = False
elem = get_webelem(tagname='object', elem = get_webelem(tagname='object',
attributes={'type': 'foo', 'classid': 'foo'}) attributes={'type': 'foo', 'classid': 'foo'})
self.assertFalse(elem.is_editable()) assert not elem.is_editable()
def test_div_empty(self): def test_div_empty(self):
"""Test div-element without class.""" """Test div-element without class."""
elem = get_webelem(tagname='div') elem = get_webelem(tagname='div')
self.assertFalse(elem.is_editable()) assert not elem.is_editable()
def test_div_noneditable(self): def test_div_noneditable(self):
"""Test div-element with non-editableclass.""" """Test div-element with non-editableclass."""
elem = get_webelem(tagname='div', classes='foo-kix-bar') elem = get_webelem(tagname='div', classes='foo-kix-bar')
self.assertFalse(elem.is_editable()) assert not elem.is_editable()
def test_div_xik(self): def test_div_xik(self):
"""Test div-element with xik class.""" """Test div-element with xik class."""
elem = get_webelem(tagname='div', classes='foo kix-foo') elem = get_webelem(tagname='div', classes='foo kix-foo')
self.assertTrue(elem.is_editable()) assert elem.is_editable()
def test_div_xik_caps(self): def test_div_xik_caps(self):
"""Test div-element with xik class in caps. """Test div-element with xik class in caps.
@ -550,13 +551,11 @@ class IsEditableTests(unittest.TestCase):
This tests if classes are case sensitive as they should. This tests if classes are case sensitive as they should.
""" """
elem = get_webelem(tagname='div', classes='KIX-FOO') elem = get_webelem(tagname='div', classes='KIX-FOO')
self.assertFalse(elem.is_editable()) assert not elem.is_editable()
def test_div_codemirror(self): def test_div_codemirror(self):
"""Test div-element with codemirror class.""" """Test div-element with codemirror class."""
elem = get_webelem(tagname='div', classes='foo CodeMirror-foo') elem = get_webelem(tagname='div', classes='foo CodeMirror-foo')
self.assertTrue(elem.is_editable()) assert elem.is_editable()
if __name__ == '__main__':
unittest.main()