[Libreoffice-commits] core.git: pyuno/source

2016-07-14 Thread Kenneth Koski
 pyuno/source/module/uno.py |  619 ++---
 1 file changed, 367 insertions(+), 252 deletions(-)

New commits:
commit deb989dd6d1f86e74864131be50ed92d8d43768c
Author: Kenneth Koski <mech...@gmail.com>
Date:   Mon Feb 29 22:22:10 2016 -0600

Improving uno.py code style

* Fixing pep8 violations
* Improving comments, docstrings, and unifying coding style
* Using functionality copied from six library for Python 2/3 compatibility
* Using standard traceback formatting

Change-Id: I62bd0e8513ffc59202163002fa4adea3d92572c3
Reviewed-on: https://gerrit.libreoffice.org/22848
Tested-by: Jenkins <c...@libreoffice.org>
Reviewed-by: Michael Stahl <mst...@redhat.com>
Tested-by: Michael Stahl <mst...@redhat.com>

diff --git a/pyuno/source/module/uno.py b/pyuno/source/module/uno.py
index 1526aac..29cc684 100644
--- a/pyuno/source/module/uno.py
+++ b/pyuno/source/module/uno.py
@@ -16,208 +16,278 @@
 #   except in compliance with the License. You may obtain a copy of
 #   the License at http://www.apache.org/licenses/LICENSE-2.0 .
 #
+import pyuno
 import sys
+import traceback
+import warnings
 
-import pyuno
+# since on Windows sal3.dll no longer calls WSAStartup
+import socket
 
-try:
-import __builtin__
-except ImportError:
-import builtins as __builtin__
+# Some Python 2/3 compatibility code copied from the six library
+PY2 = sys.version_info[0] == 2
 
-try:
-unicode
-except NameError:
-# Python 3 compatibility
-unicode = str
+if PY2:
+six_string_types = basestring,
+else:
+six_string_types = str,
 
-import socket # since on Windows sal3.dll no longer calls WSAStartup
+# All functions and variables starting with a underscore (_) must be
+# considered private and can be changed at any time. Don't use them.
+_component_context = pyuno.getComponentContext()
 
-# all functions and variables starting with a underscore (_) must be 
considered private
-# and can be changed at any time. Don't use them
-_g_ctx = pyuno.getComponentContext( )
-_g_delegatee = __builtin__.__dict__["__import__"]
 
 def getComponentContext():
-""" returns the UNO component context, that was used to initialize the 
python runtime.
+"""Returns the UNO component context used to initialize the Python 
runtime."""
+
+return _component_context
+
+
+def getCurrentContext():
+"""Returns the current context.
+
+See 
http://udk.openoffice.org/common/man/concept/uno_contexts.html#current_context
+for an explanation on the current context concept.
 """
-return _g_ctx
 
-def getConstantByName( constant ):
-"Looks up the value of a idl constant by giving its explicit name"
-return pyuno.getConstantByName( constant )
+return pyuno.getCurrentContext()
+
 
-def getTypeByName( typeName):
-""" returns a uno.Type instance of the type given by typeName. In case the
-type does not exist, a com.sun.star.uno.RuntimeException is raised.
+def setCurrentContext(newContext):
+"""Sets newContext as new UNO context.
+
+The newContext must implement the XCurrentContext interface. The
+implementation should handle the desired properties and delegate
+unknown properties to the old context. Ensure that the old one
+is reset when you leave your stack, see
+
http://udk.openoffice.org/common/man/concept/uno_contexts.html#current_context
 """
-return pyuno.getTypeByName( typeName )
 
-def createUnoStruct( typeName, *args, **kwargs ):
-"""creates a uno struct or exception given by typeName. Can be called with:
+return pyuno.setCurrentContext(newContext)
+
+
+def getConstantByName(constant):
+"""Looks up the value of an IDL constant by giving its explicit name."""
+
+return pyuno.getConstantByName(constant)
+
+
+def getTypeByName(typeName):
+"""Returns a `uno.Type` instance of the type given by typeName.
+
+If the type does not exist, a `com.sun.star.uno.RuntimeException` is 
raised.
+"""
+
+return pyuno.getTypeByName(typeName)
+
+
+def createUnoStruct(typeName, *args, **kwargs):
+"""Creates a UNO struct or exception given by typeName.
+
+Can be called with:
+
 1) No additional argument.
-   In this case, you get a default constructed uno structure.
-   ( e.g. createUnoStruct( "com.sun.star.uno.Exception" ) )
+   In this case, you get a default constructed UNO structure.
+   (e.g. `createUnoStruct("com.sun.star.uno.Exception")`)
 2) Exactly one additional argument that is an instance of typeName.
