Use o3tl::convert in Math
[LibreOffice.git] / pyuno / qa / pytests / testcollections_XNameContainer.py
blobc544ca9dd181528393e2a2ce3c6b177de728b3c5
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
11 import uno
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
24 # tested interfaces
26 class TestXNameContainer(CollectionsTestBase):
28 # Tests syntax:
29 # obj[key] = val # Insert by key
30 # For:
31 # 0->1 element
32 def test_XNameContainer_InsertName(self):
33 # Given
34 spr = self.createBlankSpreadsheet()
35 ranges = getSheetCellRangesInstance(spr)
36 new_range = spr.Sheets[0].getCellRangeByPosition(1, 2, 1, 2)
38 # When
39 ranges['foo'] = new_range
41 # Then
42 self.assertEqual(1, len(ranges.ElementNames))
44 spr.close(True)
46 # Tests syntax:
47 # obj[key] = val # Insert by key
48 # For:
49 # Invalid key
50 def test_XNameContainer_InsertName_Invalid(self):
51 # Given
52 spr = self.createBlankSpreadsheet()
53 ranges = getSheetCellRangesInstance(spr)
54 new_range = spr.Sheets[0].getCellRangeByPosition(1, 2, 1, 2)
56 # When / Then
57 with self.assertRaises(TypeError):
58 ranges[12.34] = new_range
60 spr.close(True)
62 # Tests syntax:
63 # obj[key] = val # Replace by key
64 def test_XNameContainer_ReplaceName(self):
65 # Given
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)
71 # When
72 ranges['foo'] = new_range1
73 ranges['foo'] = new_range2
75 # Then
76 self.assertEqual(1, len(ranges.ElementNames))
77 read_range = ranges['foo']
78 self.assertEqual(6, read_range.CellAddress.Column)
80 spr.close(True)
82 # Tests syntax:
83 # del obj[key] # Delete by key
84 # For:
85 # 1/2 elements
86 def test_XNameContainer_DelKey(self):
87 # Given
88 spr = self.createBlankSpreadsheet()
89 spr.Sheets.insertNewByName('foo', 1)
91 # When
92 del spr.Sheets['foo']
94 # Then
95 self.assertEqual(1, len(spr.Sheets))
96 self.assertFalse('foo' in spr.Sheets)
98 spr.close(True)
100 # Tests syntax:
101 # del obj[key] # Delete by key
102 # For:
103 # Missing key
104 def test_XNameContainer_DelKey_Missing(self):
105 # Given
106 spr = self.createBlankSpreadsheet()
108 # When / Then
109 with self.assertRaises(KeyError):
110 del spr.Sheets['foo']
112 spr.close(True)
114 # Tests syntax:
115 # del obj[key] # Delete by key
116 # For:
117 # Invalid key (float)
118 def test_XNameContainer_DelKey_Invalid(self):
119 # Given
120 spr = self.createBlankSpreadsheet()
122 # When / Then
123 with self.assertRaises(TypeError):
124 del spr.Sheets[12.34]
126 spr.close(True)
129 if __name__ == '__main__':
130 unittest.main()
132 # vim:set shiftwidth=4 softtabstop=4 expandtab: