def _store_con_fmodel(self): [ism] = models.inputs4job(self.job.id, input_type="fragility") fmodel = models.FragilityModel( owner=ism.owner, input=ism, lss=["LS1", "LS2"], format="continuous") fmodel.save() models.Ffc( fragility_model=fmodel, taxonomy="RC", ls="LS2", mean="0.35", stddev="0.10", lsi=2).save() models.Ffc( fragility_model=fmodel, taxonomy="RC", ls="LS1", mean="0.20", stddev="0.05", lsi=1).save() models.Ffc( fragility_model=fmodel, taxonomy="RM", ls="LS2", mean="0.40", stddev="0.12", lsi=2).save() models.Ffc( fragility_model=fmodel, taxonomy="RM", ls="LS1", mean="0.25", stddev="0.08", lsi=1).save() return fmodel
def test_ffc_with_duplicate_ls_and_taxonomy(self): # continuous fragility function with duplicate limit state and taxonomy # -> exception ffc = models.Ffc(fragility_model=self.mdl, ls="a", taxonomy="T1", mean=0.4, stddev=12.1, lsi=1) ffc.save() self.assertIs(self.mdl, ffc.fragility_model) self.assertEqual("T1", ffc.taxonomy) self.assertEqual("a", ffc.ls) self.assertEqual(1, ffc.lsi) self.assertEqual(0.4, ffc.mean) self.assertEqual(12.1, ffc.stddev) ffc2 = models.Ffc(fragility_model=self.mdl, ls="a", taxonomy="T1", mean=0.41, stddev=12.12, lsi=1) try: ffc2.save() except DatabaseError, de: self.assertTrue( 'duplicate key value violates unique constraint ' '"ffc_fragility_model_id_taxonomy_lsi_key"' in de.args[0]) transaction.rollback()
def test_ffc_with_invalid_ls(self): # continuous fragility function and invalid limit state -> exception ffc = models.Ffc(fragility_model=self.mdl, ls="xyz", lsi=1) try: ffc.save() except DatabaseError, de: self.assertTrue('Invalid limit state' in de.args[0]) transaction.rollback()
def test_ffc_with_discrete_model(self): # continuous fragility function and discrete model -> exception ffc = models.Ffc(fragility_model=self.discrete_mdl, ls="d", lsi=1) try: ffc.save() except DatabaseError, de: self.assertTrue('mismatch: discrete model but continuous function' in de.args[0]) transaction.rollback()
def test_ffc_with_invalid_lsi(self): # continuous fragility function with a limit state that's off by one # -> exception ffc = models.Ffc(fragility_model=self.mdl, ls="a", taxonomy="T1", mean=0.4, stddev=12.1, lsi=2) try: ffc.save() except DatabaseError, de: self.assertTrue( 'Invalid limit state index (2) for ffc(T1, a)' in de.args[0]) transaction.rollback()
def test_ffc(self): # continuous fragility function with good data is inserted OK. ffc = models.Ffc(fragility_model=self.mdl, ls="a", taxonomy="T1", mean=0.4, stddev=12.1, lsi=1) ffc.save() self.assertIs(self.mdl, ffc.fragility_model) self.assertEqual("T1", ffc.taxonomy) self.assertEqual("a", ffc.ls) self.assertEqual(1, ffc.lsi) self.assertEqual(0.4, ffc.mean) self.assertEqual(12.1, ffc.stddev)