Add test for OSX copy() to clipboard

This commit is contained in:
John Helmert
2019-06-12 19:49:05 -05:00
parent 7670c47d3f
commit c30e2559f7

View File

@@ -16,14 +16,14 @@ except ImportError:
def test_copy():
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
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'))
@@ -32,4 +32,16 @@ def test_copy():
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
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'))