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 XEnumerationAccess using the new-style
16 # collection accessors
17 # The objects chosen have no special meaning, they just happen to implement the
20 class TestXEnumerationAccess(CollectionsTestBase
):
23 # for val in obj: ... # Implicit iterator
26 def test_XEnumerationAccess_ForIn(self
):
28 doc
= self
.createBlankTextDocument()
33 paragraphs
.append(para
)
36 self
.assertEqual(1, len(paragraphs
))
41 # itr = iter(obj) # Named iterator
44 def test_XEnumerationAccess_Iter(self
):
46 doc
= self
.createBlankTextDocument()
52 self
.assertIsNotNone(next(itr
))
53 with self
.assertRaises(StopIteration):
59 # if val in obj: ... # Test value presence
62 def test_XEnumerationAccess_IfIn_Present(self
):
64 doc
= self
.createBlankTextDocument()
67 paragraph
= doc
.Text
.createEnumeration().nextElement()
68 result
= paragraph
in doc
.Text
71 self
.assertTrue(result
)
76 # if val in obj: ... # Test value presence
79 def test_XEnumerationAccess_IfIn_Absent(self
):
81 doc1
= self
.createBlankTextDocument()
82 doc2
= self
.createBlankTextDocument()
85 paragraph
= doc2
.Text
.createEnumeration().nextElement()
86 result
= paragraph
in doc1
.Text
89 self
.assertFalse(result
)
95 # if val in obj: ... # Test value presence
98 def test_XEnumerationAccess_IfIn_None(self
):
100 doc
= self
.createBlankTextDocument()
103 result
= None in doc
.Text
106 self
.assertFalse(result
)
111 # if val in obj: ... # Test value presence
113 # Invalid value (string)
114 def test_XEnumerationAccess_IfIn_String(self
):
116 doc
= self
.createBlankTextDocument()
119 result
= 'foo' in doc
.Text
122 self
.assertFalse(result
)
127 # if val in obj: ... # Test value presence
129 # Invalid value (dict)
130 def test_XEnumerationAccess_IfIn_String_TypeError(self
):
132 doc
= self
.createBlankTextDocument()
135 with self
.assertRaises(TypeError):
141 if __name__
== '__main__':
144 # vim:set shiftwidth=4 softtabstop=4 expandtab: