diff options
author | slideon <adamkasztenny@gmail.com> | 2016-03-26 21:57:38 -0400 |
---|---|---|
committer | jan iversen <jani@documentfoundation.org> | 2016-03-30 06:57:39 +0000 |
commit | c19219d5f49b305d31ad251bc87a87b0109c2402 (patch) | |
tree | 252a3d38430db99df872cb347fff0feb5a8686af /sw/qa/python | |
parent | 7b3dbf6cd1bad9a1cc94221952ac6cc54280b7d2 (diff) |
tdf#97361 Refactor load_save_test
Make new helper functions, minor style cleanup in other tests
Change-Id: Ifb188fa8227cdd1a1a5af88e692315c5f93da67d
Reviewed-on: https://gerrit.libreoffice.org/23547
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: jan iversen <jani@documentfoundation.org>
Diffstat (limited to 'sw/qa/python')
-rw-r--r-- | sw/qa/python/check_styles.py | 26 | ||||
-rw-r--r-- | sw/qa/python/check_table.py | 108 | ||||
-rw-r--r-- | sw/qa/python/load_save_test.py | 13 |
3 files changed, 65 insertions, 82 deletions
diff --git a/sw/qa/python/check_styles.py b/sw/qa/python/check_styles.py index d30037272843..c1b63fb53e04 100644 --- a/sw/qa/python/check_styles.py +++ b/sw/qa/python/check_styles.py @@ -17,18 +17,22 @@ from com.sun.star.lang import IllegalArgumentException class CheckStyle(unittest.TestCase): _uno = None + @classmethod def setUpClass(cls): cls._uno = UnoInProcess() cls._uno.setUp() + @classmethod def tearDownClass(cls): cls._uno.tearDown() + def test_StyleFamilies(self): xDoc = CheckStyle._uno.openEmptyWriterDoc() xStyleFamilies = xDoc.StyleFamilies self.assertEqual(xStyleFamilies.ImplementationName, "SwXStyleFamilies") self.assertEqual(len(xStyleFamilies.SupportedServiceNames), 1) + for servicename in xStyleFamilies.SupportedServiceNames: self.assertIn(servicename, ["com.sun.star.style.StyleFamilies"] ) self.assertTrue(xStyleFamilies.supportsService(servicename)) @@ -36,39 +40,50 @@ class CheckStyle(unittest.TestCase): self.assertTrue(xStyleFamilies.hasElements()) self.assertRegex(str(xStyleFamilies.ElementType), "com\.sun\.star\.container\.XNameContainer") self.assertEqual(len(xStyleFamilies.ElementNames), 5) + for sFamilyname in xStyleFamilies.ElementNames: self.assertIn(sFamilyname, ["CharacterStyles", "ParagraphStyles", "PageStyles", "FrameStyles", "NumberingStyles"]) + with self.assertRaises(NoSuchElementException): xStyleFamilies.getByName("foobarbaz") xDoc.dispose() + def __test_StyleFamily(self, xFamily, vExpectedNames): self.assertEqual(xFamily.ImplementationName, "XStyleFamily") self.assertEqual(len(xFamily.SupportedServiceNames), 1) + for sServicename in xFamily.SupportedServiceNames: self.assertIn(sServicename, ["com.sun.star.style.StyleFamily"] ) self.assertTrue(xFamily.supportsService(sServicename)) self.assertFalse(xFamily.supportsService("foobarbaz")) self.assertTrue(xFamily.hasElements()) self.assertRegex(str(xFamily.ElementType), "com\.sun\.star\.style\.XStyle") + with self.assertRaises(NoSuchElementException): xFamily.getByName("foobarbaz") + with self.assertRaises(IndexOutOfBoundsException): xFamily.getByIndex(-1) + for sStylename in xFamily.ElementNames: self.assertTrue(xFamily.hasByName(sStylename)) self.assertEqual(xFamily[sStylename].ImplementationName, "SwXStyle") self.assertFalse(xFamily[sStylename].isUserDefined()) + vExpectedNames.sort() vNames = list(xFamily.ElementNames) vNames.sort() self.assertListEqual(vNames, vExpectedNames) + def __test_StyleFamilyIndex(self, xFamily, vExpectedNames): self.assertEqual(xFamily.Count, len(vExpectedNames)) + for nIndex in range(xFamily.Count): xStyle = xFamily.getByIndex(nIndex) self.assertEqual(xStyle.ImplementationName, "SwXStyle") self.assertIn(xStyle.Name, vExpectedNames) self.assertFalse(xStyle.isUserDefined()) + def __test_StyleFamilyInsert(self, xDoc, xFamily, vExpectedNames, sRightStyle, sWrongStyle): xRightStyle = xDoc.createInstance(sRightStyle) xRightStyle.Name = "RightStyleOld" @@ -86,18 +101,24 @@ class CheckStyle(unittest.TestCase): self.assertEqual(xRightStyle2.Name, "RightStyle") self.assertEqual(xFamily[xRightStyle2.Name], xRightStyle2) xFamily.removeByName(xRightStyle2.Name) + with self.assertRaises(NoSuchElementException): nope = xFamily.getByName("RightStyleOld") with self.assertRaises(NoSuchElementException): nope = xFamily.getByName("RightStyle") + with self.assertRaises(NoSuchElementException): nope = xFamily.getByName("RightStyle2Old") + with self.assertRaises(NoSuchElementException): nope = xFamily.getByName("RightStyle2") + with self.assertRaises(IllegalArgumentException): xFamily.insertByName("WrongStyle", xWrongStyle) + with self.assertRaises(NoSuchElementException): nope = xFamily.getByName("WrongStyle") + def test_CharacterFamily(self): xDoc = CheckStyle._uno.openEmptyWriterDoc() xCharStyles = xDoc.StyleFamilies["CharacterStyles"] @@ -106,6 +127,7 @@ class CheckStyle(unittest.TestCase): self.__test_StyleFamilyIndex(xCharStyles, vEmptyDocStyles) self.__test_StyleFamilyInsert(xDoc, xCharStyles, vEmptyDocStyles, "com.sun.star.style.CharacterStyle", "com.sun.star.style.ParagraphStyle") xDoc.dispose() + def test_ParagraphFamily(self): xDoc = CheckStyle._uno.openEmptyWriterDoc() xParaStyles = xDoc.StyleFamilies["ParagraphStyles"] @@ -114,6 +136,7 @@ class CheckStyle(unittest.TestCase): self.__test_StyleFamilyIndex(xParaStyles, vEmptyDocStyles) self.__test_StyleFamilyInsert(xDoc, xParaStyles, vEmptyDocStyles, "com.sun.star.style.ParagraphStyle", "com.sun.star.style.CharacterStyle") xDoc.dispose() + def test_PageFamily(self): xDoc = CheckStyle._uno.openEmptyWriterDoc() xPageStyles = xDoc.StyleFamilies["PageStyles"] @@ -122,6 +145,7 @@ class CheckStyle(unittest.TestCase): self.__test_StyleFamilyIndex(xPageStyles, vEmptyDocStyles) self.__test_StyleFamilyInsert(xDoc, xPageStyles, vEmptyDocStyles, "com.sun.star.style.PageStyle", "com.sun.star.style.CharacterStyle") xDoc.dispose() + def test_FrameFamily(self): xDoc = CheckStyle._uno.openEmptyWriterDoc() xFrameStyles = xDoc.StyleFamilies["FrameStyles"] @@ -130,6 +154,7 @@ class CheckStyle(unittest.TestCase): self.__test_StyleFamilyIndex(xFrameStyles, vEmptyDocStyles) self.__test_StyleFamilyInsert(xDoc, xFrameStyles, vEmptyDocStyles, "com.sun.star.style.FrameStyle", "com.sun.star.style.CharacterStyle") xDoc.dispose() + def test_NumberingFamily(self): xDoc = CheckStyle._uno.openEmptyWriterDoc() xNumberingStyles = xDoc.StyleFamilies["NumberingStyles"] @@ -138,6 +163,7 @@ class CheckStyle(unittest.TestCase): self.__test_StyleFamilyIndex(xNumberingStyles, vEmptyDocStyles) self.__test_StyleFamilyInsert(xDoc, xNumberingStyles, vEmptyDocStyles, "com.sun.star.style.NumberingStyle", "com.sun.star.style.CharacterStyle") xDoc.dispose() + if __name__ == '__main__': unittest.main() diff --git a/sw/qa/python/check_table.py b/sw/qa/python/check_table.py index 04b95ba18130..13283efdd165 100644 --- a/sw/qa/python/check_table.py +++ b/sw/qa/python/check_table.py @@ -11,7 +11,7 @@ from com.sun.star.util import XNumberFormats from com.sun.star.lang import Locale class CheckTable(unittest.TestCase): - _uno = None + def _fill_table(self, xTable): for x in range(3): for y in range(3): @@ -28,6 +28,21 @@ class CheckTable(unittest.TestCase): def tearDownClass(cls): cls._uno.tearDown() + def __test_borderAsserts(self, typeOfLine, lineValid): + self.assertTrue(lineValid) + self.assertEqual(0, typeOfLine.InnerLineWidth) + self.assertEqual(2, typeOfLine.OuterLineWidth) + self.assertEqual(0, typeOfLine.LineDistance) + self.assertEqual(0, typeOfLine.Color) + + def __test_borderAssertsWithLineStyle(self, typeOfLine, lineValid): + self.__test_borderAsserts(typeOfLine, lineValid) + self.assertEqual(SOLID, typeOfLine.LineStyle) + + def __test_borderDistance(self, border): + self.assertTrue(border.IsDistanceValid) + self.assertEqual(97, border.Distance) + def test_tableborder(self): xDoc = CheckTable._uno.openEmptyWriterDoc() # insert table @@ -39,41 +54,12 @@ class CheckTable(unittest.TestCase): border = xTable.getPropertyValue("TableBorder") - self.assertTrue(border.IsTopLineValid) - self.assertEqual(0, border.TopLine.InnerLineWidth) - self.assertEqual(2, border.TopLine.OuterLineWidth) - self.assertEqual(0, border.TopLine.LineDistance) - self.assertEqual(0, border.TopLine.Color) - - self.assertTrue(border.IsBottomLineValid) - self.assertEqual(0, border.BottomLine.InnerLineWidth) - self.assertEqual(2, border.BottomLine.OuterLineWidth) - self.assertEqual(0, border.BottomLine.LineDistance) - self.assertEqual(0, border.BottomLine.Color) - - self.assertTrue(border.IsLeftLineValid) - self.assertEqual(0, border.LeftLine.InnerLineWidth) - self.assertEqual(2, border.LeftLine.OuterLineWidth) - self.assertEqual(0, border.LeftLine.LineDistance) - self.assertEqual(0, border.LeftLine.Color) - - self.assertTrue(border.IsRightLineValid) - self.assertEqual(0, border.RightLine.InnerLineWidth) - self.assertEqual(2, border.RightLine.OuterLineWidth) - self.assertEqual(0, border.RightLine.LineDistance) - self.assertEqual(0, border.RightLine.Color) - - self.assertTrue(border.IsHorizontalLineValid) - self.assertEqual(0, border.HorizontalLine.InnerLineWidth) - self.assertEqual(2, border.HorizontalLine.OuterLineWidth) - self.assertEqual(0, border.HorizontalLine.LineDistance) - self.assertEqual(0, border.HorizontalLine.Color) - - self.assertTrue(border.IsVerticalLineValid) - self.assertEqual(0, border.VerticalLine.InnerLineWidth) - self.assertEqual(2, border.VerticalLine.OuterLineWidth) - self.assertEqual(0, border.VerticalLine.LineDistance) - self.assertEqual(0, border.VerticalLine.Color) + self.__test_borderAsserts(border.TopLine, border.IsTopLineValid) + self.__test_borderAsserts(border.BottomLine, border.IsBottomLineValid) + self.__test_borderAsserts(border.LeftLine, border.IsLeftLineValid) + self.__test_borderAsserts(border.RightLine, border.IsRightLineValid) + self.__test_borderAsserts(border.HorizontalLine, border.IsHorizontalLineValid) + self.__test_borderAsserts(border.VerticalLine, border.IsVerticalLineValid) self.assertTrue(border.IsDistanceValid) self.assertEqual(97, border.Distance) @@ -97,17 +83,10 @@ class CheckTable(unittest.TestCase): self.assertEqual(0, border.BottomLine.LineDistance) self.assertEqual(0xFF, border.BottomLine.Color) - self.assertTrue(border.IsLeftLineValid) - self.assertEqual(0, border.LeftLine.InnerLineWidth) - self.assertEqual(2, border.LeftLine.OuterLineWidth) - self.assertEqual(0, border.LeftLine.LineDistance) - self.assertEqual(0, border.LeftLine.Color) + self.__test_borderAsserts(border.LeftLine, border.IsLeftLineValid) + + self.__test_borderAsserts(border.RightLine, border.IsRightLineValid) - self.assertTrue(border.IsRightLineValid) - self.assertEqual(0, border.RightLine.InnerLineWidth) - self.assertEqual(2, border.RightLine.OuterLineWidth) - self.assertEqual(0, border.RightLine.LineDistance) - self.assertEqual(0, border.RightLine.Color) self.assertTrue(border.IsHorizontalLineValid) self.assertEqual(0, border.HorizontalLine.InnerLineWidth) @@ -115,11 +94,8 @@ class CheckTable(unittest.TestCase): self.assertEqual(0, border.HorizontalLine.LineDistance) self.assertEqual(0xFF00, border.HorizontalLine.Color) - self.assertTrue(border.IsVerticalLineValid) - self.assertEqual(0, border.VerticalLine.InnerLineWidth) - self.assertEqual(2, border.VerticalLine.OuterLineWidth) - self.assertEqual(0, border.VerticalLine.LineDistance) - self.assertEqual(0, border.VerticalLine.Color) + self.__test_borderAsserts(border.VerticalLine, border.IsVerticalLineValid) + self.assertTrue(border.IsDistanceValid) self.assertEqual(97, border.Distance) @@ -141,21 +117,9 @@ class CheckTable(unittest.TestCase): self.assertEqual(SOLID, border2.BottomLine.LineStyle) self.assertEqual(11, border2.BottomLine.LineWidth) - self.assertTrue(border2.IsLeftLineValid) - self.assertEqual(0, border2.LeftLine.InnerLineWidth) - self.assertEqual(2, border2.LeftLine.OuterLineWidth) - self.assertEqual(0, border2.LeftLine.LineDistance) - self.assertEqual(0, border2.LeftLine.Color) - self.assertEqual(SOLID, border2.LeftLine.LineStyle) - self.assertEqual(2, border2.LeftLine.LineWidth) + self.__test_borderAssertsWithLineStyle(border2.LeftLine, border2.IsLeftLineValid) - self.assertTrue(border2.IsRightLineValid) - self.assertEqual(0, border2.RightLine.InnerLineWidth) - self.assertEqual(2, border2.RightLine.OuterLineWidth) - self.assertEqual(0, border2.RightLine.LineDistance) - self.assertEqual(0, border2.RightLine.Color) - self.assertEqual(SOLID, border2.RightLine.LineStyle) - self.assertEqual(2, border2.RightLine.LineWidth) + self.__test_borderAssertsWithLineStyle(border2.RightLine, border2.IsRightLineValid) self.assertTrue(border2.IsHorizontalLineValid) self.assertEqual(0, border2.HorizontalLine.InnerLineWidth) @@ -165,16 +129,9 @@ class CheckTable(unittest.TestCase): self.assertEqual(SOLID, border2.HorizontalLine.LineStyle) self.assertEqual(90, border2.HorizontalLine.LineWidth) - self.assertTrue(border2.IsVerticalLineValid) - self.assertEqual(0, border2.VerticalLine.InnerLineWidth) - self.assertEqual(2, border2.VerticalLine.OuterLineWidth) - self.assertEqual(0, border2.VerticalLine.LineDistance) - self.assertEqual(0, border2.VerticalLine.Color) - self.assertEqual(SOLID, border2.VerticalLine.LineStyle) - self.assertEqual(2, border2.VerticalLine.LineWidth) + self.__test_borderAssertsWithLineStyle(border2.VerticalLine, border2.IsVerticalLineValid) - self.assertTrue(border2.IsDistanceValid) - self.assertEqual(97, border2.Distance) + self.__test_borderDistance(border) # set border2 border2.RightLine = BorderLine2(0, 0, 0, 0, THICKTHIN_LARGEGAP, 120) border2.LeftLine = BorderLine2(0, 0, 0, 0, EMBOSSED, 90) @@ -232,8 +189,7 @@ class CheckTable(unittest.TestCase): self.assertEqual(DOTTED, border2.VerticalLine.LineStyle) self.assertEqual(90, border2.VerticalLine.LineWidth) - self.assertTrue(border2.IsDistanceValid) - self.assertEqual(97, border2.Distance) + self.__test_borderDistance(border2) # close document xDoc.dispose() diff --git a/sw/qa/python/load_save_test.py b/sw/qa/python/load_save_test.py index 29aa76391358..5aa0f3ba7cbf 100644 --- a/sw/qa/python/load_save_test.py +++ b/sw/qa/python/load_save_test.py @@ -49,7 +49,7 @@ class LoadSaveTest(unittest.TestCase): cls.m_fileURL = "file:/" cls.m_SourceDir = "FIXME" cls.m_TargetDir = "/tmp/out/" - cls.dirs= [] + cls.dirs = [] cls.files = [] cls.fileName = "" @@ -71,7 +71,6 @@ class LoadSaveTest(unittest.TestCase): m_xMSF = self.xContext.ServiceManager desktop = m_xMSF.createInstanceWithContext('com.sun.star.frame.Desktop', self.xContext) - #path = os.getenv("TDOC") filepath = os.path.abspath("FIXME") if os.name == "nt": sourceFile = "file:///" + filepath + "/" + quote(self.fileName) @@ -93,15 +92,15 @@ class LoadSaveTest(unittest.TestCase): raise - def getDirAndFile(self,dir): + def getDirAndFile(self, dir): root2 = os.mkdir(dir) - root = open(dir+ "/" + dir + ".odt",'a') + root = open(dir + "/" + dir + ".odt", 'a') self.getDirAndFileNames(dir) return self.dirs, self.files - def getDirAndFileNames( self, fdName): + def getDirAndFileNames(self, fdName): if os.path.isdir(fdName): self.dirs.append(fdName) @@ -109,6 +108,7 @@ class LoadSaveTest(unittest.TestCase): if not fdName[-1] == "/": fdName += "/" + for subfile in subfiles: subfileName = fdName + subfile self.getDirAndFileNames(subfileName) @@ -125,5 +125,6 @@ class LoadSaveTest(unittest.TestCase): if not os.path.exists(target + dir): f = os.mkdir(target + dir) self.assertTrue( os.path.exists(target + dir)) - root = open(target + dir + "/" + self.m_SourceDir + ".odt",'a') + + root = open(target + dir + "/" + self.m_SourceDir + ".odt", 'a') filepath = os.path.abspath(target + dir + "/" + self.m_SourceDir + ".odt") |