def test_ChangeProperty(self): cmd = CommandManager() create = self.model.modules['create'] source = self.model.modules['source'] sink = self.model.modules['sink'] cmd.change_prop(create.properties, 'destination', sink) self.assertIs(create.properties['destination'], sink) cmd.undo() self.assertIs(create.properties['destination'], source) cmd.redo() self.assertIs(create.properties['destination'], sink)
def test_ChangeProgram(self): cmd = CommandManager() machine = self.model.modules['machine'] cmd.add_prog(machine.properties['program_table'], 'p4', 4, {'change': {'length': 1}}) p = machine.properties['program_table']['p4'] cmd.change_prog_time(p, 12) self.assertEqual(p.time(), 12) cmd.undo() self.assertEqual(p.time(), 4) cmd.redo() self.assertEqual(p.time(), 12)
def test_Delete(self): cmd = CommandManager() cmd.create_module('test_module', emulation.CreateAct, self.model) module = self.model.modules['test_module'] cmd.delete_module(module, self.model) #verify module has been deleted self.assertNotIn('test_module', self.model.modules.keys()) cmd.undo() self.assertIn('test_module', self.model.modules.keys()) cmd.redo() self.assertNotIn('test_module', self.model.modules.keys())
def test_ChangeSetup(self): cmd = CommandManager() machine = self.model.modules['machine'] p1 = machine.properties['program_table']['p1'] p3 = machine.properties['program_table']['p3'] m = machine.properties['setup'] cmd.change_setup(m, 'p1', 'p3', new_time = 5) self.assertEqual(m.get('p1', 'p3'), 5) cmd.undo() self.assertEqual(m.get('p1', 'p3'), 2) cmd.redo() self.assertEqual(m.get('p1', 'p3'), 5)
def test_AddSetup(self): cmd = CommandManager() machine = self.model.modules['machine'] p1 = machine.properties['program_table']['p1'] p2 = machine.properties['program_table']['p2'] m = machine.properties['setup'] cmd.add_setup(m, p1, p2, 3) self.assertEqual(m.get(p1, p2), 3) cmd.undo() self.assertEqual(m.get(p1, p2), 1) cmd.redo() self.assertEqual(m.get(p1, p2), 3)
def test_RemoveProg(self): cmd = CommandManager() machine = self.model.modules['machine'] cmd.add_prog(machine.properties['program_table'], 'p4', 4, {'change': {'length': 1}}) p = machine.properties['program_table']['p4'] cmd.del_prog(machine.properties['program_table'], 'p4') self.assertNotIn('p4', machine.properties['program_table']) cmd.undo() self.assertIn('p4', machine.properties['program_table']) self.assertIs(machine.properties['program_table']['p4'], p) cmd.redo() self.assertNotIn('p4', machine.properties['program_table'])
def test_RemoveSetup(self): cmd = CommandManager() machine = self.model.modules['machine'] p1 = machine.properties['program_table']['p1'] p3 = machine.properties['program_table']['p3'] m = machine.properties['setup'] print m cmd.del_setup(m, 'p1', 'p3') self.assertEqual(m.get('p1', 'p3'), 1) cmd.undo() self.assertEqual(m.get('p1', 'p3'), 2) cmd.redo() self.assertEqual(m.get('p1', 'p3'), 1)
def test_Create(self): cmd = CommandManager() cmd.create_module('test_module', emulation.CreateAct, self.model) #verify that the module has been created module = self.model.modules['test_module'] self.assertIsInstance(module, emulation.CreateAct) self.assertTrue(cmd.can_undo()) self.assertFalse(cmd.can_redo()) cmd.undo() self.assertNotIn('test_module', self.model.modules.keys()) self.assertFalse(cmd.can_undo()) self.assertTrue(cmd.can_redo()) cmd.redo() module2 = self.model.modules['test_module'] self.assertEqual(module, module2) self.assertTrue(cmd.can_undo()) self.assertFalse(cmd.can_redo())
def test_Rename(self): cmd = CommandManager() cmd.create_module('test_module', emulation.CreateAct, self.model) module = self.model.modules['test_module'] cmd.rename_module(module, 'test_module2') module3 = self.model.modules['test_module2'] self.assertIs(module3, module) self.assertEqual(module3.name,'test_module2') self.assertNotIn('test_module', self.model.modules.keys()) self.assertIn('test_module2', self.model.modules.keys()) cmd.undo() self.assertEqual(module3.name,'test_module') self.assertIn('test_module', self.model.modules.keys()) self.assertNotIn('test_module2', self.model.modules.keys()) cmd.redo() self.assertEqual(module3.name,'test_module2') self.assertNotIn('test_module', self.model.modules.keys()) self.assertIn('test_module2', self.model.modules.keys())
def setUp(self): self.model = emulation.Model() self.cmd = CommandManager()
def test_Init(self): cmd = CommandManager() #verify the can undo and can redo return false self.assertFalse(cmd.can_undo()) self.assertFalse(cmd.can_redo())