Fix and split clipboard tests into *nix and Darwin

This commit is contained in:
John Helmert
2019-06-29 21:30:08 -05:00
parent 54c4e5866d
commit 17a17f12d5
2 changed files with 11 additions and 9 deletions

View File

@@ -1,6 +1,8 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from __future__ import unicode_literals from __future__ import unicode_literals
import sys
import pytest import pytest
from tuir.clipboard import copy from tuir.clipboard import copy
@@ -13,7 +15,7 @@ except ImportError:
import mock import mock
def test_copy(): def test_copy_nix():
with mock.patch('subprocess.Popen') as Popen, \ with mock.patch('subprocess.Popen') as Popen, \
mock.patch('subprocess.call', return_value=0) as call: mock.patch('subprocess.call', return_value=0) as call:
@@ -28,20 +30,20 @@ def test_copy():
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'))
copy('test ❤', 'xclip') copy('test ❤')
assert Popen.call_args[0][0] == ['xclip'] assert Popen.call_args[0][0] == ['xclip', '-selection', '-clipboard']
p.communicate.assert_called_with(input='test ❤'.encode('utf-8')) p.communicate.assert_called_with(input='test ❤'.encode('utf-8'))
def test_copy_darwin():
with mock.patch('subprocess.Popen') as Popen, \ with mock.patch('subprocess.Popen') as Popen, \
mock.patch('subprocess.call', return_value=0) as call: mock.patch('subprocess.call', return_value=0) as call:
# Simulate OSX sys.platform = 'darwin'
mock.patch('sys.platform', return_value='darwin')
p = mock.Mock() p = mock.Mock()
p.communicate = mock.Mock() p.communicate = mock.Mock()
Popen.return_value = p Popen.return_value = p
copy('test', 'pbcopy w') copy('test')
assert Popen.call_args[0][0] == ['pbcopy', 'w'] assert Popen.call_args[0][0] == ['pbcopy', 'w']
p.communicate.assert_called_with(input='test'.encode('utf-8')) p.communicate.assert_called_with(input='test'.encode('utf-8'))

View File

@@ -9,7 +9,7 @@ def _subprocess_copy(text, args_list):
p.communicate(input=text.encode('utf-8')) p.communicate(input=text.encode('utf-8'))
def copy(text, cmd): def copy(text, cmd=None):
""" """
Copy text to OS clipboard. Copy text to OS clipboard.
""" """