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/.
13 from testcollections_base
import CollectionsTestBase
14 from com
.sun
.star
.beans
import PropertyValue
16 # SheetCellRanges instance factory
17 def getSheetCellRangesInstance(spr
):
18 return spr
.createInstance("com.sun.star.sheet.SheetCellRanges")
21 # Tests behaviour of objects implementing XNameContainer using the new-style
22 # collection accessors
23 # The objects chosen have no special meaning, they just happen to implement the
26 class TestXNameContainer(CollectionsTestBase
):
29 # obj[key] = val # Insert by key
32 def test_XNameContainer_InsertName(self
):
34 spr
= self
.createBlankSpreadsheet()
35 ranges
= getSheetCellRangesInstance(spr
)
36 new_range
= spr
.Sheets
[0].getCellRangeByPosition(1, 2, 1, 2)
39 ranges
['foo'] = new_range
42 self
.assertEqual(1, len(ranges
.ElementNames
))
47 # obj[key] = val # Insert by key
50 def test_XNameContainer_InsertName_Invalid(self
):
52 spr
= self
.createBlankSpreadsheet()
53 ranges
= getSheetCellRangesInstance(spr
)
54 new_range
= spr
.Sheets
[0].getCellRangeByPosition(1, 2, 1, 2)
57 with self
.assertRaises(TypeError):
58 ranges
[12.34] = new_range
63 # obj[key] = val # Replace by key
64 def test_XNameContainer_ReplaceName(self
):
66 spr
= self
.createBlankSpreadsheet()
67 ranges
= getSheetCellRangesInstance(spr
)
68 new_range1
= spr
.Sheets
[0].getCellRangeByPosition(1, 2, 1, 2)
69 new_range2
= spr
.Sheets
[0].getCellRangeByPosition(6, 6, 6, 6)
72 ranges
['foo'] = new_range1
73 ranges
['foo'] = new_range2
76 self
.assertEqual(1, len(ranges
.ElementNames
))
77 read_range
= ranges
['foo']
78 self
.assertEqual(6, read_range
.CellAddress
.Column
)
83 # del obj[key] # Delete by key
86 def test_XNameContainer_DelKey(self
):
88 spr
= self
.createBlankSpreadsheet()
89 spr
.Sheets
.insertNewByName('foo', 1)
95 self
.assertEqual(1, len(spr
.Sheets
))
96 self
.assertFalse('foo' in spr
.Sheets
)
101 # del obj[key] # Delete by key
104 def test_XNameContainer_DelKey_Missing(self
):
106 spr
= self
.createBlankSpreadsheet()
109 with self
.assertRaises(KeyError):
110 del spr
.Sheets
['foo']
115 # del obj[key] # Delete by key
117 # Invalid key (float)
118 def test_XNameContainer_DelKey_Invalid(self
):
120 spr
= self
.createBlankSpreadsheet()
123 with self
.assertRaises(TypeError):
124 del spr
.Sheets
[12.34]
129 if __name__
== '__main__':
132 # vim:set shiftwidth=4 softtabstop=4 expandtab: