UnitTestHistory.py :  » UML » Python-UML-Tool » pyut-1.4.0 » src » 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 » UML » Python UML Tool 
Python UML Tool » pyut 1.4.0 » src » UnitTestHistory.py
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
from historyManager import *
from commandGroup import *
from printCommand import *
"""
@author P. Dabrowski <przemek.dabrowski@destroy-display.com> (15.11.2005)
This is the unit test of the HistoryManager. It was tested on 21.11.2005
and it works perfectly. It's also a good example to see how it works.
"""

#creating the history
h = HistoryManager(None)

#creating the command groups
cg1 = CommandGroup("cg1")
cg2 = CommandGroup("cg2")
cg3 = CommandGroup("cg3")
cg4 = CommandGroup("cg4")

#commands for group 1
pc1a = PrintCommand()
pc1b = PrintCommand()

#commands for group 2
pc2a = PrintCommand()
pc2b = PrintCommand()

#commands for group 3
pc3a = PrintCommand()
pc3b = PrintCommand()

#commands for group 4
pc4a = PrintCommand()
pc4b = PrintCommand()

# set the messages of the commands
pc1a.setMessage("pc1a")
pc1b.setMessage("pc1b")
pc2a.setMessage("pc2a")
pc2b.setMessage("pc2b")
pc3a.setMessage("pc3a")
pc3b.setMessage("pc3b")
pc4a.setMessage("pc4a")
pc4b.setMessage("pc4b")

#add the commands to the groups
cg1.addCommand(pc1a)
cg1.addCommand(pc1b)
cg2.addCommand(pc2a)
cg2.addCommand(pc2b)
cg3.addCommand(pc3a)
cg3.addCommand(pc3b)
cg4.addCommand(pc4a)
cg4.addCommand(pc4b)

#add the groups to the history
h.addCommandGroup(cg1)
h.addCommandGroup(cg2)
h.addCommandGroup(cg3)

#check if the undo/redo and add method works correctly
print "supposed to undo cg3 : "
h.undo()
print "supposed to undo cg2 : "
h.undo()
print "supposed to add cg4 and remove cg2 : "
h.addCommandGroup(cg4)
print "supposed to add cg3 : "
h.addCommandGroup(cg3)
print "supposed to undo cg3 : "
h.undo()
print "supposed to undo cg4 : "
h.undo()
print "supposed to undo cg1 : "
h.undo()
print "supposed to do nothing : "
h.undo()
print "-- nothing --"

print "supposed to add cg2 and delete cg1,3,4 : "
h.addCommandGroup(cg2)
print "supposed to undo cg2 : "
h.undo()
print "supposed to add cg1, cg3, cg4 and delete cg2 : "
h.addCommandGroup(cg1)
h.addCommandGroup(cg3)
h.addCommandGroup(cg4)
print "supposed to undo cg4, cg3, cg1 :"
h.undo()
h.undo()
h.undo()
print "supposed to redo cg1, cg3, cg4 :"
h.redo()
h.redo()
h.redo()
print "supposed to do nothing : "
h.redo()
print "-- nothing --"
print "supposed to add cg2"
h.addCommandGroup(cg2)
print "check that the file '" + h._fileName + "' contains groups cg1,3,4,2 and then press [enter]" 
try:
    input()
finally:
    print "should be false : ", h.isRedoPossible()
    print "should be true : ", h.isUndoPossible()
    print "should be cg2 : ", h.getCommandGroupToUndo().getComment()
    h.undo()
    print "should be cg4 : ", h.getCommandGroupToUndo().getComment()
    print "should be cg2 : ", h.getCommandGroupToRedo().getComment()
    h.undo()
    print "should be cg3 : ", h.getCommandGroupToUndo().getComment()
    print "should be cg4 : ", h.getCommandGroupToRedo().getComment()
    h.undo()
    print "should be cg1 : ", h.getCommandGroupToUndo().getComment()
    print "should be cg3 : ", h.getCommandGroupToRedo().getComment()
    h.undo()
    print "should be cg1 : ", h.getCommandGroupToRedo().getComment()
    print "should be true : ", h.isRedoPossible()
    print "should be false : ", h.isUndoPossible()
    print "check that the file '" + h._fileName + "' doesn't exist anymore"
    h.destroy()
    print "!!!DON'T CARE ABOUT THE FINAL ERROR MESSAGE!!!"
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.