def testsetndx(self): """ We test setting the index of the change. Since the ndx can only be set once, we test to make sure the ndx doesn't change when we set it again. We also try setting an invalid object type. """ change = Change() # -------- Test invalid object type self.assertRaises(ValueError, setattr, change, "ndx", "foo") # --------- Test valid type and ndx change.ndx = 5 self.assertEqual(change.ndx, 5, msg="Unable to set change index") # -------- Test setting ndx again change.ndx = 3000 self.assertEqual(change.ndx, 5, msg="Changed index after initial set") # -------- Test deleter of ndx del change.ndx self.assertIs(change.ndx, None, msg="Deleter failed to delete ndx")
def testaddatomicchange(self): """ Here we test the add_atomic_change method. We attempt to add a change with an index, without and index, with a valid change type and with an invalid change type. We also set an ndx and try to set the ndx via this method to make sure that the ndx is not overridden. """ change = Change() # ---------- Test invalid change type (non-dictionary) self.assertRaises(ValueError, change.add_atomic_change, "CHANGE") # ---------- Test valid change type with ndx valid_change = {"parameters/Run_Number": 5} change.add_atomic_change(valid_change, ndx=5) self.assertEqual(change.change_list[0], valid_change, msg="Failed to set atomic change") # ---------- Test valid change with ndx after ndx already set change2 = Change() change2.ndx = 1 change2.add_atomic_change(valid_change, ndx=5) self.assertEqual(change2.ndx, 1, msg="Set index after initial set") self.assertEqual(change2.change_list[0], valid_change, msg="Failed to set atomic change")