Ejemplo 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")
Ejemplo n.º 2
0
    def test_set_format(self):
        # Test with one format.
        text1 = u"unicode text"
        c = Clipboard()
        c.set_format(format_unicode, text1)
        self.assertTrue(c.has_format(format_unicode))
        self.assertEqual(c.get_format(format_unicode), text1)
        self.assertFalse(c.has_format(format_text))
        self.assertRaises(ValueError, c.get_format, format_text)

        # Test with two formats.
        text2 = b"text"
        c.set_format(format_text, text2)
        self.assertTrue(c.has_format(format_unicode))
        self.assertEqual(c.get_format(format_unicode), text1)
        self.assertTrue(c.has_format(format_text))
        self.assertEqual(c.get_format(format_text), text2)

        # Setting a format to None removes the format's content from the
        # instance.
        c.set_format(format_text, None)
        self.assertFalse(c.has_format(format_text))
        self.assertRaises(ValueError, c.get_format, format_text)
        c.set_format(format_unicode, None)
        self.assertFalse(c.has_format(format_unicode))
        self.assertRaises(ValueError, c.get_format, format_unicode)
Ejemplo n.º 3
0
    def test_has_format(self):
        # Test with an empty Clipboard instance.
        c = Clipboard()
        self.assertFalse(c.has_format(format_unicode))
        self.assertFalse(c.has_format(format_text))
        self.assertFalse(c.has_format(format_hdrop))

        # Test with one format.
        c = Clipboard(contents={format_unicode: u"unicode text"})
        self.assertTrue(c.has_format(format_unicode))
        self.assertFalse(c.has_format(format_text))

        # Test with two formats.
        c = Clipboard(contents={format_unicode: u"unicode text",
                                format_text: u"text"})
        self.assertTrue(c.has_format(format_unicode))
        self.assertTrue(c.has_format(format_text))