<commit_before>from pychecker2.TestSupport import WarningTester
from pychecker2 import VariableChecks

class UnusedTestCase(WarningTester):
    def testUnusedBasic(self):
        self.warning('def f(i, j): return i * 2\n',
                     1, VariableChecks.UnusedCheck.unused, 'j')
        self.warning('def _unused(): pass\n',
                     1, VariableChecks.UnusedCheck.unused, '_unused')

    def testUnusedAbstract(self):
        self.silent('def f(i): assert 0\n')
        self.silent('def f(i): assert None\n')
        self.silent('def f(i): return\n')
        self.silent('def f(i): return 7\n')
        self.silent('def f(i): pass\n')
        self.silent('def f(i): raise NotImplementedError\n')

    def testUnusedScopeNotSelf(self):
        self.silent('class A:\n'
                    '  def f(self, j): return j * 2\n')
        self.argv = ['--reportUnusedSelf']
        self.warning('class A:\n'
                     '  def f(self, j): return j * 2\n',
                     2, VariableChecks.UnusedCheck.unused, 'self')

    def testUnusedScope(self):
        self.warning('class A:\n'
                     '  def f(self, j): return self\n', 2,
                     VariableChecks.UnusedCheck.unused, 'j')
        self.silent('def f(a, b):\n'
                    '  def g(x):\n'
                    '     return x * a\n'
                    '  return g(b)\n')

    def testUnusedIgnore(self):
        self.warning('def f(a, xyzzySilly): return a',
                     1, VariableChecks.UnusedCheck.unused, 'xyzzySilly')
        self.argv = ['--unusedPrefixes=["xyzzy"]']
        self.silent('def f(a, xyzzySilly): return a')
                    

    def testGlobal(self):
        self.silent('x = 1\ndef f(x=x): return 7\n')
        self.silent('def f(x):\n'
                    '  global _y\n'
                    '  _y = _y + x\n')

    def testUnpack(self):
        self.silent('_x, _y = 1, 2\n')
        self.silent('def f(a, (b, c)): print a, b\n')
        
        self.argv = ['--no-unpackedUsed']
        self.warning('_x, _y = 1, 2\n'
                     'print _x\n',
                     1, VariableChecks.UnusedCheck.unused, '_y')
        self.warning('def f(a, (b, c)): print a, b\n',
                     1, VariableChecks.UnusedCheck.unused, 'c')

        <commit_msg>add test for empty functions<commit_after>from pychecker2.TestSupport import WarningTester
from pychecker2 import VariableChecks

class UnusedTestCase(WarningTester):
    def testUnusedBasic(self):
        self.warning('def f(i, j): return i * 2\n',
                     1, VariableChecks.UnusedCheck.unused, 'j')
        self.warning('def _unused(): pass\n',
                     1, VariableChecks.UnusedCheck.unused, '_unused')

    def testUnusedAbstract(self):
        self.silent('def f(i): assert 0\n')
        self.silent('def f(i): assert None\n')
        self.silent('def f(i): return\n')
        self.silent('def f(i): return 7\n')
        self.silent('def f(i): pass\n')
        self.silent('def f(i): raise NotImplementedError\n')

    def testUnusedScopeNotSelf(self):
        self.silent('class A:\n'
                    '  def f(self, j): return j * 2\n')
        self.argv = ['--reportUnusedSelf']
        self.warning('class A:\n'
                     '  def f(self, j): return j * 2\n',
                     2, VariableChecks.UnusedCheck.unused, 'self')

    def testUnusedScope(self):
        self.warning('class A:\n'
                     '  def f(self, j): return self\n', 2,
                     VariableChecks.UnusedCheck.unused, 'j')
        self.silent('def f(a, b):\n'
                    '  def g(x):\n'
                    '     return x * a\n'
                    '  return g(b)\n')

    def testUnusedIgnore(self):
        self.warning('def f(a, xyzzySilly): return a',
                     1, VariableChecks.UnusedCheck.unused, 'xyzzySilly')
        self.argv = ['--unusedPrefixes=["xyzzy"]']
        self.silent('def f(a, xyzzySilly): return a')
                    

    def testGlobal(self):
        self.silent('x = 1\ndef f(x=x): return 7\n')
        self.silent('def f(x):\n'
                    '  global _y\n'
                    '  _y = _y + x\n')

    def testUnpack(self):
        self.silent('_x, _y = 1, 2\n')
        self.silent('def f(a, (b, c)): print a, b\n')
        
        self.argv = ['--no-unpackedUsed']
        self.warning('_x, _y = 1, 2\n'
                     'print _x\n',
                     1, VariableChecks.UnusedCheck.unused, '_y')
        self.warning('def f(a, (b, c)): print a, b\n',
                     1, VariableChecks.UnusedCheck.unused, 'c')
        self.silent('def f(a):\n'
                    '   "this is an empty function"\n')

        
{'fraction_non_alphanumeric': 0.14935477046752696, 'fraction_numerical': 0.008462026655383965, 'mean_word_length': 1.6986301369863013, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7456542', 'n_tokens_mistral': 1636, 'n_tokens_neox': 1556, 'n_words': 333}