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/.
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
20 class TestXEnumeration(CollectionsTestBase
):
23 # for val in itr: ... # Iteration of named iterator
26 def test_XEnumeration_ForIn(self
):
28 doc
= self
.createBlankTextDocument()
32 itr
= iter(doc
.Text
.createEnumeration())
34 paragraphs
.append(para
)
37 self
.assertEqual(1, len(paragraphs
))
42 # if val in itr: ... # Test value presence
45 def test_XEnumeration_IfIn_Present(self
):
47 doc
= self
.createBlankTextDocument()
50 paragraph
= doc
.Text
.createEnumeration().nextElement()
51 itr
= iter(doc
.Text
.createEnumeration())
52 result
= paragraph
in itr
55 self
.assertTrue(result
)
60 # if val in itr: ... # Test value presence
63 def test_XEnumeration_IfIn_Absent(self
):
65 doc1
= self
.createBlankTextDocument()
66 doc2
= self
.createBlankTextDocument()
69 paragraph
= doc2
.Text
.createEnumeration().nextElement()
70 itr
= iter(doc1
.Text
.createEnumeration())
71 result
= paragraph
in itr
74 self
.assertFalse(result
)
80 # if val in itr: ... # Test value presence
83 def test_XEnumeration_IfIn_None(self
):
85 doc
= self
.createBlankTextDocument()
88 itr
= iter(doc
.Text
.createEnumeration())
92 self
.assertFalse(result
)
97 # if val in itr: ... # Test value presence
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
103 def test_XEnumeration_IfIn_String(self
):
105 doc
= self
.createBlankTextDocument()
108 itr
= iter(doc
.Text
.createEnumeration())
109 result
= 'foo' in itr
112 self
.assertFalse(result
)
117 if __name__
== '__main__':
120 # vim:set shiftwidth=4 softtabstop=4 expandtab: