tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / pyuno / qa / pytests / testcollections_XNameReplace.py
blobe93ca590e51d913615a96ec7d2ae24b9960c9539
1 #!/usr/bin/env python
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/.
10 import unittest
12 from testcollections_base import CollectionsTestBase
13 from com.sun.star.beans import PropertyValue
16 def getScriptName():
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
22 # tested interfaces
24 class TestXNameReplace(CollectionsTestBase):
26 # Tests syntax:
27 # obj[key] = val # Replace by key
28 # For:
29 # 1 element
30 def test_XNameReplace_ReplaceName(self):
31 # Given
32 doc = self.createBlankTextDocument()
33 event_properties = (PropertyValue(Name='Script', Value=getScriptName()),)
35 # When
36 doc.Events['OnSave'] = event_properties
38 # Then
39 on_save = [p.Value for p in doc.Events['OnSave'] if p.Name == 'Script'][0]
40 self.assertEqual(getScriptName(), on_save)
42 doc.close(True)
44 # Tests syntax:
45 # obj[key] = val # Replace by key
46 # For:
47 # Invalid key
48 def test_XNameReplace_ReplaceName_Invalid_Key(self):
49 # Given
50 doc = self.createBlankTextDocument()
51 event_properties = (PropertyValue(Name='Script', Value=getScriptName()),)
53 # When / Then
54 with self.assertRaises(KeyError):
55 doc.Events['qqqqq'] = event_properties
57 doc.close(True)
59 # Tests syntax:
60 # obj[key] = val # Replace by key
61 # For:
62 # Invalid key type
63 def test_XNameReplace_ReplaceName_Invalid_Key_Type(self):
64 # Given
65 doc = self.createBlankTextDocument()
66 event_properties = (PropertyValue(Name='Script', Value=getScriptName()),)
68 # When / Then
69 with self.assertRaises(TypeError):
70 doc.Events[12.34] = event_properties
72 doc.close(True)
75 if __name__ == '__main__':
76 unittest.main()
78 # vim:set shiftwidth=4 softtabstop=4 expandtab: