From c30e2559f7852a8557b0fc454f9e49b04fa2ce2b Mon Sep 17 00:00:00 2001 From: John Helmert Date: Wed, 12 Jun 2019 19:49:05 -0500 Subject: [PATCH] Add test for OSX copy() to clipboard --- tests/test_clipboard.py | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/tests/test_clipboard.py b/tests/test_clipboard.py index 96aec4e..1b8c5eb 100644 --- a/tests/test_clipboard.py +++ b/tests/test_clipboard.py @@ -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'))