Skip to content

Commit

Permalink
Move test next to the Import node case & remove duplicate test.
Browse files Browse the repository at this point in the history
Update `unused-variable` tests.
  • Loading branch information
mbyrnepr2 committed Sep 16, 2022
1 parent 869837d commit 643d7c9
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 25 deletions.
23 changes: 8 additions & 15 deletions tests/functional/g/globals.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,15 @@ def define_constant():


def global_with_import():
"""should only warn for global-statement"""
"""should only warn for global-statement when using `Import` node"""
global sys # [global-statement]
import sys # pylint: disable=import-outside-toplevel
import sys


def global_with_import_from():
"""should only warn for global-statement when using `ImportFrom` node"""
global namedtuple # [global-statement]
from collections import namedtuple


def global_no_assign():
Expand Down Expand Up @@ -75,11 +81,6 @@ def FUNC():

FUNC()

def func():
"""Overriding a global with an import should only throw a global statement error"""
global sys # [global-statement]

import sys

def override_class():
"""Overriding a class should only throw a global statement error"""
Expand All @@ -89,11 +90,3 @@ class CLASS():
pass

CLASS()


# Regression test for https://github.com/PyCQA/pylint/issues/4809
# Don't emit global-variable-not-assigned
def import_it():
global argp, namedtuple
import argparse as argp
from collections import namedtuple
14 changes: 7 additions & 7 deletions tests/functional/g/globals.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ global-variable-not-assigned:23:4:23:14:other:Using global for 'HOP' but no assi
undefined-variable:24:10:24:13:other:Undefined variable 'HOP':UNDEFINED
global-variable-undefined:29:4:29:18:define_constant:Global variable 'SOMEVAR' undefined at the module level:UNDEFINED
global-statement:35:4:35:14:global_with_import:Using the global statement:UNDEFINED
global-variable-not-assigned:41:4:41:19:global_no_assign:Using global for 'CONSTANT' but no assignment is done:UNDEFINED
global-statement:47:4:47:19:global_del:Using the global statement:UNDEFINED
global-statement:54:4:54:19:global_operator_assign:Using the global statement:UNDEFINED
global-statement:61:4:61:19:global_function_assign:Using the global statement:UNDEFINED
global-statement:71:4:71:15:override_func:Using the global statement:UNDEFINED
global-statement:80:4:80:14:func:Using the global statement:UNDEFINED
global-statement:86:4:86:16:override_class:Using the global statement:UNDEFINED
global-statement:41:4:41:21:global_with_import_from:Using the global statement:UNDEFINED
global-variable-not-assigned:47:4:47:19:global_no_assign:Using global for 'CONSTANT' but no assignment is done:UNDEFINED
global-statement:53:4:53:19:global_del:Using the global statement:UNDEFINED
global-statement:60:4:60:19:global_operator_assign:Using the global statement:UNDEFINED
global-statement:67:4:67:19:global_function_assign:Using the global statement:UNDEFINED
global-statement:77:4:77:15:override_func:Using the global statement:UNDEFINED
global-statement:87:4:87:16:override_class:Using the global statement:UNDEFINED
2 changes: 1 addition & 1 deletion tests/functional/u/unused/unused_variable.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def test_global():
variables through imports.
"""
# pylint: disable=redefined-outer-name
global PATH, OS, collections, deque # [global-variable-not-assigned, global-variable-not-assigned]
global PATH, OS, collections, deque # [global-statement]
from os import path as PATH
import os as OS
import collections
Expand Down
3 changes: 1 addition & 2 deletions tests/functional/u/unused/unused_variable.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ unused-import:55:4:55:38:unused_import_from:Unused namedtuple imported from coll
unused-import:59:4:59:40:unused_import_in_function:Unused hexdigits imported from string:UNDEFINED
unused-variable:64:4:64:10:hello:Unused variable 'my_var':UNDEFINED
unused-variable:75:4:75:8:function:Unused variable 'aaaa':UNDEFINED
global-variable-not-assigned:97:4:97:39:test_global:Using global for 'PATH' but no assignment is done:UNDEFINED
global-variable-not-assigned:97:4:97:39:test_global:Using global for 'deque' but no assignment is done:UNDEFINED
global-statement:97:4:97:39:test_global:Using the global statement:UNDEFINED
unused-import:103:4:103:28:test_global:Unused platform imported from sys:UNDEFINED
unused-import:104:4:104:38:test_global:Unused version imported from sys as VERSION:UNDEFINED
unused-import:105:4:105:15:test_global:Unused import this:UNDEFINED
Expand Down

0 comments on commit 643d7c9

Please sign in to comment.