forked from t4ngo/dragonfly
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rewrite Clipboard class using pyperclip + add tests
See issue t4ngo#15. - This makes the clipboard functionality work on other platforms. - The only supported Windows clipboard format is Unicode text. - The class should be backwards-compatibile assuming Unicode text is the only clipboard format used.
- Loading branch information
Showing
5 changed files
with
175 additions
and
145 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
# | ||
# This file is part of Dragonfly. | ||
# (c) Copyright 2007, 2008 by Christo Butcher | ||
# Licensed under the LGPL. | ||
# | ||
# Dragonfly is free software: you can redistribute it and/or modify it | ||
# under the terms of the GNU Lesser General Public License as published | ||
# by the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# Dragonfly 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 | ||
# Lesser General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU Lesser General Public | ||
# License along with Dragonfly. If not, see | ||
# <http://www.gnu.org/licenses/>. | ||
# | ||
|
||
import unittest | ||
|
||
from dragonfly import Clipboard | ||
|
||
|
||
class TestClipboard(unittest.TestCase): | ||
def setUp(self): | ||
# Clear the clipboard before each test. | ||
Clipboard.clear_clipboard() | ||
|
||
def test_system_text_methods(self): | ||
text = "testing testing" | ||
Clipboard.set_system_text(text) | ||
self.assertEqual(Clipboard.get_system_text(), text) | ||
|
||
def test_clear_clipboard(self): | ||
# Put something on the system clipboard. | ||
Clipboard.set_system_text("something") | ||
|
||
# Clear it. | ||
Clipboard.clear_clipboard() | ||
|
||
# Then test that it has been cleared. | ||
self.assertEqual(Clipboard.get_system_text(), "") | ||
|
||
def test_empty(self): | ||
# A new clipboard has no content for the unicode format. | ||
c = Clipboard() | ||
self.assertFalse(c.has_format(Clipboard.format_unicode)) | ||
|
||
# Neither does a new clipboard have text. | ||
self.assertFalse(c.has_text()) | ||
|
||
def test_from_system_argument(self): | ||
# Test the optional from_system argument of Clipboard.__init__ | ||
text = "something" | ||
Clipboard.set_system_text(text) | ||
c = Clipboard(from_system=True) | ||
self.assertEqual(c.text, text) | ||
self.assertTrue(c.has_format(Clipboard.format_unicode)) | ||
self.assertTrue(c.has_text()) | ||
|
||
def test_copy_from_system(self): | ||
text = "testing" | ||
Clipboard.set_system_text(text) | ||
c = Clipboard() | ||
|
||
# Test the method with clear=False (default) | ||
c.copy_from_system(clear=False) | ||
self.assertEqual(c.text, text) | ||
self.assertEqual(Clipboard.get_system_text(), text) | ||
|
||
# Test again with clear=True | ||
c = Clipboard() | ||
c.copy_from_system(clear=True) | ||
self.assertEqual(c.text, text) | ||
self.assertEqual(Clipboard.get_system_text(), "") | ||
|
||
def test_copy_to_system(self): | ||
text = "testing" | ||
c = Clipboard(text=text) | ||
c.copy_to_system() | ||
self.assertEqual(Clipboard.get_system_text(), text) | ||
|
||
def test_set_text(self): | ||
c = Clipboard() | ||
text = "test" | ||
c.set_text(text) | ||
self.assertTrue(c.has_text()) | ||
self.assertTrue(c.has_format(Clipboard.format_unicode)) | ||
self.assertEqual(c.get_text(), text) | ||
self.assertEqual(c.text, text) | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.