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
18 return 'macro://Standard.Module1.MySave()'
20 # Tests behaviour of objects implementing XNameReplace using the new-style
21 # collection accessors
22 # The objects chosen have no special meaning, they just happen to implement the
25 class TestXNameReplace(CollectionsTestBase
):
28 # obj[key] = val # Replace by key
31 def test_XNameReplace_ReplaceName(self
):
33 doc
= self
.createBlankTextDocument()
34 event_properties
= (PropertyValue(Name
='Script', Value
=getScriptName()),)
37 doc
.Events
['OnSave'] = event_properties
40 on_save
= [p
.Value
for p
in doc
.Events
['OnSave'] if p
.Name
== 'Script'][0]
41 self
.assertEqual(getScriptName(), on_save
)
46 # obj[key] = val # Replace by key
49 def test_XNameReplace_ReplaceName_Invalid(self
):
51 doc
= self
.createBlankTextDocument()
52 event_properties
= (PropertyValue(Name
='Script', Value
=getScriptName()),)
55 with self
.assertRaises(KeyError):
56 doc
.Events
['qqqqq'] = event_properties
61 # obj[key] = val # Replace by key
64 def test_XNameReplace_ReplaceName_Invalid(self
):
66 doc
= self
.createBlankTextDocument()
67 event_properties
= (PropertyValue(Name
='Script', Value
=getScriptName()),)
70 with self
.assertRaises(TypeError):
71 doc
.Events
[12.34] = event_properties
76 if __name__
== '__main__':
79 # vim:set shiftwidth=4 softtabstop=4 expandtab: