|
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 | 13 |
|
14 | 14 |
|
15 | 15 | try:
|
|
18 | 18 | raise nose.SkipTest("no clipboard found")
|
19 | 19 |
|
20 | 20 |
|
21 |
| - |
22 | 21 | class TestClipboard(tm.TestCase):
|
23 | 22 |
|
24 | 23 | @classmethod
|
@@ -52,23 +51,24 @@ def setUpClass(cls):
|
52 | 51 | # Test for non-ascii text: GH9263
|
53 | 52 | cls.data['nonascii'] = pd.DataFrame({'en': 'in English'.split(),
|
54 | 53 | 'es': 'en español'.split()})
|
55 |
| - |
56 |
| - # unicode round trip test for GH 13747 |
57 |
| - cls.data['utf8'] = pd.DataFrame({'a':['µasd','Ωœ∑´'], 'b':['øπ∆˚¬','œ∑´®']}) |
| 54 | + # unicode round trip test for GH 13747 |
| 55 | + cls.data['utf8'] = pd.DataFrame({'a': ['µasd', 'Ωœ∑´'], |
| 56 | + 'b': ['øπ∆˚¬', 'œ∑´®']}) |
58 | 57 | cls.data_types = list(cls.data.keys())
|
59 | 58 |
|
60 | 59 | @classmethod
|
61 | 60 | def tearDownClass(cls):
|
62 | 61 | super(TestClipboard, cls).tearDownClass()
|
63 | 62 | del cls.data_types, cls.data
|
64 | 63 |
|
65 |
| - def check_round_trip_frame(self, data_type, excel=None, sep=None): |
| 64 | + def check_round_trip_frame(self, data_type, excel=None, sep=None, |
| 65 | + encoding=None): |
66 | 66 | data = self.data[data_type]
|
67 |
| - data.to_clipboard(excel=excel, sep=sep) |
| 67 | + data.to_clipboard(excel=excel, sep=sep, encoding=encoding) |
68 | 68 | if sep is not None:
|
69 |
| - result = read_clipboard(sep=sep, index_col=0) |
| 69 | + result = read_clipboard(sep=sep, index_col=0, encoding=encoding) |
70 | 70 | else:
|
71 |
| - result = read_clipboard() |
| 71 | + result = read_clipboard(encoding=encoding) |
72 | 72 | tm.assert_frame_equal(data, result, check_dtype=False)
|
73 | 73 |
|
74 | 74 | def test_round_trip_frame_sep(self):
|
@@ -117,23 +117,15 @@ def test_read_clipboard_infer_excel(self):
|
117 | 117 |
|
118 | 118 | tm.assert_frame_equal(res, exp)
|
119 | 119 |
|
120 |
| - #test case for testing invalid encoding |
| 120 | + # test case for testing invalid encoding |
121 | 121 | def test_invalid_encoding(self):
|
122 | 122 | data = self.data['string']
|
123 | 123 | with tm.assertRaises(ValueError):
|
124 | 124 | data.to_clipboard(encoding='ascii')
|
125 | 125 | with tm.assertRaises(NotImplementedError):
|
126 |
| - pd.read_clipboard(encoding='ascii') |
| 126 | + pd.read_clipboard(encoding='ascii') |
127 | 127 |
|
128 | 128 | def test_round_trip_valid_encodings(self):
|
129 |
| - for enc in ['UTF-8','utf-8','utf8']: |
| 129 | + for enc in ['UTF-8', 'utf-8', 'utf8']: |
130 | 130 | for dt in self.data_types:
|
131 |
| - data = self.data[dt] |
132 |
| - data.to_clipboard(encoding=enc) |
133 |
| - result = read_clipboard() |
134 |
| - tm.assert_frame_equal(data, result, check_dtype=False) |
135 |
| - |
136 |
| - |
137 |
| - |
138 |
| - |
139 |
| - |
| 131 | + self.check_round_trip_frame(dt, encoding=enc) |
0 commit comments