Kaydet (Commit) e7a3329f authored tarafından Stephan Bergmann's avatar Stephan Bergmann

DeInitVCL in PythonTest

After b9757f5c "loplugin:useuniqueptr in
vcl/svdata" ASan/UBSan builds started to fail (like
<https://ci.libreoffice.org//job/lo_ubsan/1025/>) at the end of
PythonTest_dbaccess_python (and probably other PythonTests), when during exit
the static utl::ConfigManager instance already happens to be destroyed by the
time the static ImplSVData's mpSettingsConfigItem is destroyed (which would
normally be cleared during DeInitVCL, if PythonTests would call that, and which
in the past had thus simply been leaked in PythonTests when that
mpSettingsConfigItem was a plain pointer instead of std::unique_ptr).

So ensure that PythonTests that initialize VCL also call DeInitVCL, via a new
private_deinitTestEnvironment, complementing the existing
private_initTestEnvironment.

However, while private_initTestEnvironment is called once (typically via
UnoInProcess.setUp, which internally makes sure to only call it once) as soon as
the first executed test needs it, private_deinitTestEnvironment must be called
once after the lasts test needing it has executed.  The only way that I found to
do that is to override unittest.TextTestResult's stopTestRun method, which is
called once after all tests have been executed.  Hence a new test runner setup
in unotest/source/python/org/libreoffice/unittest.py that is now called from
solenv/gbuild/PythonTest.mk.

That revealed a few places in PythonTests that didn't yet close/delete documents
that they had opened, which has now been added.

One remaining problem then is that classes like SwXTextDocument and friends call
Application::GetSolarMutex from their dtors, via sw::UnoImplPtrDeleter (a "Smart
pointer class ensuring that the pointed object is deleted with a locked
SolarMutex", sw/inc/unobaseclass.hxx).  That means that any PyUNO proxies to
such C++ objects that remain alive after private_deinitTestEnvironment will
cause issues at exit, when Python does a final garbage collection of those
objects.  The ultimate fix will be to remove that unhelpful UnoImplPtrDeleter
and its locking of SolarMutex from the dtors of UNO objects; until then, the
Python code is now sprinkled with some HACKs to make sure all those PyUNO
proxies are released in a timely fashion (see the comment in
unotest/source/python/org/libreoffice/unittest.py for details).  (Also, it would
probably help if UnoInProcess didn't keep a local self.xDoc around referencing
(just) the last result of calling one of its open* methods, confusingly making
it the responsibility of UnoInProcess to close that one document while making it
the responsibility of the test code making the other UnoInProcess.open* calls to
close any other documents.)

Change-Id: Ief27c81e2b763e9be20cbf3234b68924315f13be
Reviewed-on: https://gerrit.libreoffice.org/60100
Tested-by: Jenkins
Reviewed-by: 's avatarStephan Bergmann <sbergman@redhat.com>
üst dbb444e4
...@@ -43,6 +43,8 @@ class TestXCellRange(CollectionsTestBase): ...@@ -43,6 +43,8 @@ class TestXCellRange(CollectionsTestBase):
self.assertEqual(0, cell.CellAddress.Row) self.assertEqual(0, cell.CellAddress.Row)
self.assertEqual(0, cell.CellAddress.Column) self.assertEqual(0, cell.CellAddress.Column)
spr.close(True)
# Tests syntax: # Tests syntax:
# cell = cellrange[0,0] # Access cell by indices # cell = cellrange[0,0] # Access cell by indices
# For: # For:
...@@ -63,6 +65,8 @@ class TestXCellRange(CollectionsTestBase): ...@@ -63,6 +65,8 @@ class TestXCellRange(CollectionsTestBase):
# Then # Then
self.assertEqual('A1', cell.CellName) self.assertEqual('A1', cell.CellName)
doc.close(True)
# Tests syntax: # Tests syntax:
# cell = cellrange[0,0] # Access cell by indices # cell = cellrange[0,0] # Access cell by indices
# For: # For:
...@@ -81,6 +85,8 @@ class TestXCellRange(CollectionsTestBase): ...@@ -81,6 +85,8 @@ class TestXCellRange(CollectionsTestBase):
self.assertEqual(3, rng.CellAddress.Row) self.assertEqual(3, rng.CellAddress.Row)
self.assertEqual(7, rng.CellAddress.Column) self.assertEqual(7, rng.CellAddress.Column)
spr.close(True)
# Tests syntax: # Tests syntax:
# cell = cellrange[0,0] # Access cell by indices # cell = cellrange[0,0] # Access cell by indices
# For: # For:
...@@ -101,6 +107,8 @@ class TestXCellRange(CollectionsTestBase): ...@@ -101,6 +107,8 @@ class TestXCellRange(CollectionsTestBase):
# Then # Then
self.assertEqual('H4', cell.CellName) self.assertEqual('H4', cell.CellName)
doc.close(True)
# Tests syntax: # Tests syntax:
# rng = cellrange[0,1:2] # Access cell range by index,slice # rng = cellrange[0,1:2] # Access cell range by index,slice
# For: # For:
...@@ -120,6 +128,8 @@ class TestXCellRange(CollectionsTestBase): ...@@ -120,6 +128,8 @@ class TestXCellRange(CollectionsTestBase):
self.assertEqual(0, rng.RangeAddress.EndRow) self.assertEqual(0, rng.RangeAddress.EndRow)
self.assertEqual(2, rng.RangeAddress.EndColumn) self.assertEqual(2, rng.RangeAddress.EndColumn)
spr.close(True)
# Tests syntax: # Tests syntax:
# rng = cellrange[0,1:2] # Access cell range by index,slice # rng = cellrange[0,1:2] # Access cell range by index,slice
# For: # For:
...@@ -142,6 +152,8 @@ class TestXCellRange(CollectionsTestBase): ...@@ -142,6 +152,8 @@ class TestXCellRange(CollectionsTestBase):
# Then # Then
self.assertEqual((('101', '102'),), rng.DataArray) self.assertEqual((('101', '102'),), rng.DataArray)
doc.close(True)
# Tests syntax: # Tests syntax:
# rng = cellrange[1:2,0] # Access cell range by slice,index # rng = cellrange[1:2,0] # Access cell range by slice,index
# For: # For:
...@@ -161,6 +173,8 @@ class TestXCellRange(CollectionsTestBase): ...@@ -161,6 +173,8 @@ class TestXCellRange(CollectionsTestBase):
self.assertEqual(2, rng.RangeAddress.EndRow) self.assertEqual(2, rng.RangeAddress.EndRow)
self.assertEqual(0, rng.RangeAddress.EndColumn) self.assertEqual(0, rng.RangeAddress.EndColumn)
spr.close(True)
# Tests syntax: # Tests syntax:
# rng = cellrange[1:2,0] # Access cell range by index,slice # rng = cellrange[1:2,0] # Access cell range by index,slice
# For: # For:
...@@ -183,6 +197,8 @@ class TestXCellRange(CollectionsTestBase): ...@@ -183,6 +197,8 @@ class TestXCellRange(CollectionsTestBase):
# Then # Then
self.assertEqual((('110',), ('120',)), rng.DataArray) self.assertEqual((('110',), ('120',)), rng.DataArray)
doc.close(True)
# Tests syntax: # Tests syntax:
# rng = cellrange[0:1,2:3] # Access cell range by slices # rng = cellrange[0:1,2:3] # Access cell range by slices
# For: # For:
...@@ -202,6 +218,8 @@ class TestXCellRange(CollectionsTestBase): ...@@ -202,6 +218,8 @@ class TestXCellRange(CollectionsTestBase):
self.assertEqual(2, rng.RangeAddress.EndRow) self.assertEqual(2, rng.RangeAddress.EndRow)
self.assertEqual(4, rng.RangeAddress.EndColumn) self.assertEqual(4, rng.RangeAddress.EndColumn)
spr.close(True)
# Tests syntax: # Tests syntax:
# rng = cellrange[0:1,2:3] # Access cell range by slices # rng = cellrange[0:1,2:3] # Access cell range by slices
# For: # For:
...@@ -218,6 +236,8 @@ class TestXCellRange(CollectionsTestBase): ...@@ -218,6 +236,8 @@ class TestXCellRange(CollectionsTestBase):
with self.assertRaises(KeyError): with self.assertRaises(KeyError):
rng = sht[1:3, 3:3] rng = sht[1:3, 3:3]
spr.close(True)
# Tests syntax: # Tests syntax:
# rng = cellrange[0:1,2:3] # Access cell range by slices # rng = cellrange[0:1,2:3] # Access cell range by slices
# For: # For:
...@@ -240,6 +260,8 @@ class TestXCellRange(CollectionsTestBase): ...@@ -240,6 +260,8 @@ class TestXCellRange(CollectionsTestBase):
# Then # Then
self.assertEqual((('113', '114'), ('123', '124')), rng.DataArray) self.assertEqual((('113', '114'), ('123', '124')), rng.DataArray)
doc.close(True)
# Tests syntax: # Tests syntax:
# rng = cellrange['A1:B2'] # Access cell range by descriptor # rng = cellrange['A1:B2'] # Access cell range by descriptor
# For: # For:
...@@ -259,6 +281,8 @@ class TestXCellRange(CollectionsTestBase): ...@@ -259,6 +281,8 @@ class TestXCellRange(CollectionsTestBase):
self.assertEqual(3, rng.RangeAddress.EndRow) self.assertEqual(3, rng.RangeAddress.EndRow)
self.assertEqual(1, rng.RangeAddress.EndColumn) self.assertEqual(1, rng.RangeAddress.EndColumn)
spr.close(True)
# Tests syntax: # Tests syntax:
# rng = cellrange['A1:B2'] # Access cell range by descriptor # rng = cellrange['A1:B2'] # Access cell range by descriptor
# For: # For:
...@@ -281,6 +305,8 @@ class TestXCellRange(CollectionsTestBase): ...@@ -281,6 +305,8 @@ class TestXCellRange(CollectionsTestBase):
# Then # Then
self.assertEqual((('120', '121'), ('130', '131')), rng.DataArray) self.assertEqual((('120', '121'), ('130', '131')), rng.DataArray)
doc.close(True)
# Tests syntax: # Tests syntax:
# rng = cellrange['Name'] # Access cell range by name # rng = cellrange['Name'] # Access cell range by name
# For: # For:
...@@ -303,6 +329,8 @@ class TestXCellRange(CollectionsTestBase): ...@@ -303,6 +329,8 @@ class TestXCellRange(CollectionsTestBase):
self.assertEqual(9, rng.RangeAddress.EndRow) self.assertEqual(9, rng.RangeAddress.EndRow)
self.assertEqual(5, rng.RangeAddress.EndColumn) self.assertEqual(5, rng.RangeAddress.EndColumn)
spr.close(True)
# Tests syntax: # Tests syntax:
# rng = cellrange[0] # Access cell range by row index # rng = cellrange[0] # Access cell range by row index
# For: # For:
...@@ -322,6 +350,8 @@ class TestXCellRange(CollectionsTestBase): ...@@ -322,6 +350,8 @@ class TestXCellRange(CollectionsTestBase):
self.assertEqual(0, rng.RangeAddress.EndRow) self.assertEqual(0, rng.RangeAddress.EndRow)
self.assertEqual(1023, rng.RangeAddress.EndColumn) self.assertEqual(1023, rng.RangeAddress.EndColumn)
spr.close(True)
# Tests syntax: # Tests syntax:
# rng = cellrange[0,:] # Access cell range by row index # rng = cellrange[0,:] # Access cell range by row index
# For: # For:
...@@ -341,6 +371,8 @@ class TestXCellRange(CollectionsTestBase): ...@@ -341,6 +371,8 @@ class TestXCellRange(CollectionsTestBase):
self.assertEqual(0, rng.RangeAddress.EndRow) self.assertEqual(0, rng.RangeAddress.EndRow)
self.assertEqual(1023, rng.RangeAddress.EndColumn) self.assertEqual(1023, rng.RangeAddress.EndColumn)
spr.close(True)
# Tests syntax: # Tests syntax:
# rng = cellrange[:,0] # Access cell range by column index # rng = cellrange[:,0] # Access cell range by column index
# For: # For:
...@@ -360,6 +392,8 @@ class TestXCellRange(CollectionsTestBase): ...@@ -360,6 +392,8 @@ class TestXCellRange(CollectionsTestBase):
self.assertEqual(1048575, rng.RangeAddress.EndRow) self.assertEqual(1048575, rng.RangeAddress.EndRow)
self.assertEqual(0, rng.RangeAddress.EndColumn) self.assertEqual(0, rng.RangeAddress.EndColumn)
spr.close(True)
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()
......
...@@ -38,6 +38,8 @@ class TestXEnumeration(CollectionsTestBase): ...@@ -38,6 +38,8 @@ class TestXEnumeration(CollectionsTestBase):
# Then # Then
self.assertEqual(1, len(paragraphs)) self.assertEqual(1, len(paragraphs))
doc.close(True)
# Tests syntax: # Tests syntax:
# if val in itr: ... # Test value presence # if val in itr: ... # Test value presence
# For: # For:
...@@ -54,6 +56,8 @@ class TestXEnumeration(CollectionsTestBase): ...@@ -54,6 +56,8 @@ class TestXEnumeration(CollectionsTestBase):
# Then # Then
self.assertTrue(result) self.assertTrue(result)
doc.close(True)
# Tests syntax: # Tests syntax:
# if val in itr: ... # Test value presence # if val in itr: ... # Test value presence
# For: # For:
...@@ -71,6 +75,9 @@ class TestXEnumeration(CollectionsTestBase): ...@@ -71,6 +75,9 @@ class TestXEnumeration(CollectionsTestBase):
# Then # Then
self.assertFalse(result) self.assertFalse(result)
doc1.close(True)
doc2.close(True)
# Tests syntax: # Tests syntax:
# if val in itr: ... # Test value presence # if val in itr: ... # Test value presence
# For: # For:
...@@ -86,6 +93,8 @@ class TestXEnumeration(CollectionsTestBase): ...@@ -86,6 +93,8 @@ class TestXEnumeration(CollectionsTestBase):
# Then # Then
self.assertFalse(result) self.assertFalse(result)
doc.close(True)
# Tests syntax: # Tests syntax:
# if val in itr: ... # Test value presence # if val in itr: ... # Test value presence
# For: # For:
...@@ -104,6 +113,8 @@ class TestXEnumeration(CollectionsTestBase): ...@@ -104,6 +113,8 @@ class TestXEnumeration(CollectionsTestBase):
# Then # Then
self.assertFalse(result) self.assertFalse(result)
doc.close(True)
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()
......
...@@ -37,6 +37,8 @@ class TestXEnumerationAccess(CollectionsTestBase): ...@@ -37,6 +37,8 @@ class TestXEnumerationAccess(CollectionsTestBase):
# Then # Then
self.assertEqual(1, len(paragraphs)) self.assertEqual(1, len(paragraphs))
doc.close(True)
# Tests syntax: # Tests syntax:
# itr = iter(obj) # Named iterator # itr = iter(obj) # Named iterator
# For: # For:
...@@ -53,6 +55,8 @@ class TestXEnumerationAccess(CollectionsTestBase): ...@@ -53,6 +55,8 @@ class TestXEnumerationAccess(CollectionsTestBase):
with self.assertRaises(StopIteration): with self.assertRaises(StopIteration):
next(itr) next(itr)
doc.close(True)
# Tests syntax: # Tests syntax:
# if val in obj: ... # Test value presence # if val in obj: ... # Test value presence
# For: # For:
...@@ -68,6 +72,8 @@ class TestXEnumerationAccess(CollectionsTestBase): ...@@ -68,6 +72,8 @@ class TestXEnumerationAccess(CollectionsTestBase):
# Then # Then
self.assertTrue(result) self.assertTrue(result)
doc.close(True)
# Tests syntax: # Tests syntax:
# if val in obj: ... # Test value presence # if val in obj: ... # Test value presence
# For: # For:
...@@ -84,6 +90,9 @@ class TestXEnumerationAccess(CollectionsTestBase): ...@@ -84,6 +90,9 @@ class TestXEnumerationAccess(CollectionsTestBase):
# Then # Then
self.assertFalse(result) self.assertFalse(result)
doc1.close(True)
doc2.close(True)
# Tests syntax: # Tests syntax:
# if val in obj: ... # Test value presence # if val in obj: ... # Test value presence
# For: # For:
...@@ -98,6 +107,8 @@ class TestXEnumerationAccess(CollectionsTestBase): ...@@ -98,6 +107,8 @@ class TestXEnumerationAccess(CollectionsTestBase):
# Then # Then
self.assertFalse(result) self.assertFalse(result)
doc.close(True)
# Tests syntax: # Tests syntax:
# if val in obj: ... # Test value presence # if val in obj: ... # Test value presence
# For: # For:
...@@ -112,6 +123,8 @@ class TestXEnumerationAccess(CollectionsTestBase): ...@@ -112,6 +123,8 @@ class TestXEnumerationAccess(CollectionsTestBase):
# Then # Then
self.assertFalse(result) self.assertFalse(result)
doc.close(True)
# Tests syntax: # Tests syntax:
# if val in obj: ... # Test value presence # if val in obj: ... # Test value presence
# For: # For:
...@@ -124,6 +137,8 @@ class TestXEnumerationAccess(CollectionsTestBase): ...@@ -124,6 +137,8 @@ class TestXEnumerationAccess(CollectionsTestBase):
with self.assertRaises(TypeError): with self.assertRaises(TypeError):
result = {} in doc.Text result = {} in doc.Text
doc.close(True)
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()
......
...@@ -77,6 +77,8 @@ class TestXIndexAccess(CollectionsTestBase): ...@@ -77,6 +77,8 @@ class TestXIndexAccess(CollectionsTestBase):
# Then # Then
self.assertEqual(0, count) self.assertEqual(0, count)
doc.close(True);
# Tests syntax: # Tests syntax:
# num = len(obj) # Number of elements # num = len(obj) # Number of elements
# For: # For:
...@@ -94,6 +96,8 @@ class TestXIndexAccess(CollectionsTestBase): ...@@ -94,6 +96,8 @@ class TestXIndexAccess(CollectionsTestBase):
# Then # Then
self.assertEqual(1, count) self.assertEqual(1, count)
doc.close(True);
# Tests syntax: # Tests syntax:
# val = obj[0] # Access by index # val = obj[0] # Access by index
# For: # For:
...@@ -117,6 +121,7 @@ class TestXIndexAccess(CollectionsTestBase): ...@@ -117,6 +121,7 @@ class TestXIndexAccess(CollectionsTestBase):
self.readValuesTestFixture(doc, 2, 1, 1) self.readValuesTestFixture(doc, 2, 1, 1)
self.readValuesTestFixture(doc, 2, 2, IndexError) self.readValuesTestFixture(doc, 2, 2, IndexError)
self.readValuesTestFixture(doc, 2, 3, IndexError) self.readValuesTestFixture(doc, 2, 3, IndexError)
doc.close(True);
def test_XIndexAccess_ReadIndex_Single_Invalid(self): def test_XIndexAccess_ReadIndex_Single_Invalid(self):
doc = self.createBlankTextDocument() doc = self.createBlankTextDocument()
...@@ -126,6 +131,7 @@ class TestXIndexAccess(CollectionsTestBase): ...@@ -126,6 +131,7 @@ class TestXIndexAccess(CollectionsTestBase):
self.readValuesTestFixture(doc, 0, (0, 1), TypeError) self.readValuesTestFixture(doc, 0, (0, 1), TypeError)
self.readValuesTestFixture(doc, 0, [0, 1], TypeError) self.readValuesTestFixture(doc, 0, [0, 1], TypeError)
self.readValuesTestFixture(doc, 0, {'a': 'b'}, TypeError) self.readValuesTestFixture(doc, 0, {'a': 'b'}, TypeError)
doc.close(True);
# Tests syntax: # Tests syntax:
# val1,val2 = obj[2:4] # Access by slice # val1,val2 = obj[2:4] # Access by slice
...@@ -139,6 +145,7 @@ class TestXIndexAccess(CollectionsTestBase): ...@@ -139,6 +145,7 @@ class TestXIndexAccess(CollectionsTestBase):
key = slice(j, k) key = slice(j, k)
expected = t[key] expected = t[key]
self.readValuesTestFixture(doc, i, key, expected) self.readValuesTestFixture(doc, i, key, expected)
doc.close(True);
# Tests syntax: # Tests syntax:
# val1,val2 = obj[0:3:2] # Access by extended slice # val1,val2 = obj[0:3:2] # Access by extended slice
...@@ -153,6 +160,7 @@ class TestXIndexAccess(CollectionsTestBase): ...@@ -153,6 +160,7 @@ class TestXIndexAccess(CollectionsTestBase):
key = slice(j, k, l) key = slice(j, k, l)
expected = t[key] expected = t[key]
self.readValuesTestFixture(doc, i, key, expected) self.readValuesTestFixture(doc, i, key, expected)
doc.close(True);
# Tests syntax: # Tests syntax:
# if val in obj: ... # Test value presence # if val in obj: ... # Test value presence
...@@ -173,6 +181,8 @@ class TestXIndexAccess(CollectionsTestBase): ...@@ -173,6 +181,8 @@ class TestXIndexAccess(CollectionsTestBase):
# Then # Then
self.assertTrue(present) self.assertTrue(present)
doc.close(True);
# Tests syntax: # Tests syntax:
# if val in obj: ... # Test value presence # if val in obj: ... # Test value presence
# For: # For:
...@@ -187,6 +197,8 @@ class TestXIndexAccess(CollectionsTestBase): ...@@ -187,6 +197,8 @@ class TestXIndexAccess(CollectionsTestBase):
# Then # Then
self.assertFalse(present) self.assertFalse(present)
doc.close(True);
# Tests syntax: # Tests syntax:
# if val in obj: ... # Test value presence # if val in obj: ... # Test value presence
# For: # For:
...@@ -201,6 +213,8 @@ class TestXIndexAccess(CollectionsTestBase): ...@@ -201,6 +213,8 @@ class TestXIndexAccess(CollectionsTestBase):
# Then # Then
self.assertFalse(present) self.assertFalse(present)
doc.close(True);
# Tests syntax: # Tests syntax:
# if val in obj: ... # Test value presence # if val in obj: ... # Test value presence
# For: # For:
...@@ -213,6 +227,8 @@ class TestXIndexAccess(CollectionsTestBase): ...@@ -213,6 +227,8 @@ class TestXIndexAccess(CollectionsTestBase):
with self.assertRaises(TypeError): with self.assertRaises(TypeError):
present = {} in doc.Footnotes present = {} in doc.Footnotes
doc.close(True);
# Tests syntax: # Tests syntax:
# for val in obj: ... # Implicit iterator (values) # for val in obj: ... # Implicit iterator (values)
# For: # For:
...@@ -229,6 +245,8 @@ class TestXIndexAccess(CollectionsTestBase): ...@@ -229,6 +245,8 @@ class TestXIndexAccess(CollectionsTestBase):
# Then # Then
self.assertEqual(0, len(read_footnotes)) self.assertEqual(0, len(read_footnotes))
doc.close(True);
# Tests syntax: # Tests syntax:
# for val in obj: ... # Implicit iterator (values) # for val in obj: ... # Implicit iterator (values)
# For: # For:
...@@ -250,6 +268,8 @@ class TestXIndexAccess(CollectionsTestBase): ...@@ -250,6 +268,8 @@ class TestXIndexAccess(CollectionsTestBase):
self.assertEqual(1, len(read_footnotes)) self.assertEqual(1, len(read_footnotes))
self.assertEqual('foo', read_footnotes[0].Label) self.assertEqual('foo', read_footnotes[0].Label)
doc.close(True);
# Tests syntax: # Tests syntax:
# for val in obj: ... # Implicit iterator (values) # for val in obj: ... # Implicit iterator (values)
# For: # For:
...@@ -275,6 +295,8 @@ class TestXIndexAccess(CollectionsTestBase): ...@@ -275,6 +295,8 @@ class TestXIndexAccess(CollectionsTestBase):
self.assertEqual('foo', read_footnotes[0].Label) self.assertEqual('foo', read_footnotes[0].Label)
self.assertEqual('bar', read_footnotes[1].Label) self.assertEqual('bar', read_footnotes[1].Label)
doc.close(True);
# Tests syntax: # Tests syntax:
# itr = iter(obj) # Named iterator (values) # itr = iter(obj) # Named iterator (values)
# For: # For:
...@@ -295,6 +317,8 @@ class TestXIndexAccess(CollectionsTestBase): ...@@ -295,6 +317,8 @@ class TestXIndexAccess(CollectionsTestBase):
with self.assertRaises(StopIteration): with self.assertRaises(StopIteration):
next(itr) next(itr)
doc.close(True);
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()
......
...@@ -145,6 +145,8 @@ class TestXIndexContainer(CollectionsTestBase): ...@@ -145,6 +145,8 @@ class TestXIndexContainer(CollectionsTestBase):
# Then # Then
self.assertEqual('foo', doc.DrawPage.Forms[0].Name) self.assertEqual('foo', doc.DrawPage.Forms[0].Name)
doc.close(True)
# Tests syntax: # Tests syntax:
# obj[0:3:2] = val1,val2 # Replace by extended slice # obj[0:3:2] = val1,val2 # Replace by extended slice
# For: # For:
......
...@@ -78,6 +78,8 @@ class TestXIndexReplace(CollectionsTestBase): ...@@ -78,6 +78,8 @@ class TestXIndexReplace(CollectionsTestBase):
# Then # Then
self.assertEqual(('Caption',), index.LevelParagraphStyles[0]) self.assertEqual(('Caption',), index.LevelParagraphStyles[0])
doc.close(True)
# Tests syntax: # Tests syntax:
# obj[0] = val # Replace by index # obj[0] = val # Replace by index
# For: # For:
...@@ -91,6 +93,8 @@ class TestXIndexReplace(CollectionsTestBase): ...@@ -91,6 +93,8 @@ class TestXIndexReplace(CollectionsTestBase):
with self.assertRaises(TypeError): with self.assertRaises(TypeError):
index.LevelParagraphStyles[0] = None index.LevelParagraphStyles[0] = None
doc.close(True)
# Tests syntax: # Tests syntax:
# obj[0] = val # Replace by index # obj[0] = val # Replace by index
# For: # For:
...@@ -104,6 +108,8 @@ class TestXIndexReplace(CollectionsTestBase): ...@@ -104,6 +108,8 @@ class TestXIndexReplace(CollectionsTestBase):
with self.assertRaises(TypeError): with self.assertRaises(TypeError):
index.LevelParagraphStyles[0] = 'foo' index.LevelParagraphStyles[0] = 'foo'
doc.close(True)
# Tests syntax: # Tests syntax:
# obj[0] = val # Replace by index # obj[0] = val # Replace by index
# For: # For:
...@@ -117,6 +123,8 @@ class TestXIndexReplace(CollectionsTestBase): ...@@ -117,6 +123,8 @@ class TestXIndexReplace(CollectionsTestBase):
with self.assertRaises(TypeError): with self.assertRaises(TypeError):
index.LevelParagraphStyles[0] = 12.34 index.LevelParagraphStyles[0] = 12.34
doc.close(True)
# Tests syntax: # Tests syntax:
# obj[0] = val # Replace by index # obj[0] = val # Replace by index
# For: # For:
...@@ -130,6 +138,8 @@ class TestXIndexReplace(CollectionsTestBase): ...@@ -130,6 +138,8 @@ class TestXIndexReplace(CollectionsTestBase):
with self.assertRaises(TypeError): with self.assertRaises(TypeError):
index.LevelParagraphStyles[0] = [0, 1] index.LevelParagraphStyles[0] = [0, 1]
doc.close(True)
# Tests syntax: # Tests syntax:
# obj[0] = val # Replace by index # obj[0] = val # Replace by index
# For: # For:
...@@ -143,6 +153,8 @@ class TestXIndexReplace(CollectionsTestBase): ...@@ -143,6 +153,8 @@ class TestXIndexReplace(CollectionsTestBase):
with self.assertRaises(TypeError): with self.assertRaises(TypeError):
index.LevelParagraphStyles[0] = {'a': 'b'} index.LevelParagraphStyles[0] = {'a': 'b'}
doc.close(True)
# Tests syntax: # Tests syntax:
# obj[0] = val # Replace by index # obj[0] = val # Replace by index
# For: # For:
...@@ -156,6 +168,8 @@ class TestXIndexReplace(CollectionsTestBase): ...@@ -156,6 +168,8 @@ class TestXIndexReplace(CollectionsTestBase):
with self.assertRaises(TypeError): with self.assertRaises(TypeError):
index.LevelParagraphStyles[0] = ('Caption', ()) index.LevelParagraphStyles[0] = ('Caption', ())
doc.close(True)
# Tests syntax: # Tests syntax:
# obj[2:4] = val1,val2 # Replace by slice # obj[2:4] = val1,val2 # Replace by slice
# For: # For:
...@@ -177,6 +191,7 @@ class TestXIndexReplace(CollectionsTestBase): ...@@ -177,6 +191,7 @@ class TestXIndexReplace(CollectionsTestBase):
if (len(expected) != 10): if (len(expected) != 10):
expected = ValueError() expected = ValueError()
self.assignValuesTestFixture(doc, key, assign, expected) self.assignValuesTestFixture(doc, key, assign, expected)
doc.close(True)
# Tests syntax: # Tests syntax:
# obj[2:4] = val1,val2 # Replace by slice # obj[2:4] = val1,val2 # Replace by slice
...@@ -194,6 +209,8 @@ class TestXIndexReplace(CollectionsTestBase): ...@@ -194,6 +209,8 @@ class TestXIndexReplace(CollectionsTestBase):
12.34 12.34
) )
doc.close(True)
# Tests syntax: # Tests syntax:
# obj[0:3:2] = val1,val2 # Replace by extended slice # obj[0:3:2] = val1,val2 # Replace by extended slice
# For: # For:
...@@ -214,6 +231,7 @@ class TestXIndexReplace(CollectionsTestBase): ...@@ -214,6 +231,7 @@ class TestXIndexReplace(CollectionsTestBase):
except Exception as e: except Exception as e:
expected = e expected = e
self.assignValuesTestFixture(doc, key, assign, expected) self.assignValuesTestFixture(doc, key, assign, expected)
doc.close(True)
if __name__ == '__main__': if __name__ == '__main__':
......
...@@ -35,6 +35,8 @@ class TestXNameAccess(CollectionsTestBase): ...@@ -35,6 +35,8 @@ class TestXNameAccess(CollectionsTestBase):
# Then # Then
self.assertEqual(2, length) self.assertEqual(2, length)
drw.close(True)
# Tests syntax: # Tests syntax:
# val = obj[key] # Access by key # val = obj[key] # Access by key
# For: # For:
...@@ -50,6 +52,8 @@ class TestXNameAccess(CollectionsTestBase): ...@@ -50,6 +52,8 @@ class TestXNameAccess(CollectionsTestBase):
# Then # Then
self.assertEqual('foo', link.getName()) self.assertEqual('foo', link.getName())
drw.close(True)
# Tests syntax: # Tests syntax:
# val = obj[key] # Access by key # val = obj[key] # Access by key
# For: # For:
...@@ -62,6 +66,8 @@ class TestXNameAccess(CollectionsTestBase): ...@@ -62,6 +66,8 @@ class TestXNameAccess(CollectionsTestBase):
with self.assertRaises(KeyError): with self.assertRaises(KeyError):
link = drw.Links['foo'] link = drw.Links['foo']
drw.close(True)
# Tests syntax: # Tests syntax:
# val = obj[key] # Access by key # val = obj[key] # Access by key
# For: # For:
...@@ -74,6 +80,8 @@ class TestXNameAccess(CollectionsTestBase): ...@@ -74,6 +80,8 @@ class TestXNameAccess(CollectionsTestBase):
with self.assertRaises(TypeError): with self.assertRaises(TypeError):
link = drw.Links[None] link = drw.Links[None]
drw.close(True)
# Tests syntax: # Tests syntax:
# val = obj[key] # Access by key # val = obj[key] # Access by key
# For: # For:
...@@ -86,6 +94,8 @@ class TestXNameAccess(CollectionsTestBase): ...@@ -86,6 +94,8 @@ class TestXNameAccess(CollectionsTestBase):
with self.assertRaises(TypeError): with self.assertRaises(TypeError):
link = drw.Links[12.34] link = drw.Links[12.34]
drw.close(True)
# Tests syntax: # Tests syntax:
# val = obj[key] # Access by key # val = obj[key] # Access by key
# For: # For:
...@@ -98,6 +108,8 @@ class TestXNameAccess(CollectionsTestBase): ...@@ -98,6 +108,8 @@ class TestXNameAccess(CollectionsTestBase):
with self.assertRaises(TypeError): with self.assertRaises(TypeError):
link = drw.Links[(1, 2)] link = drw.Links[(1, 2)]
drw.close(True)
# Tests syntax: # Tests syntax:
# val = obj[key] # Access by key # val = obj[key] # Access by key
# For: # For:
...@@ -110,6 +122,8 @@ class TestXNameAccess(CollectionsTestBase): ...@@ -110,6 +122,8 @@ class TestXNameAccess(CollectionsTestBase):
with self.assertRaises(TypeError): with self.assertRaises(TypeError):
link = drw.Links[[1, 2]] link = drw.Links[[1, 2]]
drw.close(True)
# Tests syntax: # Tests syntax:
# val = obj[key] # Access by key # val = obj[key] # Access by key
# For: # For:
...@@ -122,6 +136,8 @@ class TestXNameAccess(CollectionsTestBase): ...@@ -122,6 +136,8 @@ class TestXNameAccess(CollectionsTestBase):
with self.assertRaises(TypeError): with self.assertRaises(TypeError):
link = drw.Links[{'a': 'b'}] link = drw.Links[{'a': 'b'}]
drw.close(True)
# Tests syntax: # Tests syntax:
# if key in obj: ... # Test key presence # if key in obj: ... # Test key presence
# For: # For:
...@@ -137,6 +153,8 @@ class TestXNameAccess(CollectionsTestBase): ...@@ -137,6 +153,8 @@ class TestXNameAccess(CollectionsTestBase):
# Then # Then
self.assertTrue(present) self.assertTrue(present)
drw.close(True)
# Tests syntax: # Tests syntax:
# for key in obj: ... # Implicit iterator (keys) # for key in obj: ... # Implicit iterator (keys)
# For: # For:
...@@ -157,6 +175,8 @@ class TestXNameAccess(CollectionsTestBase): ...@@ -157,6 +175,8 @@ class TestXNameAccess(CollectionsTestBase):
# Then # Then
self.assertEqual(['foo0', 'foo1'], read_links) self.assertEqual(['foo0', 'foo1'], read_links)
drw.close(True)
# Tests syntax: # Tests syntax:
# itr = iter(obj) # Named iterator (keys) # itr = iter(obj) # Named iterator (keys)
# For: # For:
...@@ -174,6 +194,8 @@ class TestXNameAccess(CollectionsTestBase): ...@@ -174,6 +194,8 @@ class TestXNameAccess(CollectionsTestBase):
with self.assertRaises(StopIteration): with self.assertRaises(StopIteration):
next(itr) next(itr)
drw.close(True)
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()
......
...@@ -41,6 +41,8 @@ class TestXNameContainer(CollectionsTestBase): ...@@ -41,6 +41,8 @@ class TestXNameContainer(CollectionsTestBase):
# Then # Then
self.assertEqual(1, len(ranges.ElementNames)) self.assertEqual(1, len(ranges.ElementNames))
spr.close(True)
# Tests syntax: # Tests syntax:
# obj[key] = val # Insert by key # obj[key] = val # Insert by key
# For: # For:
...@@ -55,6 +57,8 @@ class TestXNameContainer(CollectionsTestBase): ...@@ -55,6 +57,8 @@ class TestXNameContainer(CollectionsTestBase):
with self.assertRaises(TypeError): with self.assertRaises(TypeError):
ranges[12.34] = new_range ranges[12.34] = new_range
spr.close(True)
# Tests syntax: # Tests syntax:
# obj[key] = val # Replace by key # obj[key] = val # Replace by key
def test_XNameContainer_ReplaceName(self): def test_XNameContainer_ReplaceName(self):
...@@ -73,6 +77,8 @@ class TestXNameContainer(CollectionsTestBase): ...@@ -73,6 +77,8 @@ class TestXNameContainer(CollectionsTestBase):
read_range = ranges['foo'] read_range = ranges['foo']
self.assertEqual(6, read_range.CellAddress.Column) self.assertEqual(6, read_range.CellAddress.Column)
spr.close(True)
# Tests syntax: # Tests syntax:
# del obj[key] # Delete by key # del obj[key] # Delete by key
# For: # For:
...@@ -89,6 +95,8 @@ class TestXNameContainer(CollectionsTestBase): ...@@ -89,6 +95,8 @@ class TestXNameContainer(CollectionsTestBase):
self.assertEqual(1, len(spr.Sheets)) self.assertEqual(1, len(spr.Sheets))
self.assertFalse('foo' in spr.Sheets) self.assertFalse('foo' in spr.Sheets)
spr.close(True)
# Tests syntax: # Tests syntax:
# del obj[key] # Delete by key # del obj[key] # Delete by key
# For: # For:
...@@ -101,6 +109,8 @@ class TestXNameContainer(CollectionsTestBase): ...@@ -101,6 +109,8 @@ class TestXNameContainer(CollectionsTestBase):
with self.assertRaises(KeyError): with self.assertRaises(KeyError):
del spr.Sheets['foo'] del spr.Sheets['foo']
spr.close(True)
# Tests syntax: # Tests syntax:
# del obj[key] # Delete by key # del obj[key] # Delete by key
# For: # For:
...@@ -113,6 +123,8 @@ class TestXNameContainer(CollectionsTestBase): ...@@ -113,6 +123,8 @@ class TestXNameContainer(CollectionsTestBase):
with self.assertRaises(TypeError): with self.assertRaises(TypeError):
del spr.Sheets[12.34] del spr.Sheets[12.34]
spr.close(True)
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()
......
...@@ -40,6 +40,8 @@ class TestXNameReplace(CollectionsTestBase): ...@@ -40,6 +40,8 @@ class TestXNameReplace(CollectionsTestBase):
on_save = [p.Value for p in doc.Events['OnSave'] if p.Name == 'Script'][0] on_save = [p.Value for p in doc.Events['OnSave'] if p.Name == 'Script'][0]
self.assertEqual(getScriptName(), on_save) self.assertEqual(getScriptName(), on_save)
doc.close(True)
# Tests syntax: # Tests syntax:
# obj[key] = val # Replace by key # obj[key] = val # Replace by key
# For: # For:
...@@ -53,6 +55,8 @@ class TestXNameReplace(CollectionsTestBase): ...@@ -53,6 +55,8 @@ class TestXNameReplace(CollectionsTestBase):
with self.assertRaises(KeyError): with self.assertRaises(KeyError):
doc.Events['qqqqq'] = event_properties doc.Events['qqqqq'] = event_properties
doc.close(True)
# Tests syntax: # Tests syntax:
# obj[key] = val # Replace by key # obj[key] = val # Replace by key
# For: # For:
...@@ -66,6 +70,8 @@ class TestXNameReplace(CollectionsTestBase): ...@@ -66,6 +70,8 @@ class TestXNameReplace(CollectionsTestBase):
with self.assertRaises(TypeError): with self.assertRaises(TypeError):
doc.Events[12.34] = event_properties doc.Events[12.34] = event_properties
doc.close(True)
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()
......
...@@ -32,6 +32,8 @@ class TestMisc(CollectionsTestBase): ...@@ -32,6 +32,8 @@ class TestMisc(CollectionsTestBase):
for val in doc.UIConfigurationManager: for val in doc.UIConfigurationManager:
pass pass
doc.close(True)
# Tests syntax: # Tests syntax:
# if val in itr: ... # Test value presence # if val in itr: ... # Test value presence
# For: # For:
...@@ -44,6 +46,8 @@ class TestMisc(CollectionsTestBase): ...@@ -44,6 +46,8 @@ class TestMisc(CollectionsTestBase):
with self.assertRaises(TypeError): with self.assertRaises(TypeError):
foo = "bar" in doc.UIConfigurationManager foo = "bar" in doc.UIConfigurationManager
doc.close(True)
# Tests syntax: # Tests syntax:
# num = len(obj) # Number of elements # num = len(obj) # Number of elements
# For: # For:
...@@ -56,6 +60,8 @@ class TestMisc(CollectionsTestBase): ...@@ -56,6 +60,8 @@ class TestMisc(CollectionsTestBase):
with self.assertRaises(TypeError): with self.assertRaises(TypeError):
len(doc.UIConfigurationManager) len(doc.UIConfigurationManager)
doc.close(True)
# Tests syntax: # Tests syntax:
# val = obj[0] # Access by index # val = obj[0] # Access by index
# For: # For:
...@@ -68,6 +74,8 @@ class TestMisc(CollectionsTestBase): ...@@ -68,6 +74,8 @@ class TestMisc(CollectionsTestBase):
with self.assertRaises(TypeError): with self.assertRaises(TypeError):
doc.UIConfigurationManager[0] doc.UIConfigurationManager[0]
doc.close(True)
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()
......
...@@ -41,6 +41,8 @@ class TestMixedNameIndex(CollectionsTestBase): ...@@ -41,6 +41,8 @@ class TestMixedNameIndex(CollectionsTestBase):
self.assertEqual('foo', table_by_index.Name) self.assertEqual('foo', table_by_index.Name)
self.assertEqual(table_by_name, table_by_index) self.assertEqual(table_by_name, table_by_index)
doc.close(True)
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()
......
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
#include "pyuno_impl.hxx" #include "pyuno_impl.hxx"
#include <cassert>
#include <unordered_map> #include <unordered_map>
#include <utility> #include <utility>
...@@ -318,12 +319,22 @@ static PyObject* getComponentContext( ...@@ -318,12 +319,22 @@ static PyObject* getComponentContext(
return ret.getAcquired(); return ret.getAcquired();
} }
// While pyuno.private_initTestEnvironment is called from individual Python tests (e.g., from
// UnoInProcess in unotest/source/python/org/libreoffice/unotest.py, which makes sure to call it
// only once), pyuno.private_deinitTestEnvironment is called centrally from
// unotest/source/python/org/libreoffice/unittest.py at the end of every PythonTest (to DeInitVCL
// exactly once near the end of the process, if InitVCL has ever been called via
// pyuno.private_initTestEnvironment):
static osl::Module * testModule = nullptr;
static PyObject* initTestEnvironment( static PyObject* initTestEnvironment(
SAL_UNUSED_PARAMETER PyObject*, SAL_UNUSED_PARAMETER PyObject*) SAL_UNUSED_PARAMETER PyObject*, SAL_UNUSED_PARAMETER PyObject*)
{ {
// this tries to bootstrap enough of the soffice from python to run // this tries to bootstrap enough of the soffice from python to run
// unit tests, which is only possible indirectly because pyuno is URE // unit tests, which is only possible indirectly because pyuno is URE
// so load "test" library and invoke a function there to do the work // so load "test" library and invoke a function there to do the work
assert(testModule == nullptr);
try try
{ {
PyObject *const ctx(getComponentContext(nullptr, nullptr)); PyObject *const ctx(getComponentContext(nullptr, nullptr));
...@@ -353,6 +364,7 @@ static PyObject* initTestEnvironment( ...@@ -353,6 +364,7 @@ static PyObject* initTestEnvironment(
mod.getFunctionSymbol("test_init")); mod.getFunctionSymbol("test_init"));
if (!pFunc) { abort(); } if (!pFunc) { abort(); }
reinterpret_cast<void (SAL_CALL *)(XMultiServiceFactory*)>(pFunc)(xMSF.get()); reinterpret_cast<void (SAL_CALL *)(XMultiServiceFactory*)>(pFunc)(xMSF.get());
testModule = &mod;
} }
catch (const css::uno::Exception &) catch (const css::uno::Exception &)
{ {
...@@ -361,6 +373,26 @@ static PyObject* initTestEnvironment( ...@@ -361,6 +373,26 @@ static PyObject* initTestEnvironment(
return Py_None; return Py_None;
} }
static PyObject* deinitTestEnvironment(
SAL_UNUSED_PARAMETER PyObject*, SAL_UNUSED_PARAMETER PyObject*)
{
if (testModule != nullptr)
{
try
{
oslGenericFunction const pFunc(
testModule->getFunctionSymbol("test_deinit"));
if (!pFunc) { abort(); }
reinterpret_cast<void (SAL_CALL *)()>(pFunc)();
}
catch (const css::uno::Exception &)
{
abort();
}
}
return Py_None;
}
PyObject * extractOneStringArg( PyObject *args, char const *funcName ) PyObject * extractOneStringArg( PyObject *args, char const *funcName )
{ {
if( !PyTuple_Check( args ) || PyTuple_Size( args) != 1 ) if( !PyTuple_Check( args ) || PyTuple_Size( args) != 1 )
...@@ -843,6 +875,7 @@ static PyObject *sal_debug( ...@@ -843,6 +875,7 @@ static PyObject *sal_debug(
struct PyMethodDef PyUNOModule_methods [] = struct PyMethodDef PyUNOModule_methods [] =
{ {
{"private_initTestEnvironment", initTestEnvironment, METH_VARARGS, nullptr}, {"private_initTestEnvironment", initTestEnvironment, METH_VARARGS, nullptr},
{"private_deinitTestEnvironment", deinitTestEnvironment, METH_VARARGS, nullptr},
{"getComponentContext", getComponentContext, METH_VARARGS, nullptr}, {"getComponentContext", getComponentContext, METH_VARARGS, nullptr},
{"_createUnoStructHelper", reinterpret_cast<PyCFunction>(createUnoStructHelper), METH_VARARGS | METH_KEYWORDS, nullptr}, {"_createUnoStructHelper", reinterpret_cast<PyCFunction>(createUnoStructHelper), METH_VARARGS | METH_KEYWORDS, nullptr},
{"getTypeByName", getTypeByName, METH_VARARGS, nullptr}, {"getTypeByName", getTypeByName, METH_VARARGS, nullptr},
......
...@@ -24,7 +24,6 @@ class CheckSidebar(unittest.TestCase): ...@@ -24,7 +24,6 @@ class CheckSidebar(unittest.TestCase):
def setUpClass(cls): def setUpClass(cls):
cls._uno = UnoInProcess() cls._uno = UnoInProcess()
cls._uno.setUp() cls._uno.setUp()
cls._xDoc = cls._uno.openEmptyDoc( url = "private:factory/scalc", bHidden = False, bReadOnly = False)
@classmethod @classmethod
def tearDownClass(cls): def tearDownClass(cls):
...@@ -32,7 +31,7 @@ class CheckSidebar(unittest.TestCase): ...@@ -32,7 +31,7 @@ class CheckSidebar(unittest.TestCase):
def test_check_sidebar(self): def test_check_sidebar(self):
xDoc = self.__class__._xDoc xDoc = self.__class__._uno.openEmptyDoc( url = "private:factory/scalc", bHidden = False, bReadOnly = False)
xController = xDoc.getCurrentController() xController = xDoc.getCurrentController()
xSidebar = xController.getSidebar() xSidebar = xController.getSidebar()
......
...@@ -19,7 +19,6 @@ class CheckSidebarRegistry(unittest.TestCase): ...@@ -19,7 +19,6 @@ class CheckSidebarRegistry(unittest.TestCase):
def setUpClass(cls): def setUpClass(cls):
cls._uno = UnoInProcess() cls._uno = UnoInProcess()
cls._uno.setUp() cls._uno.setUp()
cls._xDoc = cls._uno.openEmptyDoc( url = "private:factory/scalc", bHidden = False, bReadOnly = False)
@classmethod @classmethod
def tearDownClass(cls): def tearDownClass(cls):
......
...@@ -21,7 +21,7 @@ gb_PythonTest_EXECUTABLE_GDB := $(PYTHON_FOR_BUILD) ...@@ -21,7 +21,7 @@ gb_PythonTest_EXECUTABLE_GDB := $(PYTHON_FOR_BUILD)
gb_PythonTest_DEPS := gb_PythonTest_DEPS :=
endif endif
gb_PythonTest_COMMAND := $(gb_PythonTest_EXECUTABLE) -m unittest gb_PythonTest_COMMAND := $(gb_PythonTest_EXECUTABLE) -m org.libreoffice.unittest
.PHONY : $(call gb_PythonTest_get_clean_target,%) .PHONY : $(call gb_PythonTest_get_clean_target,%)
$(call gb_PythonTest_get_clean_target,%) : $(call gb_PythonTest_get_clean_target,%) :
...@@ -31,7 +31,10 @@ $(call gb_PythonTest_get_clean_target,%) : ...@@ -31,7 +31,10 @@ $(call gb_PythonTest_get_clean_target,%) :
ifneq ($(DISABLE_PYTHON),TRUE) ifneq ($(DISABLE_PYTHON),TRUE)
.PHONY : $(call gb_PythonTest_get_target,%) .PHONY : $(call gb_PythonTest_get_target,%)
$(call gb_PythonTest_get_target,%) :| $(gb_PythonTest_DEPS) $(call gb_PythonTest_get_target,%) :\
$(call gb_Library_get_target,pyuno) \
$(if $(filter-out WNT,$(OS)),$(call gb_Library_get_target,pyuno_wrapper)) \
| $(gb_PythonTest_DEPS)
ifneq ($(gb_SUPPRESS_TESTS),) ifneq ($(gb_SUPPRESS_TESTS),)
@true @true
else else
......
...@@ -47,6 +47,10 @@ class CheckBookmarks(unittest.TestCase): ...@@ -47,6 +47,10 @@ class CheckBookmarks(unittest.TestCase):
@classmethod @classmethod
def tearDownClass(cls): def tearDownClass(cls):
cls._uno.tearDown() cls._uno.tearDown()
# HACK in case cls._xDoc holds a UNO proxy to an SwXTextDocument (whose dtor calls
# Application::GetSolarMutex via sw::UnoImplPtrDeleter), which would potentially only be
# garbage-collected after VCL has already been deinitialized:
cls._xDoc = None
def test_bookmarks(self): def test_bookmarks(self):
self.xDoc = self.__class__._xDoc self.xDoc = self.__class__._xDoc
......
...@@ -27,7 +27,6 @@ class CheckChangeColor(unittest.TestCase): ...@@ -27,7 +27,6 @@ class CheckChangeColor(unittest.TestCase):
def setUpClass(cls): def setUpClass(cls):
cls._uno = UnoInProcess() cls._uno = UnoInProcess()
cls._uno.setUp() cls._uno.setUp()
cls._xEmptyDoc = cls._uno.openEmptyWriterDoc()
cls.RED = 0xFF0000 cls.RED = 0xFF0000
cls.BLUE = 0x0000FF cls.BLUE = 0x0000FF
cls.GREEN = 0x008000 cls.GREEN = 0x008000
......
...@@ -46,6 +46,10 @@ class CheckCrossReferences(unittest.TestCase): ...@@ -46,6 +46,10 @@ class CheckCrossReferences(unittest.TestCase):
@classmethod @classmethod
def tearDownClass(cls): def tearDownClass(cls):
cls._uno.tearDown() cls._uno.tearDown()
# HACK in case cls.document holds a UNO proxy to an SwXTextDocument (whose dtor calls
# Application::GetSolarMutex via sw::UnoImplPtrDeleter), which would potentially only be
# garbage-collected after VCL has already been deinitialized:
cls.document = None
def getNextField(self): def getNextField(self):
while True: while True:
......
...@@ -17,8 +17,6 @@ class CheckFields(unittest.TestCase): ...@@ -17,8 +17,6 @@ class CheckFields(unittest.TestCase):
def setUpClass(cls): def setUpClass(cls):
cls._uno = UnoInProcess() cls._uno = UnoInProcess()
cls._uno.setUp() cls._uno.setUp()
cls._xDoc = cls._uno.openTemplateFromTDOC("fdo39694.ott")
cls._xEmptyDoc = cls._uno.openEmptyWriterDoc()
@classmethod @classmethod
def tearDownClass(cls): def tearDownClass(cls):
...@@ -26,7 +24,7 @@ class CheckFields(unittest.TestCase): ...@@ -26,7 +24,7 @@ class CheckFields(unittest.TestCase):
def test_fdo39694_load(self): def test_fdo39694_load(self):
placeholders = ["<Kadr1>", "<Kadr2>", "<Kadr3>", "<Kadr4>", "<Pnname>", "<Pvname>", "<Pgeboren>"] placeholders = ["<Kadr1>", "<Kadr2>", "<Kadr3>", "<Kadr4>", "<Pnname>", "<Pvname>", "<Pgeboren>"]
xDoc = self.__class__._xDoc xDoc = self.__class__._uno.openTemplateFromTDOC("fdo39694.ott")
xEnumerationAccess = xDoc.getTextFields() xEnumerationAccess = xDoc.getTextFields()
xFieldEnum = xEnumerationAccess.createEnumeration() xFieldEnum = xEnumerationAccess.createEnumeration()
for xField in xFieldEnum: for xField in xFieldEnum:
...@@ -35,9 +33,10 @@ class CheckFields(unittest.TestCase): ...@@ -35,9 +33,10 @@ class CheckFields(unittest.TestCase):
read_content = xAnchor.getString() read_content = xAnchor.getString()
self.assertTrue(read_content in placeholders, self.assertTrue(read_content in placeholders,
"field %s is not contained: " % read_content) "field %s is not contained: " % read_content)
xDoc.close(True)
def test_fdo42073(self): def test_fdo42073(self):
xDoc = self.__class__._xEmptyDoc xDoc = self.__class__._uno.openEmptyWriterDoc()
xBodyText = xDoc.getText() xBodyText = xDoc.getText()
xCursor = xBodyText.createTextCursor() xCursor = xBodyText.createTextCursor()
xTextField = xDoc.createInstance("com.sun.star.text.TextField.Input") xTextField = xDoc.createInstance("com.sun.star.text.TextField.Input")
...@@ -48,6 +47,7 @@ class CheckFields(unittest.TestCase): ...@@ -48,6 +47,7 @@ class CheckFields(unittest.TestCase):
xTextField.setPropertyValue("Content", content) xTextField.setPropertyValue("Content", content)
read_content = xTextField.getPropertyValue("Content") read_content = xTextField.getPropertyValue("Content")
self.assertEqual(content, read_content) self.assertEqual(content, read_content)
xDoc.close(True)
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()
...@@ -26,18 +26,18 @@ class CheckFlies(unittest.TestCase): ...@@ -26,18 +26,18 @@ class CheckFlies(unittest.TestCase):
def setUpClass(cls): def setUpClass(cls):
cls._uno = UnoInProcess() cls._uno = UnoInProcess()
cls._uno.setUp() cls._uno.setUp()
cls.document = cls._uno.openDocFromTDOC("CheckFlies.odt")
@classmethod @classmethod
def tearDownClass(cls): def tearDownClass(cls):
cls._uno.tearDown() cls._uno.tearDown()
def test_checkFlies(self): def test_checkFlies(self):
xTFS = self.__class__.document document = self.__class__._uno.openDocFromTDOC("CheckFlies.odt")
xTFS = document
self.checkTextFrames(xTFS) self.checkTextFrames(xTFS)
xTGOS = self.__class__.document xTGOS = document
self.checkGraphicFrames(xTGOS) self.checkGraphicFrames(xTGOS)
xTEOS = self.__class__.document xTEOS = document
self.checkEmbeddedFrames(xTEOS) self.checkEmbeddedFrames(xTEOS)
def checkEmbeddedFrames(self, xTGOS): def checkEmbeddedFrames(self, xTGOS):
......
...@@ -34,7 +34,6 @@ class CheckIndexedPropertyValues(unittest.TestCase): ...@@ -34,7 +34,6 @@ class CheckIndexedPropertyValues(unittest.TestCase):
cls._uno = UnoInProcess() cls._uno = UnoInProcess()
cls._uno.setUp() cls._uno.setUp()
cls.xContext = cls._uno.getContext() cls.xContext = cls._uno.getContext()
cls.xDoc = cls._uno.openEmptyWriterDoc()
@classmethod @classmethod
def tearDownClass(cls): def tearDownClass(cls):
......
...@@ -36,7 +36,6 @@ class CheckNamedPropertyValues(unittest.TestCase): ...@@ -36,7 +36,6 @@ class CheckNamedPropertyValues(unittest.TestCase):
cls._uno = UnoInProcess() cls._uno = UnoInProcess()
cls._uno.setUp() cls._uno.setUp()
cls.xContext = cls._uno.getContext() cls.xContext = cls._uno.getContext()
cls.xDoc = cls._uno.openEmptyWriterDoc()
@classmethod @classmethod
def tearDownClass(cls): def tearDownClass(cls):
......
...@@ -583,6 +583,8 @@ class CheckTable(unittest.TestCase): ...@@ -583,6 +583,8 @@ class CheckTable(unittest.TestCase):
xCellRangeString = xChartDataProvider.convertRangeFromXML("Table1.$A$1:.$C$3") xCellRangeString = xChartDataProvider.convertRangeFromXML("Table1.$A$1:.$C$3")
self.assertEqual("Table1.A1:C3", xCellRangeString) self.assertEqual("Table1.A1:C3", xCellRangeString)
xDoc.dispose()
def test_splitRangeHorizontal(self): def test_splitRangeHorizontal(self):
xDoc = CheckTable._uno.openEmptyWriterDoc() xDoc = CheckTable._uno.openEmptyWriterDoc()
xTable = xDoc.createInstance("com.sun.star.text.TextTable") xTable = xDoc.createInstance("com.sun.star.text.TextTable")
...@@ -600,6 +602,7 @@ class CheckTable(unittest.TestCase): ...@@ -600,6 +602,7 @@ class CheckTable(unittest.TestCase):
self.assertTrue(math.isnan(xTable.Data[1][1])) self.assertTrue(math.isnan(xTable.Data[1][1]))
self.assertTrue(math.isnan(xTable.Data[2][0])) self.assertTrue(math.isnan(xTable.Data[2][0]))
self.assertTrue(math.isnan(xTable.Data[2][1])) self.assertTrue(math.isnan(xTable.Data[2][1]))
xDoc.dispose()
def test_mergeRangeHorizontal(self): def test_mergeRangeHorizontal(self):
xDoc = CheckTable._uno.openEmptyWriterDoc() xDoc = CheckTable._uno.openEmptyWriterDoc()
...@@ -618,6 +621,7 @@ class CheckTable(unittest.TestCase): ...@@ -618,6 +621,7 @@ class CheckTable(unittest.TestCase):
self.assertEqual(xTable.Data[1][1], float(5)) self.assertEqual(xTable.Data[1][1], float(5))
self.assertEqual(xTable.Data[1][2], float(6)) self.assertEqual(xTable.Data[1][2], float(6))
self.assertEqual(xTable.Data[2], (float(7), float(8), float(9))) self.assertEqual(xTable.Data[2], (float(7), float(8), float(9)))
xDoc.dispose()
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()
......
...@@ -22,6 +22,10 @@ class TestGetExpression(unittest.TestCase): ...@@ -22,6 +22,10 @@ class TestGetExpression(unittest.TestCase):
@classmethod @classmethod
def tearDownClass(cls): def tearDownClass(cls):
cls._uno.tearDown() cls._uno.tearDown()
# HACK in case cls._xDoc holds a UNO proxy to an SwXTextDocument (whose dtor calls
# Application::GetSolarMutex via sw::UnoImplPtrDeleter), which would potentially only be
# garbage-collected after VCL has already been deinitialized:
cls._xDoc = None
def test_get_expression(self): def test_get_expression(self):
self.__class__._uno.checkProperties( self.__class__._uno.checkProperties(
......
...@@ -18,15 +18,15 @@ class TestSetExpression(unittest.TestCase): ...@@ -18,15 +18,15 @@ class TestSetExpression(unittest.TestCase):
def setUpClass(cls): def setUpClass(cls):
cls._uno = UnoInProcess() cls._uno = UnoInProcess()
cls._uno.setUp() cls._uno.setUp()
cls._xDoc = cls._uno.openEmptyWriterDoc()
@classmethod @classmethod
def tearDownClass(cls): def tearDownClass(cls):
cls._uno.tearDown() cls._uno.tearDown()
def test_set_expression(self): def test_set_expression(self):
xDoc = self.__class__._uno.openEmptyWriterDoc()
self.__class__._uno.checkProperties( self.__class__._uno.checkProperties(
self.__class__._xDoc.createInstance("com.sun.star.text.textfield.SetExpression"), xDoc.createInstance("com.sun.star.text.textfield.SetExpression"),
{"NumberingType": 0, {"NumberingType": 0,
"Content": "foo", "Content": "foo",
"CurrentPresentation": "bar", "CurrentPresentation": "bar",
......
...@@ -934,6 +934,11 @@ class TextPortionEnumerationTest(unittest.TestCase): ...@@ -934,6 +934,11 @@ class TextPortionEnumerationTest(unittest.TestCase):
@classmethod @classmethod
def tearDownClass(cls): def tearDownClass(cls):
cls.xDoc.close(True) cls.xDoc.close(True)
cls._uno.tearDown()
# HACK in case cls.xDoc holds a UNO proxy to an SwXTextDocument (whose dtor calls
# Application::GetSolarMutex via sw::UnoImplPtrDeleter), which would potentially only be
# garbage-collected after VCL has already been deinitialized:
cls.xDoc = None
def test_text(self): def test_text(self):
root = TreeNode() root = TreeNode()
......
...@@ -19,7 +19,6 @@ class TestVarFields(unittest.TestCase): ...@@ -19,7 +19,6 @@ class TestVarFields(unittest.TestCase):
def setUpClass(cls): def setUpClass(cls):
cls._uno = UnoInProcess() cls._uno = UnoInProcess()
cls._uno.setUp() cls._uno.setUp()
cls._xDoc = cls._uno.openEmptyWriterDoc()
@classmethod @classmethod
def tearDownClass(cls): def tearDownClass(cls):
...@@ -32,7 +31,7 @@ class TestVarFields(unittest.TestCase): ...@@ -32,7 +31,7 @@ class TestVarFields(unittest.TestCase):
sw/qa/complex/writer/VarFields.java sw/qa/complex/writer/VarFields.java
""" """
xDoc = self.__class__._xDoc xDoc = self.__class__._uno.openEmptyWriterDoc()
xBodyText = xDoc.getText() xBodyText = xDoc.getText()
xCursor = xBodyText.createTextCursor() xCursor = xBodyText.createTextCursor()
# 0. create text field # 0. create text field
......
...@@ -99,6 +99,12 @@ SAL_DLLPUBLIC_EXPORT void test_init(lang::XMultiServiceFactory *pFactory) ...@@ -99,6 +99,12 @@ SAL_DLLPUBLIC_EXPORT void test_init(lang::XMultiServiceFactory *pFactory)
catch (...) { abort(); } catch (...) { abort(); }
} }
// this is called from pyuno
SAL_DLLPUBLIC_EXPORT void test_deinit()
{
DeInitVCL();
}
} // extern "C" } // extern "C"
void test::BootstrapFixture::setUp() void test::BootstrapFixture::setUp()
......
# -*- tab-width: 4; indent-tabs-mode: nil; py-indent-offset: 4 -*-
#
# This file is part of the LibreOffice project.
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#
import gc
import pyuno
import unittest
class LoTestResult(unittest.TextTestResult):
def stopTestRun(self):
# HACK calling gc.collect() to get rid of as many still existing UNO proxies to
# SwXTextDocument and friends as possible; those C++ classes' dtors call
# Application::GetSolarMutex via sw::UnoImplPtrDeleter, so the dtors must be called before
# DeInitVCL in the call to pyuno.private_deinitTestEnvironment(); any remainging proxies
# that are still referenced (UnoInProcess' self.xDoc in
# unotest/source/python/org/libreoffice/unotest.py, or per-class variables in the various
# PythonTests) need to be individually released (each marked as "HACK" in the code):
gc.collect()
pyuno.private_deinitTestEnvironment()
if __name__ == '__main__':
unittest.main(module=None, testRunner=unittest.TextTestRunner(resultclass=LoTestResult))
# vim: set shiftwidth=4 softtabstop=4 expandtab:
...@@ -246,7 +246,12 @@ class UnoInProcess: ...@@ -246,7 +246,12 @@ class UnoInProcess:
def postTest(self): def postTest(self):
assert(self.xContext) assert(self.xContext)
def tearDown(self): def tearDown(self):
self.xDoc.close(True) if hasattr(self, 'xDoc'):
self.xDoc.close(True)
# HACK in case self.xDoc holds a UNO proxy to an SwXTextDocument (whose dtor calls
# Application::GetSolarMutex via sw::UnoImplPtrDeleter), which would potentially only be
# garbage-collected after VCL has already been deinitialized:
self.xDoc = None
def simpleInvoke(connection, test): def simpleInvoke(connection, test):
try: try:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment