Changeset 53c771e in sasview for src/sas/qtgui/Utilities


Ignore:
Timestamp:
Nov 9, 2017 8:45:20 AM (7 years ago)
Author:
Piotr Rozyczko <rozyczko@…>
Branches:
ESS_GUI, ESS_GUI_Docs, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_iss959, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc
Children:
dd150ef
Parents:
d6b8a1d
git-author:
Piotr Rozyczko <rozyczko@…> (11/08/17 09:22:45)
git-committer:
Piotr Rozyczko <rozyczko@…> (11/09/17 08:45:20)
Message:

Converted unit tests

Location:
src/sas/qtgui/Utilities
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • src/sas/qtgui/Utilities/GuiUtils.py

    rd6b8a1d r53c771e  
    528528    with open(path,'w') as out: 
    529529        has_errors = True 
    530         if data.dy is None or data.dy == []: 
     530        if data.dy is None or not data.dy: 
    531531            has_errors = False 
    532532        # Sanity check 
     
    538538                has_errors = False 
    539539        if has_errors: 
    540             if data.dx is not None and data.dx != []: 
     540            if data.dx is not None and data.dx: 
    541541                out.write("<X>   <Y>   <dY>   <dX>\n") 
    542542            else: 
     
    547547        for i in range(len(data.x)): 
    548548            if has_errors: 
    549                 if data.dx is not None and data.dx != []: 
     549                if data.dx is not None and data.dx: 
    550550                    if  data.dx[i] is not None: 
    551551                        out.write("%g  %g  %g  %g\n" % (data.x[i], 
  • src/sas/qtgui/Utilities/UnitTesting/GuiUtilsTest.py

    r7fb471d r53c771e  
    33import webbrowser 
    44 
    5 from PyQt4 import QtCore 
    6 from PyQt4 import QtGui 
     5from PyQt5 import QtCore 
     6from PyQt5 import QtGui, QtWidgets 
    77from unittest.mock import MagicMock 
    88 
     
    1919from sas.qtgui.Utilities.GuiUtils import * 
    2020 
    21 if not QtGui.QApplication.instance(): 
    22     app = QtGui.QApplication(sys.argv) 
     21if not QtWidgets.QApplication.instance(): 
     22    app = QtWidgets.QApplication(sys.argv) 
    2323 
    2424class GuiUtilsTest(unittest.TestCase): 
     
    9090        # Make sure test_item got all data added 
    9191        self.assertEqual(test_item.child(0).text(), name) 
    92         list_from_item = test_item.child(0).data().toList() 
     92        list_from_item = test_item.child(0).data() 
    9393        self.assertIsInstance(list_from_item, list) 
    94         self.assertEqual(list_from_item[0].toPyObject(), test_list[0]) 
    95         self.assertEqual(list_from_item[1].toPyObject(), test_list[1]) 
    96         self.assertEqual(list_from_item[2].toPyObject(), test_list[2]) 
     94        self.assertEqual(list_from_item[0], test_list[0]) 
     95        self.assertEqual(list_from_item[1], test_list[1]) 
     96        self.assertEqual(list_from_item[2], test_list[2]) 
    9797 
    9898    def testupdateModelItemWithPlot(self): 
     
    111111        self.assertEqual(test_item.child(0).text(), name) 
    112112        self.assertTrue(test_item.child(0).isCheckable()) 
    113         list_from_item = test_item.child(0).child(0).data().toPyObject() 
     113        list_from_item = test_item.child(0).child(0).data() 
    114114        self.assertIsInstance(list_from_item, list) 
    115115        self.assertEqual(str(list_from_item[0]), test_list[0]) 
     
    305305        # Test the .txt format 
    306306        file_name = "test123_out.txt" 
    307         QtGui.QFileDialog.getSaveFileName = MagicMock(return_value=file_name) 
     307        QtWidgets.QFileDialog.getSaveFileName = MagicMock(return_value=(file_name,'')) 
    308308        data.filename = "test123.txt" 
    309309        saveData1D(data) 
     
    313313        # Test the .xml format 
    314314        file_name = "test123_out.xml" 
    315         QtGui.QFileDialog.getSaveFileName = MagicMock(return_value=file_name) 
     315        QtWidgets.QFileDialog.getSaveFileName = MagicMock(return_value=(file_name,'')) 
    316316        data.filename = "test123.xml" 
    317317        saveData1D(data) 
     
    321321        # Test the wrong format 
    322322        file_name = "test123_out.mp3" 
    323         QtGui.QFileDialog.getSaveFileName = MagicMock(return_value=file_name) 
     323        QtWidgets.QFileDialog.getSaveFileName = MagicMock(return_value=(file_name,'')) 
    324324        data.filename = "test123.mp3" 
    325325        saveData1D(data) 
     
    337337        # Test the .txt format 
    338338        file_name = "test123_out.dat" 
    339         QtGui.QFileDialog.getSaveFileName = MagicMock(return_value=file_name) 
     339        QtWidgets.QFileDialog.getSaveFileName = MagicMock(return_value=(file_name,'')) 
    340340        data.filename = "test123.dat" 
    341341        saveData2D(data) 
     
    345345        # Test the wrong format 
    346346        file_name = "test123_out.mp3" 
    347         QtGui.QFileDialog.getSaveFileName = MagicMock(return_value=file_name) 
     347        QtWidgets.QFileDialog.getSaveFileName = MagicMock(return_value=(file_name,'')) 
    348348        data.filename = "test123.mp3" 
    349349        saveData2D(data) 
  • src/sas/qtgui/Utilities/UnitTesting/SasviewLoggerTest.py

    r464cd07 r53c771e  
    33import logging 
    44 
    5 from PyQt4.QtGui import * 
    6 from PyQt4.QtCore import * 
     5from PyQt5.QtGui import * 
     6from PyQt5.QtCore import * 
     7from PyQt5.QtWidgets import * 
    78 
    89# set up import paths 
Note: See TracChangeset for help on using the changeset viewer.