Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_output_to_clipboard():
_reprex_basic('x = "hi there"; print(x)')
assert pyperclip.paste() == '```python\nx = "hi there"; ' \
'print(x)\n#> hi there\n```'
def test_transpositionEncryptProgram(self):
proc = subprocess.Popen('c:\\python32\\python.exe transpositionEncrypt.py', stdout=subprocess.PIPE)
procOut = proc.communicate()[0].decode('ascii')
# encrypting 'Common sense is not so common.' with key 8
self.assertEqual(procOut, 'Cenoonommstmme oo snnio. s s c|\n')
self.assertEqual(pyperclip.paste().decode('ascii'), 'Cenoonommstmme oo snnio. s s c')
with mock.patch('pyperclip.copy') as pc:
tctx.command(c.clip, "@all", "request.method")
assert pc.called
with mock.patch('pyperclip.copy') as pc:
tctx.command(c.clip, "@all", "request.content")
assert pc.called
with mock.patch('pyperclip.copy') as pc:
tctx.command(c.clip, "@all", "request.method,request.content")
assert pc.called
with mock.patch('pyperclip.copy') as pc:
log_message = "Pyperclip could not find a " \
"copy/paste mechanism for your system."
pc.side_effect = pyperclip.PyperclipException(log_message)
tctx.command(c.clip, "@all", "request.method")
assert tctx.master.has_log(log_message, level="error")
with taddons.context() as tctx:
with pytest.raises(exceptions.CommandError):
e.clip("nonexistent", tflow.tflow(resp=True))
with mock.patch('pyperclip.copy') as pc:
e.clip("raw", tflow.tflow(resp=True))
assert pc.called
with mock.patch('pyperclip.copy') as pc:
e.clip("curl", tflow.tflow(resp=True))
assert pc.called
with mock.patch('pyperclip.copy') as pc:
log_message = "Pyperclip could not find a " \
"copy/paste mechanism for your system."
pc.side_effect = pyperclip.PyperclipException(log_message)
e.clip("raw", tflow.tflow(resp=True))
assert tctx.master.has_log(log_message, level="error")
self.copy(-1)
self.assertEqual(self.paste(), '-1')
# Test copying a float.
self.copy(3.141592)
self.assertEqual(self.paste(), '3.141592')
# Test copying bools.
self.copy(True)
self.assertEqual(self.paste(), 'True')
self.copy(False)
self.assertEqual(self.paste(), 'False')
# All other non-str values raise an exception.
with self.assertRaises(PyperclipException):
self.copy(None)
with self.assertRaises(PyperclipException):
self.copy([2, 4, 6, 8])
def setupAndStart(testRoot, extraParameters=[], debugInformation=True, waitTime=DELAY_REFERENCE):
"""
@brief setup and start netedit
"""
if os.name == "posix":
# to work around non working gtk clipboard
pyperclip.set_clipboard("xclip")
# Open Netedit
neteditProcess = Popen(extraParameters, debugInformation)
# atexit.register(quit, neteditProcess, False, False)
# print debug information
print("TestFunctions: Netedit opened successfully")
# Wait for Netedit reference
return neteditProcess, getReferenceMatch(neteditProcess, waitTime)
import PyQt4
except ImportError:
pass
else:
clipboard = init_qt_clipboard()
else:
clipboard = init_qt_clipboard()
class TestXClip(_TestClipboard):
if _executable_exists("xclip"):
clipboard = init_xclip_clipboard()
class TestXSel(_TestClipboard):
if _executable_exists("xsel"):
clipboard = init_xsel_clipboard()
class TestKlipper(_TestClipboard):
if _executable_exists("klipper") and _executable_exists("qdbus"):
clipboard = init_klipper_clipboard()
class TestNoClipboard(unittest.TestCase):
copy, paste = init_no_clipboard()
def test_copy(self):
with self.assertRaises(RuntimeError):
self.copy("foo")
def test_paste(self):
else:
clipboard = init_qt_clipboard()
class TestXClip(_TestClipboard):
if _executable_exists("xclip"):
clipboard = init_xclip_clipboard()
class TestXSel(_TestClipboard):
if _executable_exists("xsel"):
clipboard = init_xsel_clipboard()
class TestKlipper(_TestClipboard):
if _executable_exists("klipper") and _executable_exists("qdbus"):
clipboard = init_klipper_clipboard()
class TestNoClipboard(unittest.TestCase):
copy, paste = init_no_clipboard()
def test_copy(self):
with self.assertRaises(RuntimeError):
self.copy("foo")
def test_paste(self):
with self.assertRaises(RuntimeError):
self.paste()
if __name__ == '__main__':
if HAS_DISPLAY:
try:
import PyQt5
except ImportError:
try:
import PyQt4
except ImportError:
pass
else:
clipboard = init_qt_clipboard()
else:
clipboard = init_qt_clipboard()
class TestXClip(_TestClipboard):
if _executable_exists("xclip"):
clipboard = init_xclip_clipboard()
class TestXSel(_TestClipboard):
if _executable_exists("xsel"):
clipboard = init_xsel_clipboard()
class TestKlipper(_TestClipboard):
if _executable_exists("klipper") and _executable_exists("qdbus"):
clipboard = init_klipper_clipboard()
class TestNoClipboard(unittest.TestCase):
copy, paste = init_no_clipboard()
def test_determineFunctionSet(self):
self.assertIn(pyperclip.determineFunctionSet(), ALL_FUNCTION_SETS)