Skip to content

Commit 71d58d0

Browse files
Ajay SaxenaAjay Saxena
Ajay Saxena
authored and
Ajay Saxena
committed
testing encoding in kwargs to to_clipboard and test case for the same
1 parent 02f87b0 commit 71d58d0

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

pandas/io/clipboard.py

+6
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,12 @@ def to_clipboard(obj, excel=None, sep=None, **kwargs): # pragma: no cover
7474
- Windows:
7575
- OS X:
7676
"""
77+
encoding = kwargs.get('encoding')
78+
79+
#testing if an invalid encoding is passed to clipboard
80+
if encoding is not None and encoding is not 'utf-8':
81+
raise ValueError('clipboard only supports utf-8 encoding')
82+
7783
from pandas.util.clipboard import clipboard_set
7884
if excel is None:
7985
excel = True

pandas/io/tests/test_clipboard.py

+8
Original file line numberDiff line numberDiff line change
@@ -117,3 +117,11 @@ def test_read_clipboard_infer_excel(self):
117117

118118
tm.assert_frame_equal(res, exp)
119119

120+
#test case for testing invalid encoding
121+
def test_invalid_encoding(self):
122+
data = self.data['string']
123+
with tm.assertRaises(ValueError):
124+
data.to_clipboard(encoding='ascii')
125+
126+
127+

0 commit comments

Comments
 (0)