def variable_set(self, val):
     old_value = Gaussian(pi=self.pi, tau=self.tau)
     old_messages = {
         fac: Gaussian(pi=msg.pi, tau=msg.tau)
         for fac, msg in self.messages.items()
     }
     delta = orig_variable_set(self, val)
     # inspect outer frames
     frames = inspect.getouterframes(inspect.currentframe())
     methods = [None, None]
     for frame in frames:
         method = frame[3]
         if method.startswith('update_'):
             methods[0] = method
         elif method in ('up', 'down'):
             methods[1] = method
             break
     factor = frame[0].f_locals['self']
     before = Gaussian(pi=self.pi, tau=self.tau)
     # helpers for logging
     logs = []
     l = logs.append
     bullet = lambda changed: colored(' * ', 'red') if changed else '   '
     # print layer
     if getattr(logger, '_prev_layer_name', None) != factor._layer_name:
         logger._prev_layer_name = factor._layer_name
         l(colored('[{}]'.format(factor._layer_name), 'blue'))
     # print factor
     l(colored('<{}.{}>'.format(r(factor), methods[1]), 'cyan'))
     # print value
     if old_value == self:
         line = '{}'.format(r(self))
     else:
         line = '{} -> {}'.format(r(old_value), r(self))
     l(bullet(methods[0] == 'update_value') + line)
     # print messages
     fmt = '{}: {} -> {}'.format
     for fac, msg in self.messages.items():
         old_msg = old_messages[fac]
         changed = fac is factor and methods[0] == 'update_message'
         if old_msg == msg:
             line = '{}: {}'.format(r(fac), r(msg))
         else:
             line = '{}: {} -> {}'.format(r(fac), r(old_msg), r(msg))
         l(bullet(changed) + line)
     # print buffered logs
     map(logger.debug, logs)
     return delta
def test_valid_gaussian():
    from trueskill.mathematics import Gaussian
    with raises(TypeError):  # sigma argument is needed
        Gaussian(0)
    with raises(ValueError):  # sigma**2 should be greater than 0
        Gaussian(0, 0)