Exemplo n.º 1
0
    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(), "")

        # Test formats=format_unicode.
        # Set the system clipboard before testing.
        text1 = u"unicode text"
        c1 = Clipboard(contents={format_unicode: text1})
        c1.copy_to_system()
        c2 = Clipboard()
        c2.copy_from_system(formats=format_unicode)
        self.assertTrue(c2.has_format(format_unicode))
        self.assertEqual(c2.get_format(format_unicode), text1)

        # Test formats=format_text.
        # Set the system clipboard before testing.
        text2 = b"text"
        c1 = Clipboard(contents={format_text: text2})
        c1.copy_to_system()
        c2 = Clipboard()
        c2.copy_from_system(formats=format_text)
        self.assertTrue(c2.has_format(format_text))
        self.assertEqual(c2.get_format(format_text), text2)

        # Test formats=(format_unicode, format_text).
        # Set the system clipboard before testing. Use the same string for
        # both formats so the test will work on all platforms.
        c1 = Clipboard(contents={
            format_text: b"text",
            format_unicode: u"text"
        })
        c1.copy_to_system()
        c2 = Clipboard()
        c2.copy_from_system(formats=(format_unicode, format_text))
        self.assertTrue(c2.has_format(format_unicode))
        self.assertEqual(c2.get_format(format_unicode), u"text")
        self.assertTrue(c2.has_format(format_text))
        self.assertEqual(c2.get_format(format_text), b"text")
Exemplo n.º 2
0
    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(), "")