In this case, a copy constructed instance of typeName is returned
-   ( e.g. createUnoStruct( "com.sun.star.uno.Exception" , e ) )
+   (e.g

[Libreoffice-commits] core.git: pyuno/qa

2016-02-23 Thread Kenneth Koski
 pyuno/qa/pytests/insertremovecells.py  |   28 
 pyuno/qa/pytests/testcollections_XCellRange.py |   53 -
 pyuno/qa/pytests/testcollections_XEnumeration.py   |2 
 pyuno/qa/pytests/testcollections_XEnumerationAccess.py |2 
 pyuno/qa/pytests/testcollections_XIndexAccess.py   |   22 +++
 pyuno/qa/pytests/testcollections_XIndexContainer.py|   40 ++--
 pyuno/qa/pytests/testcollections_XIndexReplace.py  |   39 ++--
 pyuno/qa/pytests/testcollections_XNameAccess.py|   13 +---
 pyuno/qa/pytests/testcollections_XNameContainer.py |   10 +--
 pyuno/qa/pytests/testcollections_XNameReplace.py   |2 
 pyuno/qa/pytests/testcollections_base.py   |3 
 pyuno/qa/pytests/testcollections_misc.py   |2 
 pyuno/qa/pytests/testcollections_mixednameindex.py |6 -
 pyuno/qa/pytests/testssl.py|4 -
 14 files changed, 111 insertions(+), 115 deletions(-)

New commits:
commit 4f6e3108d9b9b67f21d11d597f2e607acafabd72
Author: Kenneth Koski <mech...@gmail.com>
Date:   Fri Feb 19 19:55:31 2016 -0600

Running pep8 on pyuno unit test files

Change-Id: I5d35305386e1f520d1030776e2b7bcf7620eda04
Reviewed-on: https://gerrit.libreoffice.org/22514
Tested-by: Jenkins <c...@libreoffice.org>
Reviewed-by: Samuel Mehrbrodt <samuel.mehrbr...@cib.de>

diff --git a/pyuno/qa/pytests/insertremovecells.py 
b/pyuno/qa/pytests/insertremovecells.py
index 9c521f2..5c2585a 100644
--- a/pyuno/qa/pytests/insertremovecells.py
+++ b/pyuno/qa/pytests/insertremovecells.py
@@ -9,6 +9,7 @@ except ImportError:
 
 from org.libreoffice.unotest import pyuno, mkPropertyValue
 
+
 class InsertRemoveCells(unittest.TestCase):
 
 @classmethod
@@ -16,10 +17,6 @@ class InsertRemoveCells(unittest.TestCase):
 cls.xContext = pyuno.getComponentContext()
 pyuno.private_initTestEnvironment()
 
-
-# no need for a tearDown(cls) method.
-
-
 def test_fdo74824_load(self):
 ctxt = self.xContext
 assert(ctxt)
@@ -35,12 +32,12 @@ class InsertRemoveCells(unittest.TestCase):
 doc = desktop.loadComponentFromURL(url, "_blank", 0, loadProps)
 
 sheet = doc.Sheets.Sheet1
-area = sheet.getCellRangeByName( 'A2:B4' )
+area = sheet.getCellRangeByName('A2:B4')
 addr = area.getRangeAddress()
 
 # 2 = intended to shift cells right, but I don't know where to find
 # the ENUM to put in its place.  Corrections welcome.
-sheet.insertCells( addr, 2 )
+sheet.insertCells(addr, 2)
 
 # basically, the insertCells call is the test: it should not crash
 # LibreOffice.  However, for completeness, we should test the cell
@@ -65,21 +62,22 @@ class InsertRemoveCells(unittest.TestCase):
 )
 for pos in empty_cells:
 cell = sheet.getCellByPosition(*pos)
-self.assertEqual( 'EMPTY', cell.Type.value )
+self.assertEqual('EMPTY', cell.Type.value)
+
 for x, y, f, s, val in formula_cells:
 cell = sheet.getCellByPosition(x, y)
-self.assertEqual( 'FORMULA', cell.Type.value )
-self.assertEqual( f, cell.getFormula() )
-self.assertEqual( s, cell.String )
-self.assertEqual( val, cell.Value )
+self.assertEqual('FORMULA', cell.Type.value)
+self.assertEqual(f, cell.getFormula())
+self.assertEqual(s, cell.String)
+self.assertEqual(val, cell.Value)
+
 for x, y, s, val in value_cells:
 cell = sheet.getCellByPosition(x, y)
-self.assertEqual( s, cell.String )
-self.assertEqual( val, cell.Value )
+self.assertEqual(s, cell.String)
+self.assertEqual(val, cell.Value)
 
-doc.close( True )
+doc.close(True)
 
 
 if __name__ == '__main__':
 unittest.main()
-
diff --git a/pyuno/qa/pytests/testcollections_XCellRange.py 
b/pyuno/qa/pytests/testcollections_XCellRange.py
index ad8819b..871f92d 100644
--- a/pyuno/qa/pytests/testcollections_XCellRange.py
+++ b/pyuno/qa/pytests/testcollections_XCellRange.py
@@ -33,7 +33,7 @@ class TestXCellRange(CollectionsTestBase):
 sht = spr.Sheets.getByIndex(0)
 
 # When
-cell = sht[0,0]
+cell = sht[0, 0]
 
 # Then
 self.assertEqual(0, cell.CellAddress.Sheet)
@@ -49,13 +49,13 @@ class TestXCellRange(CollectionsTestBase):
 # Given
 doc = self.createBlankTextDocument()
 textTable = doc.createInstance('com.sun.star.text.TextTable')
-textTable.initialize(10,10)
+textTable.initialize(10, 10)
 cursor = doc.Text.createTextCursor()
 doc.Text.insertTextContent(cursor, textTable, False)
 tbl = doc.TextTables.getByIndex(0)
 
 # When
-cell = tbl[0,0]
+cell = tbl[0, 0]
 
 # Then