Add test for OSX copy() to clipboard
This commit is contained in:
@@ -16,14 +16,14 @@ except ImportError:
|
|||||||
def test_copy():
|
def test_copy():
|
||||||
|
|
||||||
with mock.patch('subprocess.Popen') as Popen, \
|
with mock.patch('subprocess.Popen') as Popen, \
|
||||||
mock.patch('subprocess.call') as call:
|
mock.patch('subprocess.call', return_value=0) as call:
|
||||||
|
|
||||||
# Mock out the subprocess calls
|
# Mock out the subprocess calls
|
||||||
p = mock.Mock()
|
p = mock.Mock()
|
||||||
p.communicate = mock.Mock()
|
p.communicate = mock.Mock()
|
||||||
|
|
||||||
Popen.return_value = p
|
Popen.return_value = p
|
||||||
|
|
||||||
call.return_value = 0
|
|
||||||
copy('test', 'xsel -b -i')
|
copy('test', 'xsel -b -i')
|
||||||
assert Popen.call_args[0][0] == ['xsel', '-b', '-i']
|
assert Popen.call_args[0][0] == ['xsel', '-b', '-i']
|
||||||
p.communicate.assert_called_with(input='test'.encode('utf-8'))
|
p.communicate.assert_called_with(input='test'.encode('utf-8'))
|
||||||
@@ -32,4 +32,16 @@ def test_copy():
|
|||||||
assert Popen.call_args[0][0] == ['xclip']
|
assert Popen.call_args[0][0] == ['xclip']
|
||||||
p.communicate.assert_called_with(input='test ❤'.encode('utf-8'))
|
p.communicate.assert_called_with(input='test ❤'.encode('utf-8'))
|
||||||
|
|
||||||
# Need OSX tests, can't simulate sys.platform
|
with mock.patch('subprocess.Popen') as Popen, \
|
||||||
|
mock.patch('subprocess.call', return_value=0) as call:
|
||||||
|
|
||||||
|
# Simulate OSX
|
||||||
|
mock.patch('sys.platform', return_value='darwin')
|
||||||
|
|
||||||
|
p = mock.Mock()
|
||||||
|
p.communicate = mock.Mock()
|
||||||
|
Popen.return_value = p
|
||||||
|
|
||||||
|
copy('test', 'pbcopy w')
|
||||||
|
assert Popen.call_args[0][0] == ['pbcopy', 'w']
|
||||||
|
p.communicate.assert_called_with(input='test'.encode('utf-8'))
|
||||||
|
|||||||
Reference in New Issue
Block a user