Server IP : 103.191.208.50 / Your IP : 216.73.216.226 Web Server : LiteSpeed System : Linux orion.herosite.pro 4.18.0-553.53.1.lve.el8.x86_64 #1 SMP Wed May 28 17:01:02 UTC 2025 x86_64 User : celkcksm ( 1031) PHP Version : 5.6.40 Disable Function : show_source, system, shell_exec, passthru, exec MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON Directory (0755) : /home/../opt/bitninja-python-dojo/embedded/lib/python3.9/test/ |
[ Home ] | [ C0mmand ] | [ Upload File ] |
---|
"""Verify that warnings are issued for global statements following use.""" from test.support import check_syntax_error, check_warnings import unittest import warnings class GlobalTests(unittest.TestCase): def setUp(self): self._warnings_manager = check_warnings() self._warnings_manager.__enter__() warnings.filterwarnings("error", module="<test string>") def tearDown(self): self._warnings_manager.__exit__(None, None, None) def test1(self): prog_text_1 = """\ def wrong1(): a = 1 b = 2 global a global b """ check_syntax_error(self, prog_text_1, lineno=4, offset=5) def test2(self): prog_text_2 = """\ def wrong2(): print(x) global x """ check_syntax_error(self, prog_text_2, lineno=3, offset=5) def test3(self): prog_text_3 = """\ def wrong3(): print(x) x = 2 global x """ check_syntax_error(self, prog_text_3, lineno=4, offset=5) def test4(self): prog_text_4 = """\ global x x = 2 """ # this should work compile(prog_text_4, "<test string>", "exec") def setUpModule(): cm = warnings.catch_warnings() cm.__enter__() unittest.addModuleCleanup(cm.__exit__, None, None, None) warnings.filterwarnings("error", module="<test string>") if __name__ == "__main__": unittest.main()