tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / pyuno / qa / pytests / testcollections_XCellRange.py
blob6ace0b11cba0b7ba064ada0cf4c5bcd5053d6be3
1 #!/usr/bin/env python
3 # This file is part of the LibreOffice project.
5 # This Source Code Form is subject to the terms of the Mozilla Public
6 # License, v. 2.0. If a copy of the MPL was not distributed with this
7 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 import unittest
12 from testcollections_base import CollectionsTestBase
13 from com.sun.star.table import CellAddress
15 # TextTable instance factory
16 def getTextTableInstance(doc):
17 return doc.createInstance('com.sun.star.text.TextTable')
19 # Tests behaviour of objects implementing XCellRange using the new-style
20 # collection accessors
22 class TestXCellRange(CollectionsTestBase):
24 # TODO negative indices
26 # Tests syntax:
27 # cell = cellrange[0,0] # Access cell by indices
28 # For:
29 # Spreadsheet
30 # Cell at Row 0, Col 0
31 def test_XCellRange_Spreadsheet_Cell_00(self):
32 # Given
33 spr = self.createBlankSpreadsheet()
34 sht = spr.Sheets[0]
36 # When
37 cell = sht[0, 0]
39 # Then
40 self.assertEqual(0, cell.CellAddress.Sheet)
41 self.assertEqual(0, cell.CellAddress.Row)
42 self.assertEqual(0, cell.CellAddress.Column)
44 spr.close(True)
46 # Tests syntax:
47 # cell = cellrange[0,0] # Access cell by indices
48 # For:
49 # Text table
50 # Cell at Row 0, Col 0
51 def test_XCellRange_Table_Cell_00(self):
52 # Given
53 doc = self.createBlankTextDocument()
54 text_table = getTextTableInstance(doc)
55 text_table.initialize(10, 10)
56 cursor = doc.Text.createTextCursor()
57 doc.Text.insertTextContent(cursor, text_table, False)
58 tbl = doc.TextTables[0]
60 # When
61 cell = tbl[0, 0]
63 # Then
64 self.assertEqual('A1', cell.CellName)
66 doc.close(True)
68 # Tests syntax:
69 # cell = cellrange[0,0] # Access cell by indices
70 # For:
71 # Spreadsheet
72 # Cell at Row 3, Col 7
73 def test_XCellRange_Spreadsheet_Cell_37(self):
74 # Given
75 spr = self.createBlankSpreadsheet()
76 sht = spr.Sheets[0]
78 # When
79 rng = sht[3, 7]
81 # Then
82 self.assertEqual(0, rng.CellAddress.Sheet)
83 self.assertEqual(3, rng.CellAddress.Row)
84 self.assertEqual(7, rng.CellAddress.Column)
86 spr.close(True)
88 # Tests syntax:
89 # cell = cellrange[0,0] # Access cell by indices
90 # For:
91 # Text table
92 # Cell at Row 3, Col 7
93 def test_XCellRange_Table_Cell_37(self):
94 # Given
95 doc = self.createBlankTextDocument()
96 text_table = getTextTableInstance(doc)
97 text_table.initialize(10, 10)
98 cursor = doc.Text.createTextCursor()
99 doc.Text.insertTextContent(cursor, text_table, False)
100 tbl = doc.TextTables[0]
102 # When
103 cell = tbl[3, 7]
105 # Then
106 self.assertEqual('H4', cell.CellName)
108 doc.close(True)
110 # Tests syntax:
111 # rng = cellrange[0,1:2] # Access cell range by index,slice
112 # For:
113 # Spreadsheet
114 def test_XCellRange_Spreadsheet_Range_Index_Slice(self):
115 # Given
116 spr = self.createBlankSpreadsheet()
117 sht = spr.Sheets[0]
119 # When
120 rng = sht[0, 1:3]
122 # Then
123 self.assertEqual(0, rng.RangeAddress.Sheet)
124 self.assertEqual(0, rng.RangeAddress.StartRow)
125 self.assertEqual(1, rng.RangeAddress.StartColumn)
126 self.assertEqual(0, rng.RangeAddress.EndRow)
127 self.assertEqual(2, rng.RangeAddress.EndColumn)
129 spr.close(True)
131 # Tests syntax:
132 # rng = cellrange[0,1:2] # Access cell range by index,slice
133 # For:
134 # Text table
135 def test_XCellRange_Table_Range_Index_Slice(self):
136 # Given
137 doc = self.createBlankTextDocument()
138 text_table = getTextTableInstance(doc)
139 text_table.initialize(10, 10)
140 cursor = doc.Text.createTextCursor()
141 doc.Text.insertTextContent(cursor, text_table, False)
142 tbl = doc.TextTables[0]
143 doc.lockControllers()
144 tbl.DataArray = tuple(tuple(str(100 + y) for y in range(10*x, 10*x + 10)) for x in range(10))
145 doc.unlockControllers()
147 # When
148 rng = tbl[0, 1:3]
150 # Then
151 self.assertEqual((('101', '102'),), rng.DataArray)
153 doc.close(True)
155 # Tests syntax:
156 # rng = cellrange[1:2,0] # Access cell range by slice,index
157 # For:
158 # Spreadsheet
159 def test_XCellRange_Spreadsheet_Range_Slice_Index(self):
160 # Given
161 spr = self.createBlankSpreadsheet()
162 sht = spr.Sheets[0]
164 # When
165 rng = sht[1:3, 0]
167 # Then
168 self.assertEqual(0, rng.RangeAddress.Sheet)
169 self.assertEqual(1, rng.RangeAddress.StartRow)
170 self.assertEqual(0, rng.RangeAddress.StartColumn)
171 self.assertEqual(2, rng.RangeAddress.EndRow)
172 self.assertEqual(0, rng.RangeAddress.EndColumn)
174 spr.close(True)
176 # Tests syntax:
177 # rng = cellrange[1:2,0] # Access cell range by index,slice
178 # For:
179 # Text table
180 def test_XCellRange_Table_Range_Slice_Index(self):
181 # Given
182 doc = self.createBlankTextDocument()
183 text_table = getTextTableInstance(doc)
184 text_table.initialize(10, 10)
185 cursor = doc.Text.createTextCursor()
186 doc.Text.insertTextContent(cursor, text_table, False)
187 tbl = doc.TextTables[0]
188 doc.lockControllers()
189 tbl.DataArray = tuple(tuple(str(100 + y) for y in range(10*x, 10*x + 10)) for x in range(10))
190 doc.unlockControllers()
192 # When
193 rng = tbl[1:3, 0]
195 # Then
196 self.assertEqual((('110',), ('120',)), rng.DataArray)
198 doc.close(True)
200 # Tests syntax:
201 # rng = cellrange[0:1,2:3] # Access cell range by slices
202 # For:
203 # Spreadsheet
204 def test_XCellRange_Spreadsheet_Range_Slices(self):
205 # Given
206 spr = self.createBlankSpreadsheet()
207 sht = spr.Sheets[0]
209 # When
210 rng = sht[1:3, 3:5]
212 # Then
213 self.assertEqual(0, rng.RangeAddress.Sheet)
214 self.assertEqual(1, rng.RangeAddress.StartRow)
215 self.assertEqual(3, rng.RangeAddress.StartColumn)
216 self.assertEqual(2, rng.RangeAddress.EndRow)
217 self.assertEqual(4, rng.RangeAddress.EndColumn)
219 spr.close(True)
221 # Tests syntax:
222 # rng = cellrange[0:1,2:3] # Access cell range by slices
223 # For:
224 # Spreadsheet
225 # Zero rows/columns
226 def test_XCellRange_Spreadsheet_Range_Slices_Invalid(self):
227 # Given
228 spr = self.createBlankSpreadsheet()
229 sht = spr.Sheets[0]
231 # When / Then
232 with self.assertRaises(KeyError):
233 _ = sht[1:1, 3:5]
234 with self.assertRaises(KeyError):
235 _ = sht[1:3, 3:3]
237 spr.close(True)
239 # Tests syntax:
240 # rng = cellrange[0:1,2:3] # Access cell range by slices
241 # For:
242 # Text table
243 def test_XCellRange_Table_Range_Slices(self):
244 # Given
245 doc = self.createBlankTextDocument()
246 text_table = getTextTableInstance(doc)
247 text_table.initialize(10, 10)
248 cursor = doc.Text.createTextCursor()
249 doc.Text.insertTextContent(cursor, text_table, False)
250 tbl = doc.TextTables[0]
251 doc.lockControllers()
252 tbl.DataArray = tuple(tuple(str(100 + y) for y in range(10*x, 10*x + 10)) for x in range(10))
253 doc.unlockControllers()
255 # When
256 rng = tbl[1:3, 3:5]
258 # Then
259 self.assertEqual((('113', '114'), ('123', '124')), rng.DataArray)
261 doc.close(True)
263 # Tests syntax:
264 # rng = cellrange['A1:B2'] # Access cell range by descriptor
265 # For:
266 # Spreadsheet
267 def test_XCellRange_Spreadsheet_Range_Descriptor(self):
268 # Given
269 spr = self.createBlankSpreadsheet()
270 sht = spr.Sheets[0]
272 # When
273 rng = sht['A3:B4']
275 # Then
276 self.assertEqual(0, rng.RangeAddress.Sheet)
277 self.assertEqual(2, rng.RangeAddress.StartRow)
278 self.assertEqual(0, rng.RangeAddress.StartColumn)
279 self.assertEqual(3, rng.RangeAddress.EndRow)
280 self.assertEqual(1, rng.RangeAddress.EndColumn)
282 spr.close(True)
284 # Tests syntax:
285 # rng = cellrange['A1:B2'] # Access cell range by descriptor
286 # For:
287 # Table
288 def test_XCellRange_Table_Range_Descriptor(self):
289 # Given
290 doc = self.createBlankTextDocument()
291 text_table = getTextTableInstance(doc)
292 text_table.initialize(10, 10)
293 cursor = doc.Text.createTextCursor()
294 doc.Text.insertTextContent(cursor, text_table, False)
295 tbl = doc.TextTables[0]
296 doc.lockControllers()
297 tbl.DataArray = tuple(tuple(str(100 + y) for y in range(10*x, 10*x + 10)) for x in range(10))
298 doc.unlockControllers()
300 # When
301 rng = tbl['A3:B4']
303 # Then
304 self.assertEqual((('120', '121'), ('130', '131')), rng.DataArray)
306 doc.close(True)
308 # Tests syntax:
309 # rng = cellrange['Name'] # Access cell range by name
310 # For:
311 # Spreadsheet
312 def test_XCellRange_Spreadsheet_Range_Name(self):
313 # Given
314 spr = self.createBlankSpreadsheet()
315 sht = spr.Sheets[0]
316 expr = '$' + sht.Name + '.$C2:F10'
317 addr = CellAddress(Sheet=0, Row=1, Column=2)
318 sht.NamedRanges.addNewByName('foo', expr, addr, 0)
320 # When
321 rng = sht['foo']
323 # Then
324 self.assertEqual(0, rng.RangeAddress.Sheet)
325 self.assertEqual(1, rng.RangeAddress.StartRow)
326 self.assertEqual(2, rng.RangeAddress.StartColumn)
327 self.assertEqual(9, rng.RangeAddress.EndRow)
328 self.assertEqual(5, rng.RangeAddress.EndColumn)
330 spr.close(True)
332 # Tests syntax:
333 # rng = cellrange[0] # Access cell range by row index
334 # For:
335 # Spreadsheet
336 def test_XCellRange_Spreadsheet_Range_RowIndex(self):
337 # Given
338 spr = self.createBlankSpreadsheet()
339 sht = spr.Sheets[0]
341 # When
342 rng = sht[0]
344 # Then
345 self.assertEqual(0, rng.RangeAddress.Sheet)
346 self.assertEqual(0, rng.RangeAddress.StartRow)
347 self.assertEqual(0, rng.RangeAddress.StartColumn)
348 self.assertEqual(0, rng.RangeAddress.EndRow)
349 self.assertEqual(16383, rng.RangeAddress.EndColumn)
351 spr.close(True)
353 # Tests syntax:
354 # rng = cellrange[0,:] # Access cell range by row index
355 # For:
356 # Spreadsheet
357 def test_XCellRange_Spreadsheet_Range_RowIndex_FullSlice(self):
358 # Given
359 spr = self.createBlankSpreadsheet()
360 sht = spr.Sheets[0]
362 # When
363 rng = sht[0, :]
365 # Then
366 self.assertEqual(0, rng.RangeAddress.Sheet)
367 self.assertEqual(0, rng.RangeAddress.StartRow)
368 self.assertEqual(0, rng.RangeAddress.StartColumn)
369 self.assertEqual(0, rng.RangeAddress.EndRow)
370 self.assertEqual(16383, rng.RangeAddress.EndColumn)
372 spr.close(True)
374 # Tests syntax:
375 # rng = cellrange[:,0] # Access cell range by column index
376 # For:
377 # Spreadsheet
378 def test_XCellRange_Spreadsheet_Range_FullSlice_ColumnIndex(self):
379 # Given
380 spr = self.createBlankSpreadsheet()
381 sht = spr.Sheets[0]
383 # When
384 rng = sht[:, 0]
386 # Then
387 self.assertEqual(0, rng.RangeAddress.Sheet)
388 self.assertEqual(0, rng.RangeAddress.StartRow)
389 self.assertEqual(0, rng.RangeAddress.StartColumn)
390 self.assertEqual(1048575, rng.RangeAddress.EndRow)
391 self.assertEqual(0, rng.RangeAddress.EndColumn)
393 spr.close(True)
396 if __name__ == '__main__':
397 unittest.main()
399 # vim:set shiftwidth=4 softtabstop=4 expandtab: