testglobals.py :  » Language-Interface » VB-to-Python-Converter » vb2py-0.2 » test » 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 » Language Interface » VB to Python Converter 
VB to Python Converter » vb2py 0.2 » test » testglobals.py
# Created by Leo from: C:\Development\Python22\Lib\site-packages\vb2py\vb2py.leo

from unittest import *
import vb2py.vbparser

class TestGlobals(TestCase):
  # << Globals tests >> (1 of 8)
  def setUp(self):
    """Set up our tests"""
    self.proj = vb2py.vbparser.VBProject()
    self.utils = vb2py.vbparser.VBCodeModule(modulename="utils")
    self.base = vb2py.vbparser.VBCodeModule(modulename="base")
    self.cls = vb2py.vbparser.VBClassModule(modulename="cls", classname="Cls")
    #
    self.utils.parent = self.base.parent = self.cls.parent = self.proj        
    #
    self.utils = vb2py.vbparser.parseVB("""
    Public x, y, z
    Private one, two, three

    Public Function Fact(x)
      Fact=1
    End Function
    """, container=self.utils)
    #
    self.base = vb2py.vbparser.parseVB("""
    Public a, b, c
    Private four, five, six

    Public Sub DoIt(a, b, x, y, h)
      x = 1
      y = 1
    End Sub
    """, container=self.base)
    #
  # << Globals tests >> (2 of 8)
  def testSimpleOneLookup(self):
    """testSimpleOneLookup: simple lookup of globals from one location"""
    py = vb2py.vbparser.parseVB("""
    Sub Run()
      m = x
      n = y
      o = z
    End Sub
    """, container=self.cls)
    #
    python = py.renderAsCode()
    #
    for converted in ("utils.x", "utils.y", "utils.z"):
      self.assertNotEqual(python.find(converted), -1, python)

  def testSimpleTwoLookups(self):
    """testSimpleTwoLookups: simple lookup of globals from two locations"""
    py = vb2py.vbparser.parseVB("""
    Sub Run()
      a = x
      b = y
      c = z
    End Sub
    """, container=self.cls)
    #
    python = py.renderAsCode()
    #
    for converted in ("utils.x", "utils.y", "utils.z",
              "base.a", "base.b", "base.c"):
      self.assertNotEqual(python.find(converted), -1, python)
  # << Globals tests >> (3 of 8)
  def testSimpleNoLookup(self):
    """testSimpleNoLookup: don't lookup private variables"""
    py = vb2py.vbparser.parseVB("""
    Sub Run()
      one = two
      three = four
      five = six
    End Sub
    """, container=self.cls)
    #
    python = py.renderAsCode()
    #
    for converted in (".one", ".two", ".three", ".four", ".five", ".six"):
      self.assertEqual(python.find(converted), -1, python)
  # << Globals tests >> (4 of 8)
  def testLocalsShadowGlobals(self):
    """testLocalsShadowGlobals: locals will shadow globals"""
    py = vb2py.vbparser.parseVB("""
    Sub Run()
      Dim a, b, x, y
      a = x
      b = y
      c = z
    End Sub
    """, container=self.cls)
    #
    python = py.renderAsCode()
    #
    for converted in ("utils.z", "base.c"):
      self.assertNotEqual(python.find(converted), -1, python)
    for converted in ("utils.x", "utils.y", "base.a", "base.b"):
      self.assertEqual(python.find(converted), -1, python)

  def testModuleLocalsShadowGlobals(self):
    """testModuleLocalsShadowGlobals: module locals will shadow globals"""
    py = vb2py.vbparser.parseVB("""
    Dim a, b, x, y

    Sub Run()
      a = x
      b = y
      c = z
    End Sub
    """, container=self.cls)
    #
    python = py.renderAsCode()
    #
    for converted in ("utils.z", "base.c"):
      self.assertNotEqual(python.find(converted), -1, python)
    for converted in ("utils.x", "utils.y", "base.a", "base.b"):
      self.assertEqual(python.find(converted), -1, python)

  def testModuleDefsShadowGlobals(self):
    """testModuleDefsShadowGlobals: module definitions will shadow globals"""
    py = vb2py.vbparser.parseVB("""
    Sub Run()
      a = x
      b = y
      c = z
    End Sub

    Function a()
    End Function
    Function b()
    End Function
    Function x()
    End Function
    Function y()
    End Function

    """, container=self.cls)
    #
    python = py.renderAsCode()
    #
    for converted in ("utils.z", "base.c"):
      self.assertNotEqual(python.find(converted), -1, python)
    for converted in ("utils.x", "utils.y", "base.a", "base.b"):
      self.assertEqual(python.find(converted), -1, python)
  # << Globals tests >> (5 of 8)
  def testParametersShadowGlobals(self):
    """testParametersShadowGlobals: parameters will shadow globals"""
    py = vb2py.vbparser.parseVB("""
    Sub Run(a, b, x, y)
      a = x
      b = y
      c = z
    End Sub
    """, container=self.cls)
    #
    python = py.renderAsCode()
    #
    for converted in ("utils.z", "base.c"):
      self.assertNotEqual(python.find(converted), -1, python)
    for converted in ("utils.x", "utils.y", "base.a", "base.b"):
      self.assertEqual(python.find(converted), -1, python)
  # << Globals tests >> (6 of 8)
  def testPropertyShadowGlobals(self):
    """testPropertyShadowGlobals: properties will shadow globals"""
    py = vb2py.vbparser.parseVB("""
    Sub Run()
      a = x
      b = y
      c = z
    End Sub

    Property Get a()
    End Property
    Property Get b()
    End Property
    Property Get x()
    End Property
    Property Get y()
    End Property
    """, container=self.cls)
    #
    python = py.renderAsCode()
    #
    for converted in ("utils.z", "base.c"):
      self.assertNotEqual(python.find(converted), -1, python)
    for converted in ("utils.x", "utils.y", "base.a", "base.b"):
      self.assertEqual(python.find(converted), -1, python)
  # << Globals tests >> (7 of 8)
  def testSubGlobals(self):
    """testSubGlobals: lookup of a global subroutine"""
    py = vb2py.vbparser.parseVB("""
    Sub Run()
      DoIt
    End Sub
    """, container=self.cls)
    #
    python = py.renderAsCode()
    #
    for converted in ("base.DoIt()",):
      self.assertNotEqual(python.find(converted), -1, python)

  def testFnGlobals(self):
    """testFnGlobals: lookup of a global function"""
    py = vb2py.vbparser.parseVB("""
    Sub Run()
      a = Fact(10)
    End Sub
    """, container=self.cls)
    #
    python = py.renderAsCode()
    #
    for converted in ("utils.Fact(10)",):
      self.assertNotEqual(python.find(converted), -1, python)
  # << Globals tests >> (8 of 8)
  def testGlobalButLocalHere(self):
    """testGlobalButLocalHere: lookup of a global which happens to be local here"""
    mymod = vb2py.vbparser.VBCodeModule(modulename="this")
    mymod.parent = self.proj
    py = vb2py.vbparser.parseVB("""
    Public myval
    Sub Run()
      a=myval
    End Sub
    """, container=mymod)
    #
    python = py.renderAsCode()
    #
    for converted in ("this.myval",):
      self.assertEqual(python.find(converted), -1, python)

  def testGlobalButLocalHereNoNeedForGlobal(self):
    """testGlobalButLocalHereNoNeedForGlobal: lookup of a global which happens to be local here"""
    mymod = vb2py.vbparser.VBCodeModule(modulename="this")
    mymod.parent = self.proj
    py = vb2py.vbparser.parseVB("""
    Dim myval
    Public Function MyRun()
      MyRun=myval
    End Function
    """, container=mymod)
    #
    python = py.renderAsCode()
    #
    for converted in ("this.MyRun", "global MyRun"):
      self.assertEqual(python.find(converted), -1, python)    

  def testNeedAGlobalButOnlyUseOne(self):
    """testNeedAGlobalButOnlyUseOne: need to use a global statement but should just use one"""
    mymod = vb2py.vbparser.VBCodeModule(modulename="this")
    mymod.parent = self.proj
    py = vb2py.vbparser.parseVB("""
    Dim myval
    Public Function MyRun()
      myval = 10
      myval = 20
      myval = 30
    End Function
    """, container=mymod)
    #
    python = py.renderAsCode()
    #
    for converted in ("global myval, myval",):
      self.assertEqual(python.find(converted), -1, python)
  # -- end -- << Globals tests >>

import vb2py.vbparser
vb2py.vbparser.log.setLevel(0) # Don't print all logging stuff

if __name__ == "__main__":
  main()
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.