tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / pyuno / qa / pytests / testcollections_XNameContainer.py
bloba02cf4d648990a21abdbf0a230383e501e916fa7
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
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
23 # tested interfaces
25 class TestXNameContainer(CollectionsTestBase):
27 # Tests syntax:
28 # obj[key] = val # Insert by key
29 # For:
30 # 0->1 element
31 def test_XNameContainer_InsertName(self):
32 # Given
33 spr = self.createBlankSpreadsheet()
34 ranges = getSheetCellRangesInstance(spr)
35 new_range = spr.Sheets[0][2:3,1:2]
37 # When
38 ranges['foo'] = new_range
40 # Then
41 self.assertEqual(1, len(ranges.ElementNames))
43 spr.close(True)
45 # Tests syntax:
46 # obj[key] = val # Insert by key
47 # For:
48 # Invalid key
49 def test_XNameContainer_InsertName_Invalid(self):
50 # Given
51 spr = self.createBlankSpreadsheet()
52 ranges = getSheetCellRangesInstance(spr)
53 new_range = spr.Sheets[0][2:3,1:2]
55 # When / Then
56 with self.assertRaises(TypeError):
57 ranges[12.34] = new_range
59 spr.close(True)
61 # Tests syntax:
62 # obj[key] = val # Replace by key
63 def test_XNameContainer_ReplaceName(self):
64 # Given
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]
70 # When
71 ranges['foo'] = new_range1
72 ranges['foo'] = new_range2
74 # Then
75 self.assertEqual(1, len(ranges.ElementNames))
76 read_range = ranges['foo']
77 self.assertEqual(6, read_range.CellAddress.Column)
79 spr.close(True)
81 # Tests syntax:
82 # del obj[key] # Delete by key
83 # For:
84 # 1/2 elements
85 def test_XNameContainer_DelKey(self):
86 # Given
87 spr = self.createBlankSpreadsheet()
88 spr.Sheets.insertNewByName('foo', 1)
90 # When
91 del spr.Sheets['foo']
93 # Then
94 self.assertEqual(1, len(spr.Sheets))
95 self.assertFalse('foo' in spr.Sheets)
97 spr.close(True)
99 # Tests syntax:
100 # del obj[key] # Delete by key
101 # For:
102 # Missing key
103 def test_XNameContainer_DelKey_Missing(self):
104 # Given
105 spr = self.createBlankSpreadsheet()
107 # When / Then
108 with self.assertRaises(KeyError):
109 del spr.Sheets['foo']
111 spr.close(True)
113 # Tests syntax:
114 # del obj[key] # Delete by key
115 # For:
116 # Invalid key (float)
117 def test_XNameContainer_DelKey_Invalid(self):
118 # Given
119 spr = self.createBlankSpreadsheet()
121 # When / Then
122 with self.assertRaises(TypeError):
123 del spr.Sheets[12.34]
125 spr.close(True)
128 if __name__ == '__main__':
129 unittest.main()
131 # vim:set shiftwidth=4 softtabstop=4 expandtab: