Пример #1
0
 def check(self, fn):
     assert self._test_cases, "Oops, someone forgot to write test cases."
     for args, expected in self._test_cases:
         orig_args = args
         # Wrap in tuple if necessary
         if not isinstance(args, tuple):
             args = args,
         # XXX: ugh, need to guard against mutation :(
         # Beware of more exotic mutable types (which lack a copy method, or which
         # require a deep copy). Maybe this shouldn't be handled at this level -
         # maybe cleaner to have a method that can repeatedly spit out fresh lists
         # of test cases every time it's called, rather than having test cases be
         # a static attribute.
         args = [(arg.copy() if hasattr(arg, 'copy') else arg)
                 for arg in args]
         orig_args = [(arg.copy() if hasattr(arg, 'copy') else arg)
                      for arg in args]
         try:
             actual = fn(*args)
         except Exception as e:
             raise UserlandExceptionIncorrect(e, orig_args)
         assert not (actual is None and expected is not None), (
             "Got a return value of `None`"
             " given {}, but expected a value of type `{}`. (Did you forget a `return` statement?)"
         ).format(utils.format_args(fn, orig_args),
                  type(expected).__name__)
         assert actual == expected, (
             "Expected return value of `{}` given {},"
             " but got `{}` instead.").format(
                 repr(expected), utils.format_args(fn, orig_args),
                 repr(actual))
Пример #2
0
 def check(self, *args):
     expected = self.canonical_prepared(*args)
     actual = self.ill_prepared(*args)
     assert actual != expected, ("Given {}, `prepared_for_weather` returned"
             " `{}`. But I think that's correct. (We want inputs that lead to"
             " an incorrect result from `prepared_for_weather`.)").format(
                     format_args(self.ill_prepared, args),
                     repr(actual),
                     )