Use o3tl::convert in Math
[LibreOffice.git] / pyuno / qa / pytests / testcollections_XNameReplace.py
blob18476fd2b44773ab772b36a0be0f74edf38aff6a
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
11 import uno
13 from testcollections_base import CollectionsTestBase
14 from com.sun.star.beans import PropertyValue
17 def getScriptName():
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
23 # tested interfaces
25 class TestXNameReplace(CollectionsTestBase):
27 # Tests syntax:
28 # obj[key] = val # Replace by key
29 # For:
30 # 1 element
31 def test_XNameReplace_ReplaceName(self):
32 # Given
33 doc = self.createBlankTextDocument()
34 event_properties = (PropertyValue(Name='Script', Value=getScriptName()),)
36 # When
37 doc.Events['OnSave'] = event_properties
39 # Then
40 on_save = [p.Value for p in doc.Events['OnSave'] if p.Name == 'Script'][0]
41 self.assertEqual(getScriptName(), on_save)
43 doc.close(True)
45 # Tests syntax:
46 # obj[key] = val # Replace by key
47 # For:
48 # Invalid key
49 def test_XNameReplace_ReplaceName_Invalid(self):
50 # Given
51 doc = self.createBlankTextDocument()
52 event_properties = (PropertyValue(Name='Script', Value=getScriptName()),)
54 # When / Then
55 with self.assertRaises(KeyError):
56 doc.Events['qqqqq'] = event_properties
58 doc.close(True)
60 # Tests syntax:
61 # obj[key] = val # Replace by key
62 # For:
63 # Invalid key type
64 def test_XNameReplace_ReplaceName_Invalid(self):
65 # Given
66 doc = self.createBlankTextDocument()
67 event_properties = (PropertyValue(Name='Script', Value=getScriptName()),)
69 # When / Then
70 with self.assertRaises(TypeError):
71 doc.Events[12.34] = event_properties
73 doc.close(True)
76 if __name__ == '__main__':
77 unittest.main()
79 # vim:set shiftwidth=4 softtabstop=4 expandtab: