1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
|
#!/usr/bin/env python
#
# This file is part of the LibreOffice project.
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#
import unittest
import uno
from testcollections_base import CollectionsTestBase
from com.sun.star.beans import PropertyValue
# Tests behaviour of objects implementing XNameContainer using the new-style
# collection accessors
# The objects chosen have no special meaning, they just happen to implement the
# tested interfaces
class TestXNameContainer(CollectionsTestBase):
# Tests syntax:
# obj[key] = val # Insert by key
# For:
# 0->1 element
def test_XNameContainer_InsertName(self):
# Given
spr = self.createBlankSpreadsheet()
ranges = spr.createInstance("com.sun.star.sheet.SheetCellRanges")
newRange = spr.Sheets.getByIndex(0).getCellRangeByPosition( 1, 2, 1, 2 )
# When
ranges['foo'] = newRange
# Then
self.assertEqual(1, len(ranges.ElementNames))
# Tests syntax:
# obj[key] = val # Insert by key
# For:
# Invalid key
def test_XNameContainer_InsertName_Invalid(self):
# Given
spr = self.createBlankSpreadsheet()
ranges = spr.createInstance("com.sun.star.sheet.SheetCellRanges")
newRange = spr.Sheets.getByIndex(0).getCellRangeByPosition( 1, 2, 1, 2 )
# When / Then
with self.assertRaises(TypeError):
ranges[12.34] = newRange
# Tests syntax:
# obj[key] = val # Replace by key
def test_XNameContainer_ReplaceName(self):
# Given
spr = self.createBlankSpreadsheet()
ranges = spr.createInstance("com.sun.star.sheet.SheetCellRanges")
newRange1 = spr.Sheets.getByIndex(0).getCellRangeByPosition( 1, 2, 1, 2 )
newRange2 = spr.Sheets.getByIndex(0).getCellRangeByPosition( 6, 6, 6, 6 )
# When
ranges['foo'] = newRange1
ranges['foo'] = newRange2
# Then
self.assertEqual(1, len(ranges.ElementNames))
readRange = ranges['foo']
self.assertEqual(6, readRange.CellAddress.Column)
# Tests syntax:
# del obj[key] # Delete by key
# For:
# 1/2 elements
def test_XNameContainer_DelKey(self):
# Given
spr = self.createBlankSpreadsheet()
spr.Sheets.insertNewByName('foo', 1)
# When
del spr.Sheets['foo']
# Then
self.assertEqual(1, len(spr.Sheets))
self.assertFalse('foo' in spr.Sheets)
# Tests syntax:
# del obj[key] # Delete by key
# For:
# Missing key
def test_XNameContainer_DelKey_Missing(self):
# Given
spr = self.createBlankSpreadsheet()
# When / Then
with self.assertRaises(KeyError):
del spr.Sheets['foo']
# Tests syntax:
# del obj[key] # Delete by key
# For:
# Invalid key (float)
def test_XNameContainer_DelKey_Invalid(self):
# Given
spr = self.createBlankSpreadsheet()
# When / Then
with self.assertRaises(TypeError):
del spr.Sheets[12.34]
if __name__ == '__main__':
unittest.main()
# vim:set shiftwidth=4 softtabstop=4 expandtab:
|