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'))