bump product version to 5.0.4.1
[LibreOffice.git] / pyuno / qa / pytests / insertremovecells.py
blob0c9626caa7d2328fcf2f6a1d3ed5917b63944273
1 import unittest
3 from os import getenv, path
5 try:
6 from urllib.parse import quote
7 except ImportError:
8 from urllib import quote
10 from org.libreoffice.unotest import pyuno, mkPropertyValue
12 class InsertRemoveCells(unittest.TestCase):
14 @classmethod
15 def setUpClass(cls):
16 cls.xContext = pyuno.getComponentContext()
17 pyuno.private_initTestEnvironment()
20 # no need for a tearDown(cls) method.
23 def test_fdo74824_load(self):
24 ctxt = self.xContext
25 assert(ctxt)
27 smgr = ctxt.ServiceManager
28 desktop = smgr.createInstanceWithContext('com.sun.star.frame.Desktop', ctxt)
29 loadProps = tuple(mkPropertyValue(k, v) for (k, v) in (
30 ('Hidden', True),
31 ('ReadOnly', False)
33 tdoc_dir = getenv('TDOC')
34 url = 'file://' + quote(path.join(tdoc_dir, 'fdo74824.ods'))
35 doc = desktop.loadComponentFromURL(url, "_blank", 0, loadProps)
37 sheet = doc.Sheets.Sheet1
38 area = sheet.getCellRangeByName( 'A2:B4' )
39 addr = area.getRangeAddress()
41 # 2 = intended to shift cells right, but I don't know where to find
42 # the ENUM to put in it's place. Corrections welcome.
43 sheet.insertCells( addr, 2 )
45 # basically, the insertCells call is the test: it should not crash
46 # LibreOffice. However, for completeness, we should test the cell
47 # contents as well.
49 empty_cells = (
50 (0, 0), (0, 1), (0, 2), (0, 3), (1, 0), (1, 1), (1, 2), (1, 3),
51 (3, 1), (4, 0), (4, 2), (5, 0), (5, 2), (5, 3),
53 formula_cells = (
54 (2, 0, '=(1+GDR)^-D1', '1.000', 1.0),
55 (4, 1, '=(1+GDR)^-F2', '0.125', 0.125),
56 (4, 3, '=SUM(C1:C2)', '1.000', 1.0),
58 value_cells = (
59 (2, 2, '2010', 2010.0),
60 (2, 3, '7', 7.0),
61 (3, 0, '0', 0),
62 (3, 2, '2012', 2012.0),
63 (3, 3, '6', 6.0),
64 (5, 1, '1', 1.0),
66 for pos in empty_cells:
67 cell = sheet.getCellByPosition(*pos)
68 self.assertEqual( 'EMPTY', cell.Type.value )
69 for x, y, f, s, val in formula_cells:
70 cell = sheet.getCellByPosition(x, y)
71 self.assertEqual( 'FORMULA', cell.Type.value )
72 self.assertEqual( f, cell.getFormula() )
73 self.assertEqual( s, cell.String )
74 self.assertEqual( val, cell.Value )
75 for x, y, s, val in value_cells:
76 cell = sheet.getCellByPosition(x, y)
77 self.assertEqual( s, cell.String )
78 self.assertEqual( val, cell.Value )
80 doc.close( True )
83 if __name__ == '__main__':
84 unittest.main()