MCPcopy Create free account
hub / github.com/NVIDIA/DALI / assert_raises

Function assert_raises

dali/test/python/nose_utils.py:95–133  ·  view source on GitHub ↗

Wrapper combining unittest assertRaises and assertRaisesRegex. Specify ``regex=pattern`` or ``glob=pattern`` to check error message of expected exception against the pattern. Value for `glob` must be a string, `regex` can be either a literal or compiled regex pattern. By default

(exception, *args, glob=None, regex=None, match_case=None, **kwargs)

Source from the content-addressed store, hash-verified

93
94
95def assert_raises(exception, *args, glob=None, regex=None, match_case=None, **kwargs):
96 """
97 Wrapper combining unittest assertRaises and assertRaisesRegex.
98 Specify ``regex=pattern`` or ``glob=pattern`` to check error message of expected exception
99 against the pattern.
100 Value for `glob` must be a string, `regex` can be either a literal or compiled regex pattern.
101 By default, the check will ignore case, if called with `glob` or a literal for `regex`.
102 To enforce case sensitive check pass ``match_case=True``.
103 Don't specify `match_case` if passing already compiled regex pattern.
104
105 Can be used as context manager or with callable:
106 with assert_raises(Exception):
107 raise Exception()
108
109 assert_raises(Exception, callable, arg1, arg2, kwarg=value)
110 """
111 if glob is None and regex is None:
112 # Use unittest's assertRaises
113 if args:
114 # Called with callable: assert_raises(Exception, callable, *args, **kwargs)
115 callable_func = args[0]
116 callable_args = args[1:]
117 with _test_case.assertRaises(exception):
118 callable_func(*callable_args, **kwargs)
119 else:
120 # Used as context manager
121 return _test_case.assertRaises(exception)
122 else:
123 pattern = get_pattern(glob, regex, match_case)
124 # Use unittest's assertRaisesRegex
125 if args:
126 # Called with callable
127 callable_func = args[0]
128 callable_args = args[1:]
129 with _test_case.assertRaisesRegex(exception, pattern):
130 callable_func(*callable_args, **kwargs)
131 else:
132 # Used as context manager
133 return _test_case.assertRaisesRegex(exception, pattern)
134
135
136def assert_warns(exception=Warning, *args, glob=None, regex=None, match_case=None, **kwargs):

Callers 15

__test_empty_esFunction · 0.90
test_api_fw_check1Function · 0.90
test_api_fw_check2Function · 0.90
test_move_to_device_endFunction · 0.90
check_bad_deviceFunction · 0.90
test_arithm_ops_cpu_gpuFunction · 0.90

Calls 1

get_patternFunction · 0.85

Tested by 15

__test_empty_esFunction · 0.72
test_api_fw_check1Function · 0.72
test_api_fw_check2Function · 0.72
test_move_to_device_endFunction · 0.72
check_bad_deviceFunction · 0.72
test_arithm_ops_cpu_gpuFunction · 0.72