]> SALOME platform Git repositories - modules/gui.git/commitdiff
Salome HOME
CurvePlot test breaks
authorViktor UZLOV <vuzlov@debian10-01.nnov.opencascade.com>
Mon, 21 Sep 2020 12:51:31 +0000 (15:51 +0300)
committerViktor UZLOV <vuzlov@debian10-01.nnov.opencascade.com>
Mon, 21 Sep 2020 12:51:31 +0000 (15:51 +0300)
tools/CurvePlot/src/python/test/CMakeLists.txt
tools/CurvePlot/src/python/test/PlotTestBase.py
tools/CurvePlot/src/python/test/SalomePyQt_MockUp.py [new file with mode: 0644]
tools/CurvePlot/src/python/test/SalomePyQt_MockUp.py.in [deleted file]
tools/CurvePlot/src/python/test/plot_test.py

index f1ff87f7926886bb58a05ff2ad827334bd5799b6..e4193663bad126638e2bb3f674ecb51fd57422c2 100644 (file)
@@ -40,8 +40,8 @@ INSTALL(DIRECTORY baselines DESTINATION ${SALOME_INSTALL_SCRIPT_PYTHON}/tests)
 SALOME_ACCUMULATE_ENVIRONMENT(PYTHONPATH ${CMAKE_BINARY_DIR}/local)  # point to local curveplot package in BUILD dir
 SALOME_GENERATE_TESTS_ENVIRONMENT(tests_env)
 
-#ADD_TEST(CurvePlotUnitTests ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/plot_test.py)
-#SET_TESTS_PROPERTIES(CurvePlotUnitTests PROPERTIES ENVIRONMENT "${tests_env}")
+ADD_TEST(CurvePlotUnitTests ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/plot_test.py)
+SET_TESTS_PROPERTIES(CurvePlotUnitTests PROPERTIES ENVIRONMENT "${tests_env}")
 
 # For test purposes
 FILE(COPY ${_test_SCRIPTS} DESTINATION ${CRVPLOT_TEST_INSTALL})
index 922785f2ec23a017e0a66a7a5d2622ffad7a69e0..7e9e5090bc7535ee4e34f299fd41b8a878f9eee0 100644 (file)
@@ -81,11 +81,11 @@ class PlotTestBase(unittest.TestCase):
 
   def setUp(self):
     import sys
-    from curveplot.SalomePyQt_MockUp import SalomePyQt
+    from SalomePyQt_MockUp import SalomePyQt
     from curveplot.TableModel import TableModel
     from curveplot.CurveModel import CurveModel
     from curveplot.XYPlotSetModel import XYPlotSetModel
-    from curveplot.TestDesktop import TestDesktop
+    from TestDesktop import TestDesktop
 
     self.qpixmap = None
     self.keepDir = False
@@ -95,7 +95,7 @@ class PlotTestBase(unittest.TestCase):
       self.tmpDir = None
 
     # Minimal UI setup:
-    self.app = QApplication(sys.argv)
+    #self.app = QApplication(sys.argv)
     desktop = TestDesktop(None)
     self.sgPyQt = SalomePyQt(desktop)
     desktop._sgPyQt = self.sgPyQt
