Exemple #1
0
    def test_invoker(self):
        screen = Screen('hello world!!')
        client = ScreenInvoker()

        cut_command = CutCommand(screen, start=5, end=11)
        client.store_and_execute(cut_command)
        self.assertEquals('hello!!', screen.text)

        paste_command = PasteCommand(screen, offset=0)
        client.store_and_execute(paste_command)
        self.assertEquals(' worldhello!!', screen.text)

        copy_command = CopyCommand(screen, start=0, end=screen.length())
        client.store_and_execute(copy_command)

        paste_command2 = PasteCommand(screen, offset=0)
        client.store_and_execute(paste_command2)
        self.assertEquals(' worldhello!! worldhello!!', screen.text)

        #undo last paste
        client.undo_last()
        self.assertEquals(' worldhello!!', screen.text)

        #undo copy
        client.undo_last()
        self.assertEquals(' worldhello!!', screen.text)
        self.assertEquals('', screen.clipboard)

        #undo paste
        client.undo_last()
        self.assertEquals('hello!!', screen.text)

        #undo cut
        client.undo_last()
        self.assertEquals('hello world!!', screen.text)
Exemple #2
0
    def test_invoker(self):
        screen = Screen('hello world!!')
        client = ScreenInvoker()

        cut_command = CutCommand(screen, start=5, end=11)
        client.store_and_execute(cut_command)
        self.assertEquals('hello!!', screen.text)

        paste_command = PasteCommand(screen, offset=0)
        client.store_and_execute(paste_command)
        self.assertEquals(' worldhello!!', screen.text)

        copy_command = CopyCommand(screen, start=0, end=screen.length())
        client.store_and_execute(copy_command)

        paste_command2 = PasteCommand(screen, offset=0)
        client.store_and_execute(paste_command2)
        self.assertEquals(' worldhello!! worldhello!!', screen.text)

        #undo last paste
        client.undo_last()
        self.assertEquals(' worldhello!!', screen.text)

        #undo copy
        client.undo_last()
        self.assertEquals(' worldhello!!', screen.text)
        self.assertEquals('', screen.clipboard)

        #undo paste
        client.undo_last()
        self.assertEquals('hello!!', screen.text)

        #undo cut
        client.undo_last()
        self.assertEquals('hello world!!', screen.text)
Exemple #3
0
 def test_cut_command(self):
     screen = Screen('hello world!!')
     command = CutCommand(screen, start=5, end=11)
     command.execute()
     self.assertEquals('hello!!', screen.text)
     self.assertEquals(' world', screen.clipboard)
     command.undo()
     self.assertEquals('hello world!!', screen.text)
Exemple #4
0
 def test_copy_command(self):
     screen = Screen('hello world!!')
     command = CopyCommand(screen, start=4, end=8)
     command.execute()
     self.assertEquals('o wo', screen.clipboard)
     self.assertEquals('hello world!!', screen.text)
     command.undo()
     self.assertEquals('', screen.clipboard)
Exemple #5
0
 def test_copy(self):
     screen = Screen('hello world!!')
     screen.copy(start=4, end=8)
     self.assertEquals('o wo', screen.clipboard)
     self.assertEquals('hello world!!', screen.text)
Exemple #6
0
 def test_cut(self):
     screen = Screen('hello world!!')
     screen.cut(start=5, end=11)
     self.assertEquals('hello!!', screen.text)
     self.assertEquals(' world', screen.clipboard)
Exemple #7
0
 def test_paste(self):
     screen = Screen('hello world!!')
     screen.copy(start=0, end=5)
     screen.paste(screen.length())
     self.assertEquals('hello world!!hello', screen.text)
Exemple #8
0
 def test_copy(self):
     screen = Screen('hello world!!')
     screen.copy(start=4, end=8)
     self.assertEquals('o wo', screen.clipboard)
     self.assertEquals('hello world!!', screen.text)
Exemple #9
0
 def test_cut(self):
     screen = Screen('hello world!!')
     screen.cut(start=5, end=11)
     self.assertEquals('hello!!', screen.text)
     self.assertEquals(' world', screen.clipboard)
Exemple #10
0
 def test_paste(self):
     screen = Screen('hello world!!')
     screen.copy(start=0, end=5)
     screen.paste(screen.length())
     self.assertEquals('hello world!!hello', screen.text)
Exemple #11
0
from factory import ShapeFactory

f = ShapeFactory()
s = f.getShape('Square')
print(s, s.draw())

from command import Screen, ScreenInvoker, CutCommand, PasteCommand
test_data = "Hello world"
x = Screen(test_data)
re = x.__str__()
# print(re)

cut = CutCommand(x, start=5, end=11)
client = ScreenInvoker()
client.store_and_execute(cut)
re = x.__str__()
print(re)

from observer import Obserable, AmericanStockMarket, EuropeanStockMarket
really_big_company = Obserable()
american_observer = AmericanStockMarket()
really_big_company.register(american_observer)
european_observer = EuropeanStockMarket()
really_big_company.register(european_observer)
really_big_company.update_observers('important_update',
                                    msg='CEO unexpectedly resigns!')