Staging
v0.5.1
https://github.com/python/cpython
Revision c0e77364ca29df6cfb311e79892955c92bd8e595 authored by Victor Stinner on 12 September 2017, 23:09:44 UTC, committed by GitHub on 12 September 2017, 23:09:44 UTC
* bpo-30923: Disable warning that has been part of -Wextra since gcc-7.0. (#3142)

(cherry picked from commit d73a960c575207539c3f9765cff26d4fff400b45)

* bpo-30923: Silence fall-through warnings included in -Wextra since gcc-7.0. (#3157)

(cherry picked from commit f432a3234f9f2ee09bd40be03e06bf72865ee375)

* bpo-31275: Small refactoring to silence a fall-through warning. (#3206)

(cherry picked from commit 138753c1b96b5e06a5c5d409fa4cae5e2fe1108b)
1 parent 5013a5e
Raw File
Tip revision: c0e77364ca29df6cfb311e79892955c92bd8e595 authored by Victor Stinner on 12 September 2017, 23:09:44 UTC
[3.6] bpo-30923: Silence fall-through warnings included in -Wextra since gcc-7.0 (#3518)
Tip revision: c0e7736
test_global.py
"""Verify that warnings are issued for global statements following use."""

from test.support import run_unittest, 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=4)

    def test2(self):
        prog_text_2 = """\
def wrong2():
    print(x)
    global x
"""
        check_syntax_error(self, prog_text_2, lineno=3, offset=4)

    def test3(self):
        prog_text_3 = """\
def wrong3():
    print(x)
    x = 2
    global x
"""
        check_syntax_error(self, prog_text_3, lineno=4, offset=4)

    def test4(self):
        prog_text_4 = """\
global x
x = 2
"""
        # this should work
        compile(prog_text_4, "<test string>", "exec")


def test_main():
    with warnings.catch_warnings():
        warnings.filterwarnings("error", module="<test string>")
        run_unittest(GlobalTests)

if __name__ == "__main__":
    test_main()
back to top