Add config item clipboard_cmd, with a default of 'pbcopy w' on Darwin and 'xclip' on everything else. This will allow the user to use any command for the clipboard, including 'wl-copy' for Wayland (addressing issue #693 on Github). With his change, significant simplifications could be made to clipboard.py - the copy_*() functions have been removed and combined into copy(). With this simplification, the old OSX test is obsolete, and new OSX tests are needed (need a way to simulate sys.platform).
36 lines
888 B
Python
36 lines
888 B
Python
# -*- coding: utf-8 -*-
|
|
from __future__ import unicode_literals
|
|
|
|
import pytest
|
|
|
|
from rtv.clipboard import copy
|
|
from rtv.exceptions import ProgramError
|
|
|
|
|
|
try:
|
|
from unittest import mock
|
|
except ImportError:
|
|
import mock
|
|
|
|
|
|
def test_copy():
|
|
|
|
with mock.patch('subprocess.Popen') as Popen, \
|
|
mock.patch('subprocess.call') as call:
|
|
|
|
# Mock out the subprocess calls
|
|
p = mock.Mock()
|
|
p.communicate = mock.Mock()
|
|
Popen.return_value = p
|
|
|
|
call.return_value = 0
|
|
copy('test', 'xsel -b -i')
|
|
assert Popen.call_args[0][0] == ['xsel', '-b', '-i']
|
|
p.communicate.assert_called_with(input='test'.encode('utf-8'))
|
|
|
|
copy('test ❤', 'xclip')
|
|
assert Popen.call_args[0][0] == ['xclip']
|
|
p.communicate.assert_called_with(input='test ❤'.encode('utf-8'))
|
|
|
|
# Need OSX tests, can't simulate sys.platform
|