-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
/
Copy pathtest_basic_copy_paste.py
303 lines (227 loc) · 7.63 KB
/
test_basic_copy_paste.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
import dash
import pytest
from dash.dependencies import Input, Output, State
from dash.exceptions import PreventUpdate
from dash import html
from dash.dash_table import DataTable
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.action_chains import ActionChains
import pandas as pd
url = "https://github.com/plotly/datasets/raw/master/" "26k-consumer-complaints.csv"
rawDf = pd.read_csv(url)
df = rawDf.to_dict("records")
def get_app():
app = dash.Dash(__name__)
app.layout = html.Div(
[
DataTable(
id="table",
data=df[0:250],
columns=[
{"name": i, "id": i, "hideable": i == "Complaint ID"}
for i in rawDf.columns
],
editable=True,
sort_action="native",
include_headers_on_copy_paste=True,
),
DataTable(
id="table2",
data=df[0:10],
columns=[
{"name": i, "id": i, "deletable": True} for i in rawDf.columns
],
editable=True,
sort_action="native",
include_headers_on_copy_paste=True,
),
]
)
@app.callback(
Output("table", "data"),
[Input("table", "data_timestamp")],
[State("table", "data"), State("table", "data_previous")],
)
# pylint: disable=unused-argument
def update_data(timestamp, current, previous):
# pylint: enable=unused-argument
if timestamp is None or current is None or previous is None:
raise PreventUpdate
modified = False
if len(current) == len(previous):
for (i, datum) in enumerate(current):
previous_datum = previous[i]
if datum["Unnamed: 0"] != previous_datum["Unnamed: 0"]:
datum["Complaint ID"] = "MODIFIED"
modified = True
if modified:
return current
else:
raise PreventUpdate
return app
@pytest.mark.skip(
reason="Prop `data_previous` is not correctly updated with copy+paste"
)
def test_tbcp001_copy_paste_callback(test):
test.start_server(get_app())
target = test.table("table")
target.cell(0, 0).click()
test.copy()
target.cell(1, 0).click()
test.paste()
assert target.cell(1, 0).get_text() == "0"
assert target.cell(1, 1).get_text() == "MODIFIED"
assert test.get_log_errors() == []
@pytest.mark.skip(
reason="Prop `data_previous` is not correctly updated with copy+paste"
)
def test_tbcp002_sorted_copy_paste_callback(test):
test.start_server(get_app())
target = test.table("table")
target.column(rawDf.columns[2]).sort()
assert target.cell(0, 0).get_text() == "11"
target.cell(0, 0).click()
test.copy()
target.cell(1, 0).click()
test.paste()
assert target.cell(1, 0).get_text() == "11"
assert target.cell(1, 1).get_text() == "MODIFIED"
target.cell(1, 1).click()
test.copy()
target.cell(2, 1).click()
test.paste()
assert target.cell(1, 0).get_text() == "11"
assert target.cell(2, 1).get_text() == "MODIFIED"
assert test.get_log_errors() == []
@pytest.mark.parametrize("mouse_navigation", [True, False])
@pytest.mark.skip(
reason="Prop `data_previous` is not correctly updated with copy+paste"
)
def test_tbcp003_copy_multiple_rows(test, mouse_navigation):
test.start_server(get_app())
target = test.table("table")
if mouse_navigation:
with test.hold(Keys.SHIFT):
target.cell(0, 0).click()
target.cell(2, 0).click()
else:
target.cell(0, 0).click()
with test.hold(Keys.SHIFT):
test.send_keys(Keys.ARROW_DOWN + Keys.ARROW_DOWN)
test.copy()
target.cell(3, 0).click()
test.paste()
for i in range(3):
assert target.cell(i + 3, 0).get_text() == target.cell(i, 0).get_text()
assert target.cell(i + 3, 1).get_text() == "MODIFIED"
assert test.get_log_errors() == []
def test_tbcp004_copy_9_and_10(test):
test.start_server(get_app())
source = test.table("table")
target = test.table("table2")
source.cell(9, 0).click()
with test.hold(Keys.SHIFT):
ActionChains(test.driver).send_keys(Keys.DOWN).perform()
test.copy()
target.cell(0, 0).click()
test.paste()
for row in range(2):
for col in range(1):
assert (
target.cell(row, col).get_text() == source.cell(row + 9, col).get_text()
)
assert test.get_log_errors() == []
@pytest.mark.skip(
reason="Prop `data_previous` is not correctly updated with copy+paste"
)
def test_tbcp005_copy_multiple_rows_and_columns(test):
test.start_server(get_app())
target = test.table("table")
target.cell(0, 1).click()
with test.hold(Keys.SHIFT):
target.cell(2, 2).click()
test.copy()
target.cell(3, 1).click()
test.paste()
for row in range(3):
for col in range(1, 3):
assert (
target.cell(row + 3, col).get_text() == target.cell(row, col).get_text()
)
assert test.get_log_errors() == []
@pytest.mark.skip(
reason="Prop `data_previous` is not correctly updated with copy+paste"
)
def test_tbcp006_copy_paste_between_tables(test):
test.start_server(get_app())
source = test.table("table")
target = test.table("table2")
source.cell(10, 0).click()
with test.hold(Keys.SHIFT):
source.cell(13, 3).click()
test.copy()
target.cell(0, 0).click()
test.paste()
for row in range(4):
for col in range(4):
assert (
source.cell(row + 10, col).get_text()
== target.cell(row, col).get_text()
)
assert test.get_log_errors() == []
@pytest.mark.skip(
reason="Prop `data_previous` is not correctly updated with copy+paste"
)
def test_tbcp007_copy_paste_with_hidden_column(test):
test.start_server(get_app())
target = test.table("table")
target.column("Complaint ID").hide()
target.cell(0, 0).click()
with test.hold(Keys.SHIFT):
target.cell(2, 2).click()
test.copy()
target.cell(3, 1).click()
test.paste()
for row in range(3):
for col in range(3):
assert (
target.cell(row, col).get_text()
== target.cell(row + 3, col + 1).get_text()
)
assert test.get_log_errors() == []
@pytest.mark.skip(
reason="Prop `data_previous` is not correctly updated with copy+paste"
)
def test_tbcp008_copy_paste_between_tables_with_hidden_columns(test):
test.start_server(get_app())
target = test.table("table")
target.column("Complaint ID").hide()
target.cell(10, 0).click()
with test.hold(Keys.SHIFT):
target.cell(13, 2).click()
test.copy()
target.cell(0, 0).click()
test.paste()
for row in range(4):
for col in range(3):
assert (
target.cell(row + 10, col).get_text()
== target.cell(row, col).get_text()
)
assert test.get_log_errors() == []
def test_tbcp009_copy_9_and_10_click(test):
test.start_server(get_app())
source = test.table("table")
target = test.table("table2")
source.cell(9, 0).click()
with test.hold(Keys.SHIFT):
source.cell(10, 0).click()
test.copy()
target.cell(0, 0).click()
test.paste()
for row in range(2):
for col in range(1):
assert (
target.cell(row, col).get_text() == source.cell(row + 9, col).get_text()
)
assert test.get_log_errors() == []