def _mock_defuzzifyModel(self, defuzzify_type, init_kwargs={}): self.defuzzify_type = defuzzify_type self.defuzzify = DefuzzifyModel(defuzzify=defuzzify_type) self.parameters_mock = [] for arg_name, arg_value in init_kwargs.items(): self.parameters_mock.append( self._parameters_mock(name=arg_name, value=arg_value)) # mocking parameters (queryset) parameters_queryset = mock.Mock() parameters_queryset.all = lambda: self.parameters_mock self.set_pre_mock(DefuzzifyModel, 'parameters') DefuzzifyModel.parameters = parameters_queryset # # mocking inf # self.set_pre_mock(DefuzzifyModel,'inf') # DefuzzifyModel.inf = self._norm_mock("inf") # # mocking acc # self.set_pre_mock(DefuzzifyModel,'acc') # DefuzzifyModel.acc = self._norm_mock("acc") return self.defuzzify
def test_defuzzify_from_pyfuzzy_for_dict_type(self): " shoud return the correct corresponding DefuzzifyModel for the Dict pyfuzzy object " pyfuzzy_defuzzify = Dict() new_defuzzify = DefuzzifyModel.from_pyfuzzy(pyfuzzy_defuzzify) pyfuzzy_defuzzify_full_namespace = pyfuzzy_defuzzify.__module__ pyfuzzy_defuzzify_full_namespace += "." + pyfuzzy_defuzzify.__class__.__name__ # are from the same class self.assertEquals(pyfuzzy_defuzzify_full_namespace, new_defuzzify.defuzzify)
def test_defuzzify_from_pyfuzzy_for_rm_type(self): " shoud return the correct corresponding DefuzzifyModel for the RM pyfuzzy object " init_kwargs = { 'failsafe': 1, } pyfuzzy_defuzzify = RM(**init_kwargs) new_defuzzify = DefuzzifyModel.from_pyfuzzy(pyfuzzy_defuzzify) pyfuzzy_defuzzify_full_namespace = pyfuzzy_defuzzify.__module__ pyfuzzy_defuzzify_full_namespace += "." + pyfuzzy_defuzzify.__class__.__name__ # are from the same class self.assertEquals(pyfuzzy_defuzzify_full_namespace, new_defuzzify.defuzzify) # have the same args self.assertEquals(1, new_defuzzify.parameters.all().count()) failsafe_param = new_defuzzify.parameters.get(name='failsafe') self.assertEquals(1.0, failsafe_param.get_value())