tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / pyuno / qa / pytests / testcollections_XEnumeration.py
bloba12d303596583ed14109569c879f15bcefe235c1
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 XEnumeration 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 TestXEnumeration(CollectionsTestBase):
22 # Tests syntax:
23 # for val in itr: ... # Iteration of named iterator
24 # For:
25 # 1 element
26 def test_XEnumeration_ForIn(self):
27 # Given
28 doc = self.createBlankTextDocument()
30 # When
31 paragraphs = []
32 itr = iter(doc.Text.createEnumeration())
33 for para in itr:
34 paragraphs.append(para)
36 # Then
37 self.assertEqual(1, len(paragraphs))
39 doc.close(True)
41 # Tests syntax:
42 # if val in itr: ... # Test value presence
43 # For:
44 # Present value
45 def test_XEnumeration_IfIn_Present(self):
46 # Given
47 doc = self.createBlankTextDocument()
49 # When
50 paragraph = doc.Text.createEnumeration().nextElement()
51 itr = iter(doc.Text.createEnumeration())
52 result = paragraph in itr
54 # Then
55 self.assertTrue(result)
57 doc.close(True)
59 # Tests syntax:
60 # if val in itr: ... # Test value presence
61 # For:
62 # Absent value
63 def test_XEnumeration_IfIn_Absent(self):
64 # Given
65 doc1 = self.createBlankTextDocument()
66 doc2 = self.createBlankTextDocument()
68 # When
69 paragraph = doc2.Text.createEnumeration().nextElement()
70 itr = iter(doc1.Text.createEnumeration())
71 result = paragraph in itr
73 # Then
74 self.assertFalse(result)
76 doc1.close(True)
77 doc2.close(True)
79 # Tests syntax:
80 # if val in itr: ... # Test value presence
81 # For:
82 # None
83 def test_XEnumeration_IfIn_None(self):
84 # Given
85 doc = self.createBlankTextDocument()
87 # When
88 itr = iter(doc.Text.createEnumeration())
89 result = None in itr
91 # Then
92 self.assertFalse(result)
94 doc.close(True)
96 # Tests syntax:
97 # if val in itr: ... # Test value presence
98 # For:
99 # Invalid value (string)
100 # Note: Ideally this would raise TypeError in the same manner as for
101 # XEnumerationAccess, but an XEnumeration doesn't know the type of its
102 # values
103 def test_XEnumeration_IfIn_String(self):
104 # Given
105 doc = self.createBlankTextDocument()
107 # When
108 itr = iter(doc.Text.createEnumeration())
109 result = 'foo' in itr
111 # Then
112 self.assertFalse(result)
114 doc.close(True)
117 if __name__ == '__main__':
118 unittest.main()
120 # vim:set shiftwidth=4 softtabstop=4 expandtab: