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/.
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
22 class TestXEnumeration(CollectionsTestBase
):
25 # for val in itr: ... # Iteration of named iterator
28 def test_XEnumeration_ForIn(self
):
30 doc
= self
.createBlankTextDocument()
34 itr
= iter(doc
.Text
.createEnumeration())
36 paragraphs
.append(para
)
39 self
.assertEqual(1, len(paragraphs
))
44 # if val in itr: ... # Test value presence
47 def test_XEnumeration_IfIn_Present(self
):
49 doc
= self
.createBlankTextDocument()
52 paragraph
= doc
.Text
.createEnumeration().nextElement()
53 itr
= iter(doc
.Text
.createEnumeration())
54 result
= paragraph
in itr
57 self
.assertTrue(result
)
62 # if val in itr: ... # Test value presence
65 def test_XEnumeration_IfIn_Absent(self
):
67 doc1
= self
.createBlankTextDocument()
68 doc2
= self
.createBlankTextDocument()
71 paragraph
= doc2
.Text
.createEnumeration().nextElement()
72 itr
= iter(doc1
.Text
.createEnumeration())
73 result
= paragraph
in itr
76 self
.assertFalse(result
)
82 # if val in itr: ... # Test value presence
85 def test_XEnumeration_IfIn_None(self
):
87 doc
= self
.createBlankTextDocument()
90 itr
= iter(doc
.Text
.createEnumeration())
94 self
.assertFalse(result
)
99 # if val in itr: ... # Test value presence
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
105 def test_XEnumeration_IfIn_String(self
):
107 doc
= self
.createBlankTextDocument()
110 itr
= iter(doc
.Text
.createEnumeration())
111 result
= 'foo' in itr
114 self
.assertFalse(result
)
119 if __name__
== '__main__':
122 # vim:set shiftwidth=4 softtabstop=4 expandtab: