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
13 from com
.sun
.star
.beans
import PropertyValue
17 return 'macro://Standard.Module1.MySave()'
19 # Tests behaviour of objects implementing XNameReplace using the new-style
20 # collection accessors
21 # The objects chosen have no special meaning, they just happen to implement the
24 class TestXNameReplace(CollectionsTestBase
):
27 # obj[key] = val # Replace by key
30 def test_XNameReplace_ReplaceName(self
):
32 doc
= self
.createBlankTextDocument()
33 event_properties
= (PropertyValue(Name
='Script', Value
=getScriptName()),)
36 doc
.Events
['OnSave'] = event_properties
39 on_save
= [p
.Value
for p
in doc
.Events
['OnSave'] if p
.Name
== 'Script'][0]
40 self
.assertEqual(getScriptName(), on_save
)
45 # obj[key] = val # Replace by key
48 def test_XNameReplace_ReplaceName_Invalid_Key(self
):
50 doc
= self
.createBlankTextDocument()
51 event_properties
= (PropertyValue(Name
='Script', Value
=getScriptName()),)
54 with self
.assertRaises(KeyError):
55 doc
.Events
['qqqqq'] = event_properties
60 # obj[key] = val # Replace by key
63 def test_XNameReplace_ReplaceName_Invalid_Key_Type(self
):
65 doc
= self
.createBlankTextDocument()
66 event_properties
= (PropertyValue(Name
='Script', Value
=getScriptName()),)
69 with self
.assertRaises(TypeError):
70 doc
.Events
[12.34] = event_properties
75 if __name__
== '__main__':
78 # vim:set shiftwidth=4 softtabstop=4 expandtab: