Use o3tl::convert in Math
[LibreOffice.git] / pyuno / qa / pytests / testcollections_XEnumeration.py
blob8d1f8eece0463c3e929d943e280d183aeda0e165
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
17 # Tests behaviour of objects implementing XEnumeration using the new-style
18 # collection accessors
19 # The objects chosen have no special meaning, they just happen to implement the
20 # tested interfaces
22 class TestXEnumeration(CollectionsTestBase):
24 # Tests syntax:
25 # for val in itr: ... # Iteration of named iterator
26 # For:
27 # 1 element
28 def test_XEnumeration_ForIn(self):
29 # Given
30 doc = self.createBlankTextDocument()
32 # When
33 paragraphs = []
34 itr = iter(doc.Text.createEnumeration())
35 for para in itr:
36 paragraphs.append(para)
38 # Then
39 self.assertEqual(1, len(paragraphs))
41 doc.close(True)
43 # Tests syntax:
44 # if val in itr: ... # Test value presence
45 # For:
46 # Present value
47 def test_XEnumeration_IfIn_Present(self):
48 # Given
49 doc = self.createBlankTextDocument()
51 # When
52 paragraph = doc.Text.createEnumeration().nextElement()
53 itr = iter(doc.Text.createEnumeration())
54 result = paragraph in itr
56 # Then
57 self.assertTrue(result)
59 doc.close(True)
61 # Tests syntax:
62 # if val in itr: ... # Test value presence
63 # For:
64 # Absent value
65 def test_XEnumeration_IfIn_Absent(self):
66 # Given
67 doc1 = self.createBlankTextDocument()
68 doc2 = self.createBlankTextDocument()
70 # When
71 paragraph = doc2.Text.createEnumeration().nextElement()
72 itr = iter(doc1.Text.createEnumeration())
73 result = paragraph in itr
75 # Then
76 self.assertFalse(result)
78 doc1.close(True)
79 doc2.close(True)
81 # Tests syntax:
82 # if val in itr: ... # Test value presence
83 # For:
84 # None
85 def test_XEnumeration_IfIn_None(self):
86 # Given
87 doc = self.createBlankTextDocument()
89 # When
90 itr = iter(doc.Text.createEnumeration())
91 result = None in itr
93 # Then
94 self.assertFalse(result)
96 doc.close(True)
98 # Tests syntax:
99 # if val in itr: ... # Test value presence
100 # For:
101 # Invalid value (string)
102 # Note: Ideally this would raise TypeError in the same manner as for
103 # XEnumerationAccess, but an XEnumeration doesn't know the type of its
104 # values
105 def test_XEnumeration_IfIn_String(self):
106 # Given
107 doc = self.createBlankTextDocument()
109 # When
110 itr = iter(doc.Text.createEnumeration())
111 result = 'foo' in itr
113 # Then
114 self.assertFalse(result)
116 doc.close(True)
119 if __name__ == '__main__':
120 unittest.main()
122 # vim:set shiftwidth=4 softtabstop=4 expandtab: