|
9 | 9 | from pandas import read_clipboard
|
10 | 10 | from pandas import get_option
|
11 | 11 | from pandas.util import testing as tm
|
12 |
| -from pandas.util.testing import makeCustomDataframe as mkdf, disabled |
| 12 | +from pandas.util.testing import makeCustomDataframe as mkdf |
| 13 | +from pandas.util.clipboard.exceptions import PyperclipException |
13 | 14 |
|
14 | 15 |
|
15 | 16 | try:
|
16 |
| - import pandas.util.clipboard # noqa |
17 |
| -except OSError: |
18 |
| - raise nose.SkipTest("no clipboard found") |
| 17 | + DataFrame({'A': [1, 2]}).to_clipboard() |
| 18 | +except PyperclipException: |
| 19 | + raise nose.SkipTest("clipboard primitives not installed") |
19 | 20 |
|
20 | 21 |
|
21 |
| -@disabled |
22 | 22 | class TestClipboard(tm.TestCase):
|
23 | 23 |
|
24 | 24 | @classmethod
|
@@ -52,20 +52,24 @@ def setUpClass(cls):
|
52 | 52 | # Test for non-ascii text: GH9263
|
53 | 53 | cls.data['nonascii'] = pd.DataFrame({'en': 'in English'.split(),
|
54 | 54 | 'es': 'en español'.split()})
|
| 55 | + # unicode round trip test for GH 13747, GH 12529 |
| 56 | + cls.data['utf8'] = pd.DataFrame({'a': ['µasd', 'Ωœ∑´'], |
| 57 | + 'b': ['øπ∆˚¬', 'œ∑´®']}) |
55 | 58 | cls.data_types = list(cls.data.keys())
|
56 | 59 |
|
57 | 60 | @classmethod
|
58 | 61 | def tearDownClass(cls):
|
59 | 62 | super(TestClipboard, cls).tearDownClass()
|
60 | 63 | del cls.data_types, cls.data
|
61 | 64 |
|
62 |
| - def check_round_trip_frame(self, data_type, excel=None, sep=None): |
| 65 | + def check_round_trip_frame(self, data_type, excel=None, sep=None, |
| 66 | + encoding=None): |
63 | 67 | data = self.data[data_type]
|
64 |
| - data.to_clipboard(excel=excel, sep=sep) |
| 68 | + data.to_clipboard(excel=excel, sep=sep, encoding=encoding) |
65 | 69 | if sep is not None:
|
66 |
| - result = read_clipboard(sep=sep, index_col=0) |
| 70 | + result = read_clipboard(sep=sep, index_col=0, encoding=encoding) |
67 | 71 | else:
|
68 |
| - result = read_clipboard() |
| 72 | + result = read_clipboard(encoding=encoding) |
69 | 73 | tm.assert_frame_equal(data, result, check_dtype=False)
|
70 | 74 |
|
71 | 75 | def test_round_trip_frame_sep(self):
|
@@ -115,3 +119,16 @@ def test_read_clipboard_infer_excel(self):
|
115 | 119 | exp = pd.read_clipboard()
|
116 | 120 |
|
117 | 121 | tm.assert_frame_equal(res, exp)
|
| 122 | + |
| 123 | + def test_invalid_encoding(self): |
| 124 | + # test case for testing invalid encoding |
| 125 | + data = self.data['string'] |
| 126 | + with tm.assertRaises(ValueError): |
| 127 | + data.to_clipboard(encoding='ascii') |
| 128 | + with tm.assertRaises(NotImplementedError): |
| 129 | + pd.read_clipboard(encoding='ascii') |
| 130 | + |
| 131 | + def test_round_trip_valid_encodings(self): |
| 132 | + for enc in ['UTF-8', 'utf-8', 'utf8']: |
| 133 | + for dt in self.data_types: |
| 134 | + self.check_round_trip_frame(dt, encoding=enc) |
0 commit comments