diff --git a/tools/CurvePlot/src/python/test/SalomePyQt_MockUp.py b/tools/CurvePlot/src/python/test/SalomePyQt_MockUp.py
new file mode 100644 (file)
index 0000000..42685b5
--- /dev/null
@@ -0,0 +1,148 @@
+# Copyright (C) 2007-2020  CEA/DEN, EDF R&D
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+#
+# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+#
+# Author : A. Bruneton
+#
+
+from pyqtside.QtWidgets import QApplication, QTabWidget 
+from pyqtside.QtWidgets import QAction, QMenu, QDesktopWidget, QFileDialog
+from pyqtside.QtGui import QIcon, QPixmap
+from pyqtside.QtCore import QObject, pyqtSlot, pyqtSignal
+
+RESOURCE_DIR = "@SGPYQT_RES_DIR@"
+
+class SalomePyQt(QObject):
+  """ A pure Qt implementation of the SgPyQt API (usually provided in the SALOME context)
+  This class can be used to mimick the true SALOME object without having to launch 
+  SALOME
+  """  
+  currentTabChanged = pyqtSignal(int)
+  
+  START_VIEW_ID = 0
+  
+  def __init__(self, mainWindow=None):
+    QObject.__init__(self)
+    self._mainWindow = mainWindow
+    self._tabWidget = QTabWidget()
+    self._tabWidget.setObjectName("TabWidget")
+    self._viewIDs = {}
+    self._menuBar = None
+    if self._mainWindow:
+      self._menuBar = self._mainWindow.menuBar()
+      self._mainWindow.setCentralWidget(self._tabWidget)
+    self._tabWidget.currentChanged.connect(self.onTabChanged)
+    self._blockSignal = False
+  
+  def getDesktop(self):
+    return self._mainWindow
+  
+  def getFileName(self, parent_widget, initial, filters, caption, do_open):
+    fil = ";;".join([str(f) for f in filters])
+    return QFileDialog.getSaveFileName(parent=parent_widget,
+                                       caption=caption, directory=initial, filter=fil);
+  
+  @pyqtSlot(int)
+  def onTabChanged(self, index):
+    if self._blockSignal:
+      return
+    invDict = dict([(v, k) for k,v in self._viewIDs.items()])
+    if index in invDict:
+      self._blockSignal = True
+      self.currentTabChanged.emit(invDict[index])
+      self._blockSignal = False
+  
+  def createView(self, name, widget):
+    self.START_VIEW_ID += 1
+    idx = self._tabWidget.insertTab(-1, widget, name)
+    self._viewIDs[self.START_VIEW_ID] = idx 
+    return self.START_VIEW_ID
+  
+  def activateView(self, viewID):
+    idx = self._viewIDs[viewID]
+    self._tabWidget.setCurrentIndex(idx)
+  
+  def setViewVisible(self, viewID, isVis):
+    ## TODO: improve to really remove tab
+    if isVis:
+      self.activateView(viewID) 
+  
+  def closeView(self, viewID):
+    self._blockSignal = True
+    idxClosed = self._viewIDs[viewID]
+    # QTabWidget doesn't clean after itself when removing a tab
+    w = self._tabWidget.widget(idxClosed)  
+    self._tabWidget.removeTab(idxClosed)
+    try:
+      w.clearAll()
+    except:
+      pass
+    # Update the other tab indices which are now shifted:
+    for k, idx in self._viewIDs.items():
+      if idx > idxClosed:
+        self._viewIDs[k] -= 1
+    self._blockSignal = False
+  
+  def setViewTitle(self, viewID, title):
+    idx = self._viewIDs[viewID]
+    self._tabWidget.setTabText(idx, title)
+  
+  def createAction(self, id, short_name, long_name, tooltip, icon):
+    import os
+    return QAction(QIcon(QPixmap(os.path.normpath(icon))),short_name, None)
+  
+  def defaultMenuGroup(self):
+    return None
+  
+  def createMenu(self, name_or_action, pos_or_menu, menuId=-1, menuGroup=None):
+    if not self._mainWindow is None:
+      if isinstance(name_or_action, str):
+        return self.__createMenu1( name_or_action, pos_or_menu, menuId, menuGroup)
+      else:
+        return self.__createMenu2(name_or_action, pos_or_menu)
+    
+  def __createMenu1(self, name, pos, menuId, menuGroup):
+    menu = QMenu(name, self._menuBar)
+    self._menuBar.addMenu(menu)
+    return menu
+  
+  def __createMenu2(self, action, menu):
+    menu.addAction(action)
+  
+  def createSeparator(self):
+    return None
+  
+  def createTool(self, toolbar_name_or_action, toolbar=None):
+    if not self._mainWindow is None:
+      if isinstance(toolbar_name_or_action, str):
+        return self.__createTool1(toolbar_name_or_action)
+      else:
+        return self.__createTool2(toolbar_name_or_action, toolbar)
+    
+  def __createTool1(self, toolbar_name):
+    return None
+  
+  def __createTool2(self, action, toolbar):
+    return None
+  
+  def loadIcon(self, module_name, file_name):
+    import os
+    mod_dir = os.getenv("%s_ROOT_DIR" % module_name)
+    mod_lc = module_name.lower()
+    res_path = os.path.join(mod_dir, RESOURCE_DIR, mod_lc, file_name)
+    # e.g. MODULE_ROOT_DIR/share/resource/module/image.png
+    return QIcon(res_path)
diff --git a/tools/CurvePlot/src/python/test/SalomePyQt_MockUp.py.in b/tools/CurvePlot/src/python/test/SalomePyQt_MockUp.py.in
deleted file mode 100644 (file)
index 42685b5..0000000
+++ /dev/null
@@ -1,148 +0,0 @@
-# Copyright (C) 2007-2020  CEA/DEN, EDF R&D
-#
-# This library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 2.1 of the License, or (at your option) any later version.
-#
-# This library is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this library; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
-#
-# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
-#
-# Author : A. Bruneton
-#
-
-from pyqtside.QtWidgets import QApplication, QTabWidget 
-from pyqtside.QtWidgets import QAction, QMenu, QDesktopWidget, QFileDialog
-from pyqtside.QtGui import QIcon, QPixmap
-from pyqtside.QtCore import QObject, pyqtSlot, pyqtSignal
-
-RESOURCE_DIR = "@SGPYQT_RES_DIR@"
-
-class SalomePyQt(QObject):
-  """ A pure Qt implementation of the SgPyQt API (usually provided in the SALOME context)
-  This class can be used to mimick the true SALOME object without having to launch 
-  SALOME
-  """  
-  currentTabChanged = pyqtSignal(int)
-  
-  START_VIEW_ID = 0
-  
-  def __init__(self, mainWindow=None):
-    QObject.__init__(self)
-    self._mainWindow = mainWindow
-    self._tabWidget = QTabWidget()
-    self._tabWidget.setObjectName("TabWidget")
-    self._viewIDs = {}
-    self._menuBar = None
-    if self._mainWindow:
-      self._menuBar = self._mainWindow.menuBar()
-      self._mainWindow.setCentralWidget(self._tabWidget)
-    self._tabWidget.currentChanged.connect(self.onTabChanged)
-    self._blockSignal = False
-  
-  def getDesktop(self):
-    return self._mainWindow
-  
-  def getFileName(self, parent_widget, initial, filters, caption, do_open):
-    fil = ";;".join([str(f) for f in filters])
-    return QFileDialog.getSaveFileName(parent=parent_widget,
-                                       caption=caption, directory=initial, filter=fil);
-  
-  @pyqtSlot(int)
-  def onTabChanged(self, index):
-    if self._blockSignal:
-      return
-    invDict = dict([(v, k) for k,v in self._viewIDs.items()])
-    if index in invDict:
-      self._blockSignal = True
-      self.currentTabChanged.emit(invDict[index])
-      self._blockSignal = False
-  
-  def createView(self, name, widget):
-    self.START_VIEW_ID += 1
-    idx = self._tabWidget.insertTab(-1, widget, name)
-    self._viewIDs[self.START_VIEW_ID] = idx 
-    return self.START_VIEW_ID
-  
-  def activateView(self, viewID):
-    idx = self._viewIDs[viewID]
-    self._tabWidget.setCurrentIndex(idx)
-  
-  def setViewVisible(self, viewID, isVis):
-    ## TODO: improve to really remove tab
-    if isVis:
-      self.activateView(viewID) 
-  
-  def closeView(self, viewID):
-    self._blockSignal = True
-    idxClosed = self._viewIDs[viewID]
-    # QTabWidget doesn't clean after itself when removing a tab
-    w = self._tabWidget.widget(idxClosed)  
-    self._tabWidget.removeTab(idxClosed)
-    try:
-      w.clearAll()
-    except:
-      pass
-    # Update the other tab indices which are now shifted:
-    for k, idx in self._viewIDs.items():
-      if idx > idxClosed:
-        self._viewIDs[k] -= 1
-    self._blockSignal = False
-  
-  def setViewTitle(self, viewID, title):
-    idx = self._viewIDs[viewID]
-    self._tabWidget.setTabText(idx, title)
-  
-  def createAction(self, id, short_name, long_name, tooltip, icon):
-    import os
-    return QAction(QIcon(QPixmap(os.path.normpath(icon))),short_name, None)
-  
-  def defaultMenuGroup(self):
-    return None
-  
-  def createMenu(self, name_or_action, pos_or_menu, menuId=-1, menuGroup=None):
-    if not self._mainWindow is None:
-      if isinstance(name_or_action, str):
-        return self.__createMenu1( name_or_action, pos_or_menu, menuId, menuGroup)
-      else:
-        return self.__createMenu2(name_or_action, pos_or_menu)
-    
-  def __createMenu1(self, name, pos, menuId, menuGroup):
-    menu = QMenu(name, self._menuBar)
-    self._menuBar.addMenu(menu)
-    return menu
-  
-  def __createMenu2(self, action, menu):
-    menu.addAction(action)
-  
-  def createSeparator(self):
-    return None
-  
-  def createTool(self, toolbar_name_or_action, toolbar=None):
-    if not self._mainWindow is None:
-      if isinstance(toolbar_name_or_action, str):
-        return self.__createTool1(toolbar_name_or_action)
-      else:
-        return self.__createTool2(toolbar_name_or_action, toolbar)
-    
-  def __createTool1(self, toolbar_name):
-    return None
-  
-  def __createTool2(self, action, toolbar):
-    return None
-  
-  def loadIcon(self, module_name, file_name):
-    import os
-    mod_dir = os.getenv("%s_ROOT_DIR" % module_name)
-    mod_lc = module_name.lower()
-    res_path = os.path.join(mod_dir, RESOURCE_DIR, mod_lc, file_name)
-    # e.g. MODULE_ROOT_DIR/share/resource/module/image.png
-    return QIcon(res_path)
index 3267193323bedf1776e5a3335c24d41a2edb3e51..82db5e7755d614cbbc2aee44f1bdb1ae0af1899a 100644 (file)
@@ -20,7 +20,7 @@
 # Author : A. Bruneton
 #
 from curveplot import *
-from curveplot.PlotTestBase import PlotTestBase, processDecorator
+from PlotTestBase import PlotTestBase, processDecorator
 from curveplot.PlotSettings import PlotSettings
 
 from pyqtside.QtWidgets import QApplication
@@ -41,6 +41,7 @@ class PlotTest(PlotTestBase):
 
   def __init__(self, methodName):
     PlotTestBase.__init__(self, methodName)
+    
 
   ###
   ### Data generation
@@ -49,6 +50,7 @@ class PlotTest(PlotTestBase):
     import numpy as np
     x = np.arange(100)
     y = np.sin(x*alpha/np.pi)
+    print(1)
     return x, y
 
   def generateExp(self, alpha=1.0):
@@ -144,7 +146,7 @@ class PlotTest(PlotTestBase):
     x, y = self.generateSine()
     tw = self.showTabWidget()
     PlotController.AddCurve(x, y, curve_label="My curve", x_label="Lèés X (unicode!)", y_label="Et des ŷ", append=False)
-    self.assertTrue(self.areScreenshotEqual(tw))
+    self.assertTrue(self.areScreenshotEqual(tw), msg='Hello!')
 
   def testAddCurveAppend(self):
     x, y = self.generateSine()