def test_format_sacred_error(print_traceback, filter_traceback, print_usage, expected): try: raise SacredError('message', print_traceback, filter_traceback, print_usage) except SacredError as e: st = format_sacred_error(e, 'usage') assert re.match(expected, st, re.MULTILINE)
def test_chained_error(): try: try: print(1 / 0) except Exception as e: raise SacredError("Something bad happened") from e except SacredError as e: st = format_sacred_error(e, "usage") assert re.match( r"Traceback \(most recent calls WITHOUT Sacred internals\):\n File " + r"\"[^\"]+?test_exceptions.py\", line \d+, in test_chained_error\n " + r"print\(1 / 0\)\nZeroDivisionError: division by zero\n\nThe above " + r"exception was the direct cause of the following exception:\n\nTraceback " + r"\(most recent calls WITHOUT Sacred internals\):\n File \"[^\"]+?" + r"test_exceptions.py\", line \d+, in test_chained_error\n raise " + r"SacredError\(\"Something bad happened\"\) from e\nsacred.utils." + r"SacredError: Something bad happened\n", st, re.MULTILINE, )
def _readonly(self, *args, **kwargs): raise SacredError(self.message, filter_traceback="always")
def _readonly(self, *args, **kwargs): raise SacredError( "The configuration is read-only in a captured function!", filter_traceback="always", )