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/.
12 from testcollections_base
import CollectionsTestBase
15 # SheetCellRanges instance factory
16 def getSheetCellRangesInstance(spr
):
17 return spr
.createInstance("com.sun.star.sheet.SheetCellRanges")
20 # Tests behaviour of objects implementing XNameContainer using the new-style
21 # collection accessors
22 # The objects chosen have no special meaning, they just happen to implement the
25 class TestXNameContainer(CollectionsTestBase
):
28 # obj[key] = val # Insert by key
31 def test_XNameContainer_InsertName(self
):
33 spr
= self
.createBlankSpreadsheet()
34 ranges
= getSheetCellRangesInstance(spr
)
35 new_range
= spr
.Sheets
[0][2:3,1:2]
38 ranges
['foo'] = new_range
41 self
.assertEqual(1, len(ranges
.ElementNames
))
46 # obj[key] = val # Insert by key
49 def test_XNameContainer_InsertName_Invalid(self
):
51 spr
= self
.createBlankSpreadsheet()
52 ranges
= getSheetCellRangesInstance(spr
)
53 new_range
= spr
.Sheets
[0][2:3,1:2]
56 with self
.assertRaises(TypeError):
57 ranges
[12.34] = new_range
62 # obj[key] = val # Replace by key
63 def test_XNameContainer_ReplaceName(self
):
65 spr
= self
.createBlankSpreadsheet()
66 ranges
= getSheetCellRangesInstance(spr
)
67 new_range1
= spr
.Sheets
[0][2:3,1:2]
68 new_range2
= spr
.Sheets
[0][6:7,6:7]
71 ranges
['foo'] = new_range1
72 ranges
['foo'] = new_range2
75 self
.assertEqual(1, len(ranges
.ElementNames
))
76 read_range
= ranges
['foo']
77 self
.assertEqual(6, read_range
.CellAddress
.Column
)
82 # del obj[key] # Delete by key
85 def test_XNameContainer_DelKey(self
):
87 spr
= self
.createBlankSpreadsheet()
88 spr
.Sheets
.insertNewByName('foo', 1)
94 self
.assertEqual(1, len(spr
.Sheets
))
95 self
.assertFalse('foo' in spr
.Sheets
)
100 # del obj[key] # Delete by key
103 def test_XNameContainer_DelKey_Missing(self
):
105 spr
= self
.createBlankSpreadsheet()
108 with self
.assertRaises(KeyError):
109 del spr
.Sheets
['foo']
114 # del obj[key] # Delete by key
116 # Invalid key (float)
117 def test_XNameContainer_DelKey_Invalid(self
):
119 spr
= self
.createBlankSpreadsheet()
122 with self
.assertRaises(TypeError):
123 del spr
.Sheets
[12.34]
128 if __name__
== '__main__':
131 # vim:set shiftwidth=4 softtabstop=4 expandtab: