forked from autokey/autokey
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_clipboard.py
More file actions
121 lines (103 loc) · 4.28 KB
/
Copy pathtest_clipboard.py
File metadata and controls
121 lines (103 loc) · 4.28 KB
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
# Copyright (C) 2021 BlueDrink9
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import logging
from datetime import datetime
import unittest
from unittest.mock import patch
import pytest
skip = pytest.mark.skip
import hamcrest as hm
import autokey
# Needs to be set before importing scripting
autokey.common.USED_UI_TYPE = "headless"
import autokey.scripting as api
import autokey.scripting.clipboard_gtk
import autokey.scripting.clipboard_qt
import autokey.scripting.clipboard_tkinter
import autokey.sys_interface.clipboard
logger = __import__("autokey.logger").logger.get_logger(__name__)
def get_errors_in_log(caplog):
errors = [record for record in caplog.get_records('call') if record.levelno >= logging.ERROR]
return errors
@skip(reason="selection clipboard not implemented")
def test_tkinter_selection_clipboard():
# Note: this test does not test that the *system* clipboard is actually
# filled, it just tests that the tk object clipboard is.
#
# Add current time to ensure fresh test string
now = datetime.now()
test_string = "this is the new clipboard contents {}".format(now)
b = api.clipboard_tkinter.TkClipboard()
b.fill_selection(test_string)
hm.assert_that(
b.get_selection(),
hm.equal_to(test_string),
"Selection clipboard is not the same as what it was filled with!"
)
def test_tkinter_clipboard():
# Note: this test does not test that the *system* clipboard is actually
# filled, it just tests that the tk object clipboard is.
#
# Add current time to ensure fresh test string
now = datetime.now()
test_string = "this is the new clipboard contents {}".format(now)
b = api.clipboard_tkinter.TkClipboard()
b.fill_clipboard(test_string)
hm.assert_that(
b.get_clipboard(),
hm.equal_to(test_string),
"Clipboard is not the same as what it was filled with!"
)
def test_tkinter_clipboard_from_interface():
# Note: this test does not test that the *system* clipboard is actually
# filled, it just tests that the tk object clipboard is.
# Add current time to ensure fresh test string
now = datetime.now()
test_string = "this is the new clipboard contents {}".format(now)
b = autokey.sys_interface.clipboard.Clipboard()
# Need to overwrite to ensure it hasn't picked up a qtclipboard somewhere.
b.cb = autokey.scripting.clipboard_tkinter.TkClipboard()
# uses a setter that sets the clipboard rather than an internal variable
b.text = test_string
hm.assert_that(
b.text,
hm.equal_to(test_string),
"Clipboard is not the same as what it was filled with!"
)
def test_gtk_clipboard():
# Without a gtkapp, this clipboard does not work.
# This test is purely to test the code path has no syntax errors.
now = datetime.now()
test_string = "this is the new clipboard contents {}".format(now)
b = api.clipboard_gtk.GtkClipboard()
# uses a setter that sets the clipboard rather than an internal variable
b.text = test_string
print(b.text)
# hm.assert_that(
# b.text,
# hm.equal_to(test_string),
# "Clipboard is not the same as what it was filled with!"
# )
def test_qt_clipboard():
# Without a gtkapp, this clipboard does not work.
# This test is purely to test the code path has no syntax errors.
now = datetime.now()
test_string = "this is the new clipboard contents {}".format(now)
b = api.clipboard_qt.QtClipboard()
# uses a setter that sets the clipboard rather than an internal variable
b.text = test_string
print(b.text)
# hm.assert_that(
# b.text,
# hm.equal_to(test_string),
# "Clipboard is not the same as what it was filled with!"
# )