本文整理汇总了Python中test.warning_tests.inner函数的典型用法代码示例。如果您正苦于以下问题:Python inner函数的具体用法?Python inner怎么用?Python inner使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了inner函数的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_filename
def test_filename(self):
with warnings_state(self.module):
with original_warnings.catch_warnings(record=True, module=self.module) as w:
warning_tests.inner("spam1")
self.assertEqual(os.path.basename(w[-1].filename), "warning_tests.py")
warning_tests.outer("spam2")
self.assertEqual(os.path.basename(w[-1].filename), "warning_tests.py")
示例2: test_missing_filename_not_main
def test_missing_filename_not_main(self):
# If __file__ is not specified and __main__ is not the module name,
# then __file__ should be set to the module name.
filename = warning_tests.__file__
try:
del warning_tests.__file__
with warnings_state(self.module):
with original_warnings.catch_warnings(record=True, module=self.module) as w:
warning_tests.inner("spam8", stacklevel=1)
self.assertEqual(w[-1].filename, warning_tests.__name__)
finally:
warning_tests.__file__ = filename
示例3: test_missing_filename_main_with_argv
def test_missing_filename_main_with_argv(self):
# If __file__ is not specified and the caller is __main__ and sys.argv
# exists, then use sys.argv[0] as the file.
filename = warning_tests.__file__
module_name = warning_tests.__name__
try:
del warning_tests.__file__
warning_tests.__name__ = "__main__"
with warnings_state(self.module):
with original_warnings.catch_warnings(record=True, module=self.module) as w:
warning_tests.inner("spam9", stacklevel=1)
self.assertEqual(w[-1].filename, sys.argv[0])
finally:
warning_tests.__file__ = filename
warning_tests.__name__ = module_name
示例4: test_show_source_line
def test_show_source_line(self):
import warnings
import sys, StringIO
from test.warning_tests import inner
# With showarning() missing, make sure that output is okay.
del warnings.showwarning
stderr = sys.stderr
try:
sys.stderr = StringIO.StringIO()
inner('test message')
result = sys.stderr.getvalue()
finally:
sys.stderr = stderr
assert result.count('\n') == 2
assert ' warnings.warn(message, ' in result
示例5: test_missing_filename_main_without_argv
def test_missing_filename_main_without_argv(self):
# If __file__ is not specified, the caller is __main__, and sys.argv
# is not set, then '__main__' is the file name.
filename = warning_tests.__file__
module_name = warning_tests.__name__
argv = sys.argv
try:
del warning_tests.__file__
warning_tests.__name__ = "__main__"
del sys.argv
with warnings_state(self.module):
with original_warnings.catch_warnings(record=True, module=self.module) as w:
warning_tests.inner("spam10", stacklevel=1)
self.assertEqual(w[-1].filename, "__main__")
finally:
warning_tests.__file__ = filename
warning_tests.__name__ = module_name
sys.argv = argv
示例6: test_missing_filename_main_with_argv_empty_string
def test_missing_filename_main_with_argv_empty_string(self):
# If __file__ is not specified, the caller is __main__, and sys.argv[0]
# is the empty string, then '__main__ is the file name.
# Tests issue 2743.
file_name = warning_tests.__file__
module_name = warning_tests.__name__
argv = sys.argv
try:
del warning_tests.__file__
warning_tests.__name__ = "__main__"
sys.argv = [""]
with warnings_state(self.module):
with original_warnings.catch_warnings(record=True, module=self.module) as w:
warning_tests.inner("spam11", stacklevel=1)
self.assertEqual(w[-1].filename, "__main__")
finally:
warning_tests.__file__ = file_name
warning_tests.__name__ = module_name
sys.argv = argv
示例7: test_show_warning_output
def test_show_warning_output(self):
# With showarning() missing, make sure that output is okay.
text = "test show_warning"
with original_warnings.catch_warnings(module=self.module):
self.module.filterwarnings("always", category=UserWarning)
del self.module.showwarning
with support.captured_output("stderr") as stream:
warning_tests.inner(text)
result = stream.getvalue()
self.assertEqual(result.count("\n"), 2, "Too many newlines in %r" % result)
first_line, second_line = result.split("\n", 1)
expected_file = os.path.splitext(warning_tests.__file__)[0] + ".py"
first_line_parts = first_line.rsplit(":", 3)
path, line, warning_class, message = first_line_parts
line = int(line)
self.assertEqual(expected_file, path)
self.assertEqual(warning_class, " " + UserWarning.__name__)
self.assertEqual(message, " " + text)
expected_line = " " + linecache.getline(path, line).strip() + "\n"
assert expected_line
self.assertEqual(second_line, expected_line)
示例8: test_stacklevel
def test_stacklevel(self):
# Test stacklevel argument
# make sure all messages are different, so the warning won't be skipped
with warnings_state(self.module):
with original_warnings.catch_warnings(record=True,
module=self.module) as w:
warning_tests.inner("spam3", stacklevel=1)
self.assertEqual(os.path.basename(w[-1].filename),
"warning_tests.py")
warning_tests.outer("spam4", stacklevel=1)
self.assertEqual(os.path.basename(w[-1].filename),
"warning_tests.py")
warning_tests.inner("spam5", stacklevel=2)
self.assertEqual(os.path.basename(w[-1].filename),
"test_warnings.py")
warning_tests.outer("spam6", stacklevel=2)
self.assertEqual(os.path.basename(w[-1].filename),
"warning_tests.py")
warning_tests.outer("spam6.5", stacklevel=3)
self.assertEqual(os.path.basename(w[-1].filename),
"test_warnings.py")
warning_tests.inner("spam7", stacklevel=9999)
self.assertEqual(os.path.basename(w[-1].filename),
"sys")