Changeset 0261bc1 in sasview for src/sas/qtgui/Utilities/UnitTesting
- Timestamp:
- Nov 20, 2017 5:55:30 AM (7 years ago)
- 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:
- f1ec901
- Parents:
- 6a3e1fe
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/qtgui/Utilities/UnitTesting/GuiUtilsTest.py
r53c771e r0261bc1 414 414 self.assertEqual(yscale, "log") 415 415 416 def testParseName(self): 417 '''test parse out a string from the beinning of a string''' 418 # good input 419 value = "_test" 420 self.assertEqual(parseName(value, '_'), 'test') 421 value = "____test____" 422 self.assertEqual(parseName(value, '_'), '___test____') 423 self.assertEqual(parseName(value, '___'), '_test____') 424 self.assertEqual(parseName(value, 'test'), '____test____') 425 # bad input 426 with self.assertRaises(TypeError): 427 parseName(value, None) 428 with self.assertRaises(TypeError): 429 parseName(None, '_') 430 value = [] 431 with self.assertRaises(TypeError): 432 parseName(value, '_') 433 value = 1.44 434 with self.assertRaises(TypeError): 435 parseName(value, 'p') 436 value = 100 437 with self.assertRaises(TypeError): 438 parseName(value, 'p') 439 440 def testToDouble(self): 441 '''test homemade string-> double converter''' 442 #good values 443 value = "1" 444 self.assertEqual(toDouble(value), 1.0) 445 value = "1.2" 446 # has to be AlmostEqual due to numerical rounding 447 self.assertAlmostEqual(toDouble(value), 1.2, 6) 448 value = "2,1" 449 self.assertAlmostEqual(toDouble(value), 2.1, 6) 450 451 # bad values 452 value = None 453 with self.assertRaises(TypeError): 454 toDouble(value) 455 value = "MyDouble" 456 with self.assertRaises(TypeError): 457 toDouble(value) 458 value = [1,2.2] 459 with self.assertRaises(TypeError): 460 toDouble(value) 461 462 463 class DoubleValidatorTest(unittest.TestCase): 464 """ Test the validator for floats """ 465 def setUp(self): 466 '''Create the validator''' 467 self.validator = DoubleValidator() 468 469 def tearDown(self): 470 '''Destroy the validator''' 471 self.validator = None 472 473 def testValidateGood(self): 474 """Test a valid float """ 475 QtCore.QLocale.setDefault(QtCore.QLocale('en_US')) 476 float_good = "170" 477 self.assertEqual(self.validator.validate(float_good, 1)[0], QtGui.QValidator.Acceptable) 478 float_good = "170.11" 479 ## investigate: a double returns Invalid here! 480 ##self.assertEqual(self.validator.validate(float_good, 1)[0], QtGui.QValidator.Acceptable) 481 float_good = "17e2" 482 self.assertEqual(self.validator.validate(float_good, 1)[0], QtGui.QValidator.Acceptable) 483 484 def testValidateBad(self): 485 """Test a bad float """ 486 float_bad = None 487 self.assertEqual(self.validator.validate(float_bad, 1)[0], QtGui.QValidator.Intermediate) 488 float_bad = [1] 489 with self.assertRaises(TypeError): 490 self.validator.validate(float_bad, 1) 491 float_bad = "1,3" 492 self.assertEqual(self.validator.validate(float_bad, 1)[0], QtGui.QValidator.Invalid) 493 494 def notestFixup(self): 495 """Fixup of a float""" 496 float_to_fixup = "1,3" 497 self.validator.fixup(float_to_fixup) 498 self.assertEqual(float_to_fixup, "13") 499 416 500 417 501 class FormulaValidatorTest(unittest.TestCase): … … 434 518 435 519 def testValidateBad(self): 436 """Test a 520 """Test an invalid Formula """ 437 521 formula_bad = "H24 %%%O12C4C6N2Pu" 438 522 self.assertRaises(self.validator.validate(formula_bad, 1)[0]) … … 442 526 self.assertEqual(self.validator.validate(formula_bad, 1)[0], QtGui.QValidator.Intermediate) 443 527 528 class HashableStandardItemTest(unittest.TestCase): 529 """ Test the reimplementation of QStandardItem """ 530 def setUp(self): 531 '''Create the validator''' 532 self.item = HashableStandardItem() 533 534 def tearDown(self): 535 '''Destroy the validator''' 536 self.item = None 537 538 def testHash(self): 539 '''assure the item returns hash''' 540 self.assertEqual(self.item.__hash__(), 0) 541 542 def testIndexing(self): 543 '''test that we can use HashableSI as an index''' 544 dictionary = {} 545 dictionary[self.item] = "wow!" 546 self.assertEqual(dictionary[self.item], "wow!") 547 548 def testClone(self): 549 '''let's see if we can clone the item''' 550 item_clone = self.item.clone() 551 self.assertEqual(item_clone.__hash__(), 0) 444 552 445 553 if __name__ == "__main__":
Note: See TracChangeset
for help on using the changeset viewer.