-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
/
test_reporterror.py
135 lines (107 loc) · 5.04 KB
/
test_reporterror.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# -*- coding: utf-8 -*-
# -----------------------------------------------------------------------------
# Copyright © Spyder Project Contributors
#
# Licensed under the terms of the MIT License
# (see spyder/__init__.py for details)
# -----------------------------------------------------------------------------
"""Tests for the report error dialog."""
from unittest.mock import Mock, MagicMock
# Third party imports
import pytest
from qtpy.QtCore import Qt, QUrl
# Local imports
from spyder import __project_url__
from spyder.widgets.reporterror import (DESC_MIN_CHARS, TITLE_MIN_CHARS,
SpyderErrorDialog)
# =============================================================================
# Fixtures
# =============================================================================
@pytest.fixture
def error_dialog(qtbot):
"""Set up error report dialog."""
widget = SpyderErrorDialog(None)
qtbot.addWidget(widget)
widget.show()
return widget
# =============================================================================
# Tests
# =============================================================================
def test_dialog(error_dialog, qtbot):
"""Test that error report dialog UI behaves properly."""
dlg = error_dialog
desc_text = "1" * DESC_MIN_CHARS
title_text = "1" * TITLE_MIN_CHARS
# Assert Submit button is disabled at first
assert not dlg.submit_btn.isEnabled()
# Introduce MIN_CHARS to input_description
qtbot.keyClicks(dlg.input_description, desc_text)
qtbot.keyClicks(dlg.title, title_text)
# Assert Submit button is now enabled
assert dlg.submit_btn.isEnabled()
# Assert cut leaves the header
dlg.input_description.selectAll()
dlg.input_description.cut()
assert dlg.input_description.toPlainText() == dlg.input_description.header
# Assert delete leaves the header
qtbot.keyClicks(dlg.input_description, desc_text)
dlg.input_description.selectAll()
dlg.input_description.delete()
assert dlg.input_description.toPlainText() == dlg.input_description.header
# Assert delete doesn't remove characters on the header
ini_pos = dlg.input_description.get_position('sof')
dlg.input_description.set_cursor_position(ini_pos)
dlg.input_description.delete()
assert dlg.input_description.toPlainText() == dlg.input_description.header
# Assert backspace works as expected
qtbot.keyClicks(dlg.input_description, desc_text)
qtbot.keyPress(dlg.input_description, Qt.Key_Backspace)
assert not dlg.submit_btn.isEnabled()
dlg.input_description.selectAll()
qtbot.keyPress(dlg.input_description, Qt.Key_Backspace)
assert dlg.input_description.toPlainText() == dlg.input_description.header
ini_pos = dlg.input_description.get_position('sof')
dlg.input_description.set_cursor_position(ini_pos)
dlg.input_description.set_cursor_position('eol')
qtbot.keyPress(dlg.input_description, Qt.Key_Backspace)
assert dlg.input_description.toPlainText() == dlg.input_description.header
# Assert chars label works as expected
assert dlg.desc_chars_label.text() == '{} more characters to go...'.format(DESC_MIN_CHARS)
qtbot.keyClicks(dlg.input_description, desc_text)
assert dlg.desc_chars_label.text() == 'Description complete; thanks!'
def test_report_issue_url(monkeypatch):
"""Test that report_issue sends the data, and to correct url."""
body = 'This is an example error report body text.'
title = 'Uncreative issue title here'
target_url_base = __project_url__ + '/issues/new'
MockQDesktopServices = MagicMock()
attr_to_patch = ('spyder.widgets.reporterror.QDesktopServices')
monkeypatch.setattr(attr_to_patch, MockQDesktopServices)
# Test when body != None, i.e. when auto-submitting error to Github
target_url = QUrl(target_url_base + '?body=' + body)
SpyderErrorDialog.open_web_report(body=body, title=None)
assert MockQDesktopServices.openUrl.call_count == 1
MockQDesktopServices.openUrl.assert_called_with(target_url)
# Test when body != None and title != None
target_url = QUrl(target_url_base + '?body=' + body
+ "&title=" + title)
SpyderErrorDialog.open_web_report(body=body, title=title)
assert MockQDesktopServices.openUrl.call_count == 2
MockQDesktopServices.openUrl.assert_called_with(target_url)
def test_render_issue():
"""Test that render issue works without errors and returns text."""
test_description = "This is a test description"
test_traceback = "An error occurred. Oh no!"
# Test when description and traceback are not provided
test_issue_1 = SpyderErrorDialog.render_issue()
assert type(test_issue_1) == str
assert len(test_issue_1) > 100
# Test when description and traceback are provided
test_issue_2 = SpyderErrorDialog.render_issue(
test_description, test_traceback)
assert type(test_issue_2) == str
assert len(test_issue_2) > 100
assert test_description in test_issue_2
assert test_traceback in test_issue_2
if __name__ == "__main__":
pytest.main()