def __call__(self):
        
        try:
            obs = self.parse_observable()
            exp = self.parse_expected()
        except IOError as e:
            inform("Input/output error when\
                   checking for observable data: %s" % e)
            return False
        
        try:
            tolerance = float(self.observable['tolerance'])
        except (TypeError, KeyError):  # observable can be None
            tolerance = 1e-1

        are_close, best_tol = ts.compare_arrays((obs, exp), tolerance)

        if not are_close:
	    pretty_obs, pretty_exp = ts.pretty_print_copypaste(obs,exp)
            inform("Comparison of \n\
                    (observed data): %s\n\
                    and\n\
                    (expected data): %s\n\
                    failed against tolerance %g" %
                   (pretty_obs, pretty_exp, tolerance))
            if best_tol:
                inform("A better tolerance to try is: ", best_tol, indent=1)
        else:
            if best_tol and best_tol < tolerance:
                inform("Passed, but an even better tolerance might be: %f, as opposed to: %f" % (best_tol, tolerance), indent=3, verbosity=1)
        return are_close
Пример #2
0
    def __call__(self):

        try:
            obs = self.parse_observable()
            if obs is None:
                inform("Could not determine observed values")
                return False
            if isinstance(obs, list):
                for o in obs:
                    if not o:
                        inform("Could not determine observed values")
                        return False

            exp = self.parse_expected()

            if exp is None:
                inform("Could not determine expected values")
                return False
            if isinstance(exp, list):
                for e in exp:
                    if not e:
                        inform("Could not determine expected values")
                        return False
        except IOError as e:
            inform("Input/output error when\
                   checking for observable data: %s" % e)
            return False

        try:
            tolerance = float(self.observable['tolerance'])
        except (TypeError, KeyError):  # observable can be None
            tolerance = 1e-1

        are_close, best_tol = ts.compare_arrays((obs, exp), tolerance)

        if not are_close:
            pretty_obs, pretty_exp = ts.pretty_print_copypaste(obs, exp)
            inform("Comparison of \n\
                    (observed data): %s\n\
                    and\n\
                    (expected data): %s\n\
                    failed against tolerance %g" %
                   (pretty_obs, pretty_exp, tolerance))
            if best_tol:
                inform("A better tolerance to try is: ", best_tol, indent=1)
        else:
            if best_tol and best_tol < tolerance:
                inform(
                    "Passed, but an even better tolerance might be: %f, as opposed to: %f"
                    % (best_tol, tolerance),
                    indent=3,
                    verbosity=1)
        return are_close
Пример #3
0
    def __call__(self):
        obs = self.parse_observable()
        exp = self.parse_expected()
        try: 
            tolerance = float(self.observable['tolerance'])
        except (TypeError, KeyError): #observable can be None 
            tolerance =  1e-1

        are_close = ts.compare_arrays((obs, exp), tolerance)
        if not are_close:
            inform('Comparison of \n%s\nand\n%s\nfailed against tolerance %g'%(obs,exp, tolerance))
        
        return are_close
Пример #4
0
    def __call__(self):
        obs = self.parse_observable()
        exp = self.parse_expected()
        try:
            tolerance = float(self.observable['tolerance'])
        except (TypeError, KeyError) as e:  #observable can be None
            tolerance = 1e-1

        are_close = ts.compare_arrays((obs, exp), tolerance)
        if not are_close:
            inform(
                'Comparison of \n %s \n and \n %s \n failed against tolerance %g'
                % (obs, exp, tolerance))

        return are_close
Пример #5
0
    def __call__(self):

        try:
            obs = self.parse_observable()
            exp = self.parse_expected()
        except IOError as e:
            inform(
                "Input/output error when\
                   checking for observable data: %s"
                % e
            )
            return False

        try:
            tolerance = float(self.observable["tolerance"])
        except (TypeError, KeyError):  # observable can be None
            tolerance = 1e-1

        are_close, best_tol = ts.compare_arrays((obs, exp), tolerance)
        if not are_close:
            suggest_tol = True
            try:  # making it easier to copy/paste lists
                pretty_obs = [float(el) for el in obs]
                pretty_exp = [float(el) for el in exp]
                suggest_tol = len(obs) == len(exp)
            except TypeError:  # obs,exp can be singletons
                pretty_obs, pretty_exp = map(float, (obs, exp))
            inform(
                "Comparison of \n\
                    (observed data): %s\n\
                    and\n\
                    (expected data): %s\n\
                    failed against tolerance %g"
                % (pretty_obs, pretty_exp, tolerance)
            )
            if suggest_tol:
                inform("A better tolerance to try is: ", best_tol, indent=1)
        else:
            if best_tol < tolerance:
                inform(
                    "Passed, but an even better tolerance might be: %f, as opposed to: %f" % (best_tol, tolerance),
                    indent=3,
                    verbosity=1,
                )
        return are_close
Пример #6
0
    def __call__(self):

        try:
            obs = self.parse_observable()
            exp = self.parse_expected()
        except IOError as e:
            inform("Input/output error when\
                   checking for observable data: %s" % e)
            return False

        try:
            tolerance = float(self.observable['tolerance'])
        except (TypeError, KeyError):  # observable can be None
            tolerance = 1e-1

        are_close, best_tol = ts.compare_arrays((obs, exp), tolerance)
        if not are_close:
            suggest_tol = True
            try:  # making it easier to copy/paste lists
                pretty_obs = [float(el) for el in obs]
                pretty_exp = [float(el) for el in exp]
                suggest_tol = len(obs) == len(exp)
            except TypeError:  # obs,exp can be singletons
                pretty_obs, pretty_exp = map(float, (obs, exp))
            inform("Comparison of \n\
                    (observed data): %s\n\
                    and\n\
                    (expected data): %s\n\
                    failed against tolerance %g" %
                   (pretty_obs, pretty_exp, tolerance))
            if suggest_tol:
                inform("A better tolerance to try is: ", best_tol, indent=1)
        else:
            if best_tol < tolerance:
                inform(
                    "Passed, but an even better tolerance might be: %f, as opposed to: %f"
                    % (best_tol, tolerance),
                    indent=3,
                    verbosity=1)
        return are_close