unused.py :  » Development » PyChecker » pychecker-0.8.18 » pychecker2 » utest » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » Development » PyChecker 
PyChecker » pychecker 0.8.18 » pychecker2 » utest » unused.py
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')
        self.silent('def f(x):\n'
                    '  def g():\n'
                    '     x.y.z, = 1\n'
                    '  g()\n')

    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\n',
                     1, VariableChecks.UnusedCheck.unused, 'xyzzySilly')
        self.argv = ['--unusedPrefixes=["xyzzy"]']
        self.silent('def f(a, xyzzySilly): return a\n')
                    

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

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

    def testUsedBeforeSet(self):
        w = VariableChecks.UsedBeforeSetCheck.usedBeforeDefined
        self.warning('G1 = 1\n'
                     'def f(L1, (L2, L3)):\n'
                     '  x = 1\n'
                     '  if G1:\n'
                     '    y = 2\n'
                     '  if G1:\n'
                     '    z = 1\n'
                     '    y = 2\n'
                     '  else:\n'
                     '    z = 2\n'
                     '  return L1, L2, L3, x, y, z\n',
                     11, w, 'y')
        self.silent('def f():\n'
                    '  import sys\n'
                    '  return sys.argv\n')
        self.silent('def f():\n'
                    '  from sys import argv\n'
                    '  return argv\n')
        self.silent('def f():\n'
                    '  from sys import *\n'
                    '  return argv\n')
        self.silent('def f():\n'
                    '  return [(a, b) for a, b in [(1,2)]]\n')
        self.silent('def f():\n'
                    '  r = [(a, b) for a, b in [(1,2)]]\n'
                    '  return r, a, b\n')
        self.silent('import pychecker2.utest\n'
                    'print pychecker2.utest.data.exceptions.Warning()')
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.