testclassmethods.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 » testclassmethods.py
# Created by Leo from: C:\Development\Python22\Lib\site-packages\vb2py\vb2py.leo

from unittest import *
from complexframework import *


# << ClassMethod tests >> (1 of 6)
#
# Simple public method
tests.append((
    VBClassModule(),
    """
    Public my_a As String

    Public Sub SetA(Value As Integer)
      my_a = Value
    End Sub
    """,
    ("A = MyClass()\n"
     "A.SetA('hello')\n"
     "assert A.my_a == 'hello', 'A.my_a was (%s)' % (A.my_a,)\n",)
))         

#
# Simple public method with a local variable shadowing a class variable
tests.append((
    VBClassModule(),
    """
    Public my_a As String
    Public my_b As String

    Public Sub SetA(Value As Integer)
      Dim my_b
      my_b = "other"
      my_a = Value + my_b
    End Sub

    Public Sub SetB(Value As Integer)
      my_b = Value
    End Sub
    """,
    ("A = MyClass()\n"
     "A.SetB('thisisb')\n"
     "A.SetA('thisisa')\n"
     "assert A.my_a == 'thisisaother', 'A.my_a was (%s)' % (A.my_a,)\n"
     "assert A.my_b == 'thisisb', 'A.my_b was (%s)' % (A.my_b,)\n",)
))         

#
# Simple public method calling another method
tests.append((
    VBClassModule(),
    """
    Public my_a As String
    Public my_b As String

    Public Sub SetA(Value As Integer)
      SetB Value
      my_a = my_b
    End Sub

    Public Sub SetB(Value As Integer)
      my_b = Value
    End Sub
    """,
    ("A = MyClass()\n"
     "A.SetA('thisisa')\n"
     "assert A.my_a == 'thisisa', 'A.my_a was (%s)' % (A.my_a,)\n"
     "assert A.my_b == 'thisisa', 'A.my_b was (%s)' % (A.my_b,)\n",)
))         


#
# Simple public method with a parameter shadowing a class variable
tests.append((
    VBClassModule(),
    """
    Public my_a As String
    Public my_b As String

    Public Sub SetA(my_b As Integer)
      my_a = my_b
    End Sub

    Public Sub SetB(Value As Integer)
      my_b = Value
    End Sub
    """,
    ("A = MyClass()\n"
     "A.SetB('thisisb')\n"
     "A.SetA('thisisa')\n"
     "assert A.my_a == 'thisisa', 'A.my_a was (%s)' % (A.my_a,)\n"
     "assert A.my_b == 'thisisb', 'A.my_b was (%s)' % (A.my_b,)\n",)
))
# << ClassMethod tests >> (2 of 6)
#
# Simple public function
tests.append((
    VBClassModule(),
    """
    Public lower_bound As Integer

    Public Sub setLowerBound(Value As Integer)
      lower_bound = Value
    End Sub

    Public Function Factorial(Value As Integer)
      If Value = lower_bound Then
        Factorial = 1
      Else
        Factorial = Value * Factorial(Value-1)
      End If
    End Function
    """,
    ("A = MyClass()\n"
     "A.setLowerBound(1)\n"
     "assert A.Factorial(6) == 720, 'A.Factorial(6) was (%s)' % (A.Factorial(6),)\n",)
))
# << ClassMethod tests >> (3 of 6)
#
# Simple private method
tests.append((
    VBClassModule(),
    """
    Public my_a As String

    Private Sub SetA(Value As Integer)
      my_a = Value
    End Sub
    """,
    ("A = MyClass()\n"
     "try:\n"
     "  A.SetA('hello')\n"
     "except AttributeError:\n"
     "  pass\n"
     "else:\n"
     "  assert 0, 'Method should be private'\n",)
))
# << ClassMethod tests >> (4 of 6)
#
# Simple init method called automatically
tests.append((
    VBClassModule(),
    """
    Public my_a As String

    Public Sub Class_Initialize()
      my_a = "hello"
    End Sub

    Public Sub SetA(Value As Integer)
      my_a = Value
    End Sub
    """,
    ("A = MyClass()\n"
     "assert A.my_a == 'hello', 'A.my_a was (%s)' % (A.my_a,)\n"
     "A.SetA('bye')\n"
     "assert A.my_a == 'bye', 'A.my_a was (%s)' % (A.my_a,)\n",)
))         


#
# Explicitely calling the init method
tests.append((
    VBClassModule(),
    """
    Public my_a As String

    Public Sub Class_Initialize()
      my_a = "hello"
    End Sub

    Public Sub ReInit()
      Class_Initialize
    End Sub

    Public Sub SetA(Value As Integer)
      my_a = Value
    End Sub

    """,
    ("A = MyClass()\n"
     "A.SetA('bye')\n"
     "A.ReInit()\n"
     "assert A.my_a == 'hello', 'A.my_a was (%s)' % (A.my_a,)\n",)
))         

#
# Explicitely calling the terminate method
tests.append((
    VBClassModule(),
    """
    Public my_a As String

    Public Sub Class_Terminate()
      my_a = "hello"
    End Sub

    Public Sub Reset()
      Class_Terminate
    End Sub

    Public Sub SetA(Value As Integer)
      my_a = Value
    End Sub

    """,
    ("A = MyClass()\n"
     "A.SetA('bye')\n"
     "A.Reset()\n"
     "assert A.my_a == 'hello', 'A.my_a was (%s)' % (A.my_a,)\n",)
))         


#
# init method is private
tests.append((
    VBClassModule(),
    """
    Public my_a As String

    Sub Class_Initialize()
      my_a = "hello"
    End Sub

    Public Sub ReInit()
      Class_Initialize
    End Sub

    Public Sub SetA(Value As Integer)
      my_a = Value
    End Sub

    """,
    ("A = MyClass()\n"
     "A.SetA('bye')\n"
     "A.ReInit()\n"
     "assert A.my_a == 'hello', 'A.my_a was (%s)' % (A.my_a,)\n",)
))         


#
# Terminate method is private
tests.append((
    VBClassModule(),
    """
    Public my_a As String

    Sub Class_Terminate()
      my_a = "hello"
    End Sub

    Public Sub Reset()
      Class_Terminate
    End Sub

    Public Sub SetA(Value As Integer)
      my_a = Value
    End Sub

    """,
    ("A = MyClass()\n"
     "A.SetA('bye')\n"
     "A.Reset()\n"
     "assert A.my_a == 'hello', 'A.my_a was (%s)' % (A.my_a,)\n",)
))
# << ClassMethod tests >> (5 of 6)
#
# Class properties
tests.append((
    VBClassModule(),
    """
    Public arr()

    Public Sub DoIt(Value As Integer)
      ReDim arr(Value)
    End Sub
    """,
    ("A = MyClass()\n"
     "B = MyClass()\n"
     "A.DoIt(10)\n"
     "B.DoIt(20)\n"
     "assert len(A.arr) == 11, 'len(A.arr) was (%s)' % (len(A.arr),)\n"
     "assert len(B.arr) == 21, 'len(B.arr) was (%s)' % (len(B.arr),)\n",)
))         

#
# Make sure class properties are not shared
tests.append((
    VBClassModule(),
    """
    Public arr(20)

    Public Sub DoIt(Value As Integer)
      arr(10) = Value
    End Sub
    """,
    ("A = MyClass()\n"
     "B = MyClass()\n"
     "A.DoIt(10)\n"
     "B.DoIt(20)\n"
     "assert A.arr[10] == 10, 'A.arr[10] was (%s)' % (A.arr[10],)\n"
     "assert B.arr[10] == 20, 'B.arr[10] was (%s)' % (B.arr[10],)\n",)
))
# << ClassMethod tests >> (6 of 6)
#
# Me in an expression
tests.append((
    VBClassModule(),
    """
    Public Val

    Public Sub DoIt(Value As Integer)
      Me.Val = Value
    End Sub
    """,
    ("A = MyClass()\n"
     "A.DoIt(10)\n"
     "assert A.Val==10, 'A.Val was (%s)' % (A.Val,)\n",)
))         


#
# Me in a call
tests.append((
    VBClassModule(),
    """
    Public Val

    Public Sub DoIt(Value As Integer)
      Val = Value
      Me.AddOne
    End Sub

    Public Sub AddOne()
      Val = Val + 1
    End Sub

    """,
    ("A = MyClass()\n"
     "A.DoIt(10)\n"
     "assert A.Val==11, 'A.Val was (%s)' % (A.Val,)\n",)
))
# -- end -- << ClassMethod tests >>

import vb2py.vbparser
vb2py.vbparser.log.setLevel(0) # Don't print all logging stuff
TestClass = addTestsTo(BasicTest, tests)

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.