def test_deprecated_missing_args(self):
    date = "2016-07-04"
    instructions = "This is how you update..."

    def _fn(arg0, arg1, deprecated=None):
      return arg0 + arg1 if deprecated else arg1 + arg0

    # Assert calls without the deprecated argument log nothing.
    with self.assertRaisesRegexp(ValueError, "not present.*\\['missing'\\]"):
      deprecation.deprecated_args(date, instructions, "missing")(_fn)
Beispiel #2
0
  def test_deprecated_missing_args(self):
    date = "2016-07-04"
    instructions = "This is how you update..."

    def _fn(arg0, arg1, deprecated=None):
      return arg0 + arg1 if deprecated else arg1 + arg0

    # Assert calls without the deprecated argument log nothing.
    with self.assertRaisesRegexp(ValueError, "not present.*\\['missing'\\]"):
      deprecation.deprecated_args(date, instructions, "missing")(_fn)
 def test_deprecated_illegal_args(self):
   instructions = "This is how you update..."
   date = "2016-07-04"
   with self.assertRaisesRegexp(ValueError, "YYYY-MM-DD"):
     deprecation.deprecated_args("", instructions, "deprecated")
   with self.assertRaisesRegexp(ValueError, "YYYY-MM-DD"):
     deprecation.deprecated_args("07-04-2016", instructions, "deprecated")
   with self.assertRaisesRegexp(ValueError, "instructions"):
     deprecation.deprecated_args(date, None, "deprecated")
   with self.assertRaisesRegexp(ValueError, "instructions"):
     deprecation.deprecated_args(date, "", "deprecated")
   with self.assertRaisesRegexp(ValueError, "argument"):
     deprecation.deprecated_args(date, instructions)
Beispiel #4
0
 def test_deprecated_illegal_args(self):
   instructions = "This is how you update..."
   date = "2016-07-04"
   with self.assertRaisesRegexp(ValueError, "YYYY-MM-DD"):
     deprecation.deprecated_args("", instructions, "deprecated")
   with self.assertRaisesRegexp(ValueError, "YYYY-MM-DD"):
     deprecation.deprecated_args("07-04-2016", instructions, "deprecated")
   with self.assertRaisesRegexp(ValueError, "instructions"):
     deprecation.deprecated_args(date, None, "deprecated")
   with self.assertRaisesRegexp(ValueError, "instructions"):
     deprecation.deprecated_args(date, "", "deprecated")
   with self.assertRaisesRegexp(ValueError, "argument"):
     deprecation.deprecated_args(date, instructions)
Beispiel #5
0
 def safe_trace_fn(traceable_quantities):
   """A `trace_fn that takes the single `minimizer_state` argument."""
   try:
     return trace_fn(traceable_quantities)
   except TypeError:
     deprecated_trace_fn = deprecation.deprecated_args(
         '2020-07-01',
         'The signature for `trace_fn`s passed to `minimize` has changed. '
         'Trace functions now take a single `traceable_quantities` argument, '
         'which is a `tfp.math.MinimizeTraceableQuantities` namedtuple '
         'containing `traceable_quantities.loss`, '
         '`traceable_quantities.gradients`, etc. '
         'Please update your `trace_fn` definition.',
         ('loss', 'grads', 'variables')
     )(trace_fn)
     return deprecated_trace_fn(
         traceable_quantities.loss,
         traceable_quantities.gradients,
         traceable_quantities.parameters)