Skip to content

Commit

Permalink
clipboard: fixes for nspaste
Browse files Browse the repository at this point in the history
+ includes fixes for clipboard tests, they weren't working alone, SDL2 requires initialization/Window to work, but not nspaste. This allow also to run the test by itself.
This wasn't seen before because they were no test about testing if the content of the copy() is returned in paste(). Before paste() was just empty.
  • Loading branch information
tito committed Mar 5, 2019
1 parent 5462523 commit e5e2114
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
3 changes: 2 additions & 1 deletion kivy/core/clipboard/clipboard_nspaste.py
Expand Up @@ -37,7 +37,8 @@ def get(self, mimetype='text/plain'):
def put(self, data, mimetype='text/plain'):
pb = self._clipboard
pb.clearContents()
pb.writeObjects_([data])
utf8 = NSString.alloc().initWithUTF8String_(data)
pb.setString_forType_(utf8, 'public.utf8-plain-text')

def get_types(self):
return list('text/plain',)
12 changes: 10 additions & 2 deletions kivy/tests/test_clipboard.py
@@ -1,7 +1,7 @@
import unittest
from kivy.tests.common import GraphicUnitTest


class ClipboardTestCase(unittest.TestCase):
class ClipboardTestCase(GraphicUnitTest):

def setUp(self):
from kivy.core.clipboard import Clipboard
Expand All @@ -11,6 +11,7 @@ def setUp(self):
if 'UTF8_STRING' in clippy_types:
cliptype = 'UTF8_STRING'
self._cliptype = cliptype
super(ClipboardTestCase, self).setUp()

def test_clipboard_not_dummy(self):
clippy = self._clippy
Expand All @@ -32,3 +33,10 @@ def test_clipboard_copy(self):
except:
self.fail(
'Can not get put data to clipboard')

def test_clipboard_copy_paste(self):
clippy = self._clippy
txt1 = u"Hello 1"
clippy.copy(txt1)
ret = clippy.paste()
self.assertEqual(txt1, ret)

0 comments on commit e5e2114

Please sign in to comment.