Index: src/sas/qtgui/Calculators/UnitTesting/DensityCalculatorTest.py
===================================================================
--- src/sas/qtgui/Calculators/UnitTesting/DensityCalculatorTest.py	(revision 83eb5208b8acb86b064162274de583670f72da47)
+++ src/sas/qtgui/Calculators/UnitTesting/DensityCalculatorTest.py	(revision 83eb5208b8acb86b064162274de583670f72da47)
@@ -0,0 +1,121 @@
+import sys
+import unittest
+import webbrowser
+
+from PyQt4 import QtGui
+from PyQt4.QtTest import QTest
+from PyQt4 import QtCore
+from mock import MagicMock
+
+####### TEMP
+import sas.qtgui.path_prepare
+#######
+
+# Local
+from sas.qtgui.Calculators.DensityPanel import DensityPanel
+from sas.qtgui.Calculators.DensityPanel import toMolarMass
+from sas.qtgui.Utilities.GuiUtils import FormulaValidator
+
+import sas.qtgui.Utilities.LocalConfig
+
+app = QtGui.QApplication(sys.argv)
+
+class ToMolarMassTest(unittest.TestCase):
+    """ Test the auxiliary conversion method"""
+    def testGoodEasy(self):
+        self.assertEqual(toMolarMass("H2"), "2.01588")
+
+    def testGoodComplex(self):
+        self.assertEqual(toMolarMass("H24O12C4C6N2Pu"), "608.304")
+
+    def testGoodComplex2(self):
+        self.assertEqual(toMolarMass("(H2O)0.5(D2O)0.5"), "19.0214")
+
+    def testBadInputInt(self):
+        self.assertEqual(toMolarMass(1), "")
+
+    def testBadInputStr(self):
+        self.assertEqual(toMolarMass("Im a bad string"), "")
+
+class DensityCalculatorTest(unittest.TestCase):
+    '''Test the DensityCalculator'''
+    def setUp(self):
+        '''Create the DensityCalculator'''
+        self.widget = DensityPanel(None)
+
+    def tearDown(self):
+        '''Destroy the DensityCalculator'''
+        self.widget.close()
+        self.widget = None
+
+    def testDefaults(self):
+        '''Test the GUI in its default state'''
+        self.assertIsInstance(self.widget, QtGui.QWidget)
+        self.assertEqual(self.widget.windowTitle(), "Density/Volume Calculator")
+        self.assertIsInstance(self.widget.ui.editMolecularFormula.validator(), FormulaValidator)
+        self.assertEqual(self.widget.ui.editMolecularFormula.styleSheet(), '')
+        self.assertEqual(self.widget.model.columnCount(), 1)
+        self.assertEqual(self.widget.model.rowCount(), 4)
+        self.assertEqual(self.widget.sizePolicy().Policy(), QtGui.QSizePolicy.Fixed)
+
+    def testSimpleEntry(self):
+        ''' Default compound calculations '''
+        self.widget.ui.editMolarVolume.insert("1.0")
+
+        self.widget.show()
+        # Send tab x3
+        key = QtCore.Qt.Key_Tab
+        QTest.keyEvent(QTest.Press, self.widget, key, QtCore.Qt.NoModifier)
+        QTest.keyEvent(QTest.Press, self.widget, key, QtCore.Qt.NoModifier)
+        QTest.keyEvent(QTest.Press, self.widget, key, QtCore.Qt.NoModifier)
+        QTest.qWait(100)
+
+        # Assure the mass density field is set
+        self.assertEqual(self.widget.ui.editMassDensity.text(), '18.0153')
+
+        # Change mass density
+        self.widget.ui.editMassDensity.insert("16.0")
+        # Send shift-tab to update the molar volume field
+        key =  QtCore.Qt.Key_Tab
+        QTest.keyEvent(QTest.Press, self.widget, key, QtCore.Qt.ShiftModifier)
+        QTest.qWait(100)
+
+        # Assure the molar volume field got updated
+        self.assertEqual(self.widget.ui.editMolarVolume.text(), '1.12595625')
+
+    def testComplexEntryAndReset(self):
+        ''' User entered compound calculations and subsequent reset'''
+
+        self.widget.ui.editMolecularFormula.clear()
+        self.widget.ui.editMolecularFormula.insert("KMnO4")
+        self.widget.ui.editMolarVolume.insert("2.0")
+
+        self.widget.show()
+        # Send tab x3
+        key = QtCore.Qt.Key_Tab
+        QTest.keyEvent(QTest.Press, self.widget, key, QtCore.Qt.NoModifier)
+        QTest.keyEvent(QTest.Press, self.widget, key, QtCore.Qt.NoModifier)
+        QTest.keyEvent(QTest.Press, self.widget, key, QtCore.Qt.NoModifier)
+        QTest.qWait(100)
+
+        # Assure the mass density field is set
+        self.assertEqual(self.widget.ui.editMassDensity.text(), '79.017')
+
+        # Reset the widget
+        self.widget.modelReset()
+
+        self.assertEqual(self.widget.ui.editMolecularFormula.text(), "H2O")
+        self.assertEqual(self.widget.ui.editMolarMass.text(), "18.0153")
+        self.assertEqual(self.widget.ui.editMolarVolume.text(), "")
+        self.assertEqual(self.widget.ui.editMassDensity.text(), "")
+
+        #self.widget.exec_()
+
+    def testHelp(self):
+        """ Assure help file is shown """
+
+        # this should not rise
+        self.widget.displayHelp()
+
+if __name__ == "__main__":
+    unittest.main()
Index: src/sas/qtgui/Calculators/UnitTesting/KiessigCalculatorTest.py
===================================================================
--- src/sas/qtgui/Calculators/UnitTesting/KiessigCalculatorTest.py	(revision 83eb5208b8acb86b064162274de583670f72da47)
+++ src/sas/qtgui/Calculators/UnitTesting/KiessigCalculatorTest.py	(revision 83eb5208b8acb86b064162274de583670f72da47)
@@ -0,0 +1,83 @@
+import sys
+import unittest
+from PyQt4 import QtGui
+from PyQt4.QtTest import QTest
+from PyQt4.QtCore import Qt
+
+# TEMP
+import sas.qtgui.path_prepare
+
+
+from sas.qtgui.Calculators.KiessigPanel import KiessigPanel
+
+app = QtGui.QApplication(sys.argv)
+
+
+class KiessigCalculatorTest(unittest.TestCase):
+    """Test the KiessigCalculator"""
+    def setUp(self):
+        """Create the KiessigCalculator"""
+        self.widget = KiessigPanel(None)
+
+    def tearDown(self):
+        """Destroy the KiessigCalculator"""
+        self.widget.close()
+        self.widget = None
+
+    def testDefaults(self):
+        """Test the GUI in its default state"""
+        self.assertIsInstance(self.widget, QtGui.QWidget)
+        self.assertEqual(self.widget.windowTitle(), "Kiessig Thickness Calculator")
+        self.assertEqual(self.widget.sizePolicy().Policy(), QtGui.QSizePolicy.Fixed)
+
+    def testHelp(self):
+        """ Assure help file is shown """
+
+        # this should not rise
+        self.widget.onHelp()
+
+    def testComplexEntryNumbers(self):
+        """ User entered compound calculations and subsequent reset"""
+
+        self.widget.deltaq_in.clear()
+        self.widget.deltaq_in.insert('0.05')
+        #
+        # Push Compute with the left mouse button
+        computeButton = self.widget.computeButton
+        QTest.mouseClick(computeButton, Qt.LeftButton)
+        self.assertEqual(self.widget.lengthscale_out.text(), '125.664')
+
+    def testComplexEntryNumbers2(self):
+        """ User entered compound calculations and subsequent reset"""
+
+        self.widget.deltaq_in.clear()
+        self.widget.deltaq_in.insert('1.0')
+        #
+        # Push Compute with the left mouse button
+        computeButton = self.widget.computeButton
+        QTest.mouseClick(computeButton, Qt.LeftButton)
+        self.assertEqual(self.widget.lengthscale_out.text(), '6.283')
+
+    def testComplexEntryNumbers3(self):
+        """ User entered compound calculations and subsequent reset"""
+
+        self.widget.deltaq_in.clear()
+        self.widget.deltaq_in.insert('2.0')
+        #
+        # Push Compute with the left mouse button
+        computeButton = self.widget.computeButton
+        QTest.mouseClick(computeButton, Qt.LeftButton)
+        self.assertEqual(self.widget.lengthscale_out.text(), '3.142')
+
+    def testComplexEntryLetters(self):
+        """ User entered compound calculations and subsequent reset"""
+
+        self.widget.deltaq_in.insert("xyz")
+
+        # Push Compute with the left mouse button
+        computeButton = self.widget.computeButton
+        QTest.mouseClick(computeButton, Qt.LeftButton)
+        self.assertEqual(self.widget.lengthscale_out.text(), '')
+
+if __name__ == "__main__":
+    unittest.main()
Index: src/sas/qtgui/Calculators/UnitTesting/SLDCalculatorTest.py
===================================================================
--- src/sas/qtgui/Calculators/UnitTesting/SLDCalculatorTest.py	(revision 83eb5208b8acb86b064162274de583670f72da47)
+++ src/sas/qtgui/Calculators/UnitTesting/SLDCalculatorTest.py	(revision 83eb5208b8acb86b064162274de583670f72da47)
@@ -0,0 +1,145 @@
+import sys
+import unittest
+import webbrowser
+
+from PyQt4 import QtGui
+from PyQt4.QtTest import QTest
+from PyQt4 import QtCore
+from mock import MagicMock
+
+####### TEMP
+import sas.qtgui.path_prepare
+#######
+
+# Local
+from sas.qtgui.Calculators.SldPanel import SldResult
+from sas.qtgui.Calculators.SldPanel import SldPanel
+from sas.qtgui.Calculators.SldPanel import sldAlgorithm
+from sas.qtgui.Utilities.GuiUtils import FormulaValidator
+
+import sas.qtgui.Utilities.LocalConfig
+
+app = QtGui.QApplication(sys.argv)
+
+class SldResultTest(unittest.TestCase):
+    """ Test the simple container class"""
+    def testObjectSize(self):
+        results = SldResult(0.0, 0.0, 0.0, 0.0, 0.0, 0.0,
+                            0.0, 0.0, 0.0, 0.0, 0.0, 0.0)
+        self.assertEqual(sys.getsizeof(results), 56)
+
+
+class SldAlgorithmTest(unittest.TestCase):
+    """ Test the periodictable wrapper """
+    def testSldAlgorithm1(self):
+        molecular_formula = "H2O"
+        mass_density = 1.0
+        wavelength = 6.0
+        
+        results = sldAlgorithm( molecular_formula,
+                                mass_density,
+                                wavelength)
+        self.assertIsInstance(results, SldResult)
+        self.assertAlmostEqual(results.neutron_length, 0.175463, 5)
+        self.assertAlmostEqual(results.neutron_inc_xs, 5.365857, 5)
+        self.assertAlmostEqual(results.neutron_abs_xs, 0.074224, 5)
+
+    def testSldAlgorithm2(self):
+        molecular_formula = "C29O[18]5+7NH[2]3"
+        mass_density = 3.0
+        wavelength = 666.0
+        
+        results = sldAlgorithm( molecular_formula,
+                                mass_density,
+                                wavelength)
+        self.assertIsInstance(results, SldResult)
+        self.assertAlmostEqual(results.neutron_length,   0.059402, 5)
+        self.assertAlmostEqual(results.neutron_inc_xs,   0.145427, 5)
+        self.assertAlmostEqual(results.neutron_abs_xs,  15.512215, 5)
+        self.assertAlmostEqual(results.neutron_sld_real, 1.3352833e-05, 5)
+        self.assertAlmostEqual(results.neutron_sld_imag, 1.1645807e-10, 5)
+
+
+class SLDCalculatorTest(unittest.TestCase):
+    '''Test the SLDCalculator'''
+    def setUp(self):
+        '''Create the SLDCalculator'''
+        self.widget = SldPanel(None)
+
+    def tearDown(self):
+        '''Destroy the DensityCalculator'''
+        self.widget.close()
+        self.widget = None
+
+    def testDefaults(self):
+        '''Test the GUI in its default state'''
+        self.assertIsInstance(self.widget, QtGui.QWidget)
+        self.assertEqual(self.widget.windowTitle(), "SLD Calculator")
+        self.assertIsInstance(self.widget.ui.editMolecularFormula.validator(), FormulaValidator)
+        self.assertEqual(self.widget.ui.editMolecularFormula.styleSheet(), '')
+        self.assertEqual(self.widget.model.columnCount(), 1)
+        self.assertEqual(self.widget.model.rowCount(), 12)
+        self.assertEqual(self.widget.sizePolicy().Policy(), QtGui.QSizePolicy.Fixed)
+
+    def testSimpleEntry(self):
+        ''' Default compound calculations '''
+
+        self.widget.show()
+
+        self.widget.ui.editMassDensity.clear()
+        self.widget.ui.editMassDensity.insert("1.0")
+        # Send tab x3
+        key = QtCore.Qt.Key_Tab
+        QTest.keyEvent(QTest.Press, self.widget, key, QtCore.Qt.NoModifier)
+        QTest.keyEvent(QTest.Press, self.widget, key, QtCore.Qt.NoModifier)
+        QtGui.qApp.processEvents()
+        QTest.qWait(100)
+
+        # Assure the output fields are set
+        self.assertEqual(self.widget.ui.editNeutronIncXs.text(), '5.37')
+
+        # Change mass density
+        self.widget.ui.editWavelength.clear()
+        self.widget.ui.editWavelength.setText("666.0")
+
+        # Send shift-tab to update the molar volume field
+        QTest.keyEvent(QTest.Press, self.widget, key, QtCore.Qt.NoModifier)
+        QTest.keyEvent(QTest.Press, self.widget, key, QtCore.Qt.NoModifier)
+        QtGui.qApp.processEvents()
+        QTest.qWait(100)
+
+        # Assure the molar volume field got updated
+        self.assertEqual(self.widget.ui.editNeutronAbsXs.text(), '8.24')
+
+    def testComplexEntryAndReset(self):
+        ''' User entered compound calculations and subsequent reset'''
+
+        self.widget.ui.editMolecularFormula.clear()
+        self.widget.ui.editMolecularFormula.insert("CaCO[18]3+6H2O")
+        self.widget.ui.editMassDensity.insert("5.0")
+
+        self.widget.show()
+        # Send tab x2
+        key = QtCore.Qt.Key_Tab
+        QTest.keyEvent(QTest.Press, self.widget, key, QtCore.Qt.NoModifier)
+        QTest.keyEvent(QTest.Press, self.widget, key, QtCore.Qt.NoModifier)
+        QTest.qWait(100)
+
+        # Assure the mass density field is set
+        self.assertEqual(self.widget.ui.editNeutronIncXs.text(), '40.6')
+
+        # Reset the widget
+        self.widget.modelReset()
+
+        self.assertEqual(self.widget.ui.editMolecularFormula.text(), "H2O")
+        self.assertEqual(self.widget.ui.editMassDensity.text(), "1")
+        self.assertEqual(self.widget.ui.editWavelength.text(), "6")
+
+    def testHelp(self):
+        """ Assure help file is shown """
+
+        # this should not rise
+        self.widget.displayHelp()
+
+if __name__ == "__main__":
+    unittest.main()
Index: src/sas/qtgui/Calculators/UnitTesting/SlitSizeCalculatorTest.py
===================================================================
--- src/sas/qtgui/Calculators/UnitTesting/SlitSizeCalculatorTest.py	(revision 83eb5208b8acb86b064162274de583670f72da47)
+++ src/sas/qtgui/Calculators/UnitTesting/SlitSizeCalculatorTest.py	(revision 83eb5208b8acb86b064162274de583670f72da47)
@@ -0,0 +1,103 @@
+import sys
+import unittest
+from PyQt4 import QtGui
+from PyQt4.QtTest import QTest
+from PyQt4.QtCore import Qt
+from mock import MagicMock
+
+# set up import paths
+import sas.qtgui.path_prepare
+
+from sas.qtgui.Calculators.SlitSizeCalculator import SlitSizeCalculator
+from sas.sascalc.dataloader.loader import Loader
+
+app = QtGui.QApplication(sys.argv)
+
+
+class SlitSizeCalculatorTest(unittest.TestCase):
+    """Test the SlitSizeCalculator"""
+    def setUp(self):
+        """Create the SlitSizeCalculator"""
+        self.widget = SlitSizeCalculator(None)
+
+    def tearDown(self):
+        """Destroy the SlitSizeCalculator"""
+        self.widget.close()
+        self.widget = None
+
+    def testDefaults(self):
+        """Test the GUI in its default state"""
+        self.assertIsInstance(self.widget, QtGui.QWidget)
+        self.assertEqual(self.widget.windowTitle(), "Slit Size Calculator")
+        self.assertEqual(self.widget.sizePolicy().Policy(), QtGui.QSizePolicy.Fixed)
+
+    def testHelp(self):
+        """ Assure help file is shown """
+
+        # this should not rise
+        self.widget.onHelp()
+
+    def testBrowseButton(self):
+        browseButton = self.widget.browseButton
+
+        filename = "beam_profile.DAT"
+
+        # Return no files.
+        QtGui.QFileDialog.getOpenFileName = MagicMock(return_value=None)
+
+        # Click on the Browse button
+        QTest.mouseClick(browseButton, Qt.LeftButton)
+
+        # Test the getOpenFileName() dialog called once
+        self.assertTrue(QtGui.QFileDialog.getOpenFileName.called)
+        QtGui.QFileDialog.getOpenFileName.assert_called_once()
+
+        # Now, return a single file
+        QtGui.QFileDialog.getOpenFileName = MagicMock(return_value=filename)
+
+        # Click on the Load button
+        QTest.mouseClick(browseButton, Qt.LeftButton)
+        QtGui.qApp.processEvents()
+
+        # Test the getOpenFileName() dialog called once
+        self.assertTrue(QtGui.QFileDialog.getOpenFileName.called)
+        QtGui.QFileDialog.getOpenFileName.assert_called_once()
+
+
+    def testCalculateSlitSize(self):
+        """ Test slit size calculated value """
+
+        filename = "beam_profile.DAT"
+        loader = Loader()
+        data = loader.load(filename)
+
+        self.widget.calculateSlitSize(data)
+        # The value "5.5858" was obtained by manual calculation.
+        # It turns out our slit length is FWHM/2
+        self.assertAlmostEqual(float(self.widget.slit_length_out.text()), 5.5858/2, 3)
+
+    def testWrongInput(self):
+        """ Test on wrong input data """
+
+        filename = "Dec07031.ASC"
+        loader = Loader()
+        data = loader.load(filename)
+        self.assertRaisesRegexp(RuntimeError,
+                                "Slit Length cannot be computed for 2D Data",
+                                self.widget.calculateSlitSize, data)
+
+        filename = "empty_file.txt"
+        loader = Loader()
+        data = loader.load(filename)
+        self.assertRaisesRegexp(RuntimeError,
+                                "ERROR: Data hasn't been loaded correctly",
+                                self.widget.calculateSlitSize, data)
+
+        data = None
+        self.assertRaisesRegexp(RuntimeError,
+                                "ERROR: Data hasn't been loaded correctly",
+                                self.widget.calculateSlitSize, data)
+
+
+if __name__ == "__main__":
+    unittest.main()
