How to use the pyperclip.setFunctions function in pyperclip

To help you get started, we’ve selected a few pyperclip examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github asweigart / pyperclip / tests / basicTests.py View on Github external
import pyperclip
from pyperclip import CYGWIN, WINDOWS, PBCOPY_PBPASTE, XCLIP, XSEL, KLIPPER, PYQT4, GTK

import platform
RUNNING_PY2 = '2' == platform.python_version_tuple()[0]

ALL_FUNCTION_SETS = (CYGWIN, WINDOWS, PBCOPY_PBPASTE, XCLIP, XSEL, KLIPPER, PYQT4, GTK)

# The user can specify which set of copy/paste functions to use instead of the default. The names are given as strings in OVERRIDE_FUNCTION_SET.
OVERRIDE_FUNCTION_SET = None
if len(sys.argv) > 1:
    OVERRIDE_FUNCTION_SET = sys.argv[1]
    assert OVERRIDE_FUNCTION_SET in ALL_FUNCTION_SETS, 'Function set specified must be one of: %s' % (ALL_FUNCTION_SETS)

if OVERRIDE_FUNCTION_SET is not None:
    pyperclip.setFunctions(OVERRIDE_FUNCTION_SET)

class TestCopyPaste(unittest.TestCase):
    def test_copyPaste(self):
        #pyVersion = '%s.%s.%s' % (sys.version_info[0], sys.version_info[1], sys.version_info[2])
        #print('Testing on: Python %s - %s' % (pyVersion, pyperclip._functions))
        msg = 'The quick brown fox jumped over the yellow lazy dog.'
        pyperclip.copy(msg)
        self.assertEqual(pyperclip.paste(), msg)

    def test_randomCopyPaste(self):
        # This random version of the test_copyPaste() test is so that previous text on the clipboard does not cause a false positive.
        random.seed = 42
        msg = list('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890' * 3)
        random.shuffle(msg)
        msg = ''.join(msg)
        pyperclip.copy(msg)