tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / pyuno / qa / pytests / testcollections_XEnumerationAccess.py
blobeecb81c0502190f61646fee4cfa4a0bc503996d4
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 # Tests behaviour of objects implementing XEnumerationAccess using the new-style
16 # collection accessors
17 # The objects chosen have no special meaning, they just happen to implement the
18 # tested interfaces
20 class TestXEnumerationAccess(CollectionsTestBase):
22 # Tests syntax:
23 # for val in obj: ... # Implicit iterator
24 # For:
25 # 1 element
26 def test_XEnumerationAccess_ForIn(self):
27 # Given
28 doc = self.createBlankTextDocument()
30 # When
31 paragraphs = []
32 for para in doc.Text:
33 paragraphs.append(para)
35 # Then
36 self.assertEqual(1, len(paragraphs))
38 doc.close(True)
40 # Tests syntax:
41 # itr = iter(obj) # Named iterator
42 # For:
43 # 1 element
44 def test_XEnumerationAccess_Iter(self):
45 # Given
46 doc = self.createBlankTextDocument()
48 # When
49 itr = iter(doc.Text)
51 # Then
52 self.assertIsNotNone(next(itr))
53 with self.assertRaises(StopIteration):
54 next(itr)
56 doc.close(True)
58 # Tests syntax:
59 # if val in obj: ... # Test value presence
60 # For:
61 # Present value
62 def test_XEnumerationAccess_IfIn_Present(self):
63 # Given
64 doc = self.createBlankTextDocument()
66 # When
67 paragraph = doc.Text.createEnumeration().nextElement()
68 result = paragraph in doc.Text
70 # Then
71 self.assertTrue(result)
73 doc.close(True)
75 # Tests syntax:
76 # if val in obj: ... # Test value presence
77 # For:
78 # Absent value
79 def test_XEnumerationAccess_IfIn_Absent(self):
80 # Given
81 doc1 = self.createBlankTextDocument()
82 doc2 = self.createBlankTextDocument()
84 # When
85 paragraph = doc2.Text.createEnumeration().nextElement()
86 result = paragraph in doc1.Text
88 # Then
89 self.assertFalse(result)
91 doc1.close(True)
92 doc2.close(True)
94 # Tests syntax:
95 # if val in obj: ... # Test value presence
96 # For:
97 # None
98 def test_XEnumerationAccess_IfIn_None(self):
99 # Given
100 doc = self.createBlankTextDocument()
102 # When
103 result = None in doc.Text
105 # Then
106 self.assertFalse(result)
108 doc.close(True)
110 # Tests syntax:
111 # if val in obj: ... # Test value presence
112 # For:
113 # Invalid value (string)
114 def test_XEnumerationAccess_IfIn_String(self):
115 # Given
116 doc = self.createBlankTextDocument()
118 # When
119 result = 'foo' in doc.Text
121 # Then
122 self.assertFalse(result)
124 doc.close(True)
126 # Tests syntax:
127 # if val in obj: ... # Test value presence
128 # For:
129 # Invalid value (dict)
130 def test_XEnumerationAccess_IfIn_String_TypeError(self):
131 # Given
132 doc = self.createBlankTextDocument()
134 # When / Then
135 with self.assertRaises(TypeError):
136 _ = {} in doc.Text
138 doc.close(True)
141 if __name__ == '__main__':
142 unittest.main()
144 # vim:set shiftwidth=4 softtabstop=4 expandtab: