def setUp(self): self.mac1 = Macro("Sample Macro 1") for i in range(1, 6): self.mac1.add( Command(lambda: None, lambda: None, "Sample Command {}".format(i)))
def test_call(self): self.mac2 = Macro("Sample Macro 2") self.mac3 = Macro("Sample Macro 3") for i in range(1, 6): self.mac2.add( Command(lambda: None, lambda: None, "Sample Command {}".format(i))) for i in range(6, 11): self.mac3.add( Command(lambda: None, lambda: None, "Sample Command {}".format(i))) mock_mac2 = MagicMock(self.mac2) mock_mac3 = MagicMock(self.mac3) mock_mac2() mock_mac2.undo() mock_mac3.do() mock_mac3.undo() self.assertTrue(mock_mac2.called) self.assertTrue(mock_mac2.undo.called) self.assertTrue(mock_mac3.do.called) self.assertTrue(mock_mac3.undo.called) self.assertEqual(mock_mac2.call_count, 1) self.assertEqual(len(mock_mac2.method_calls), 1) self.assertEqual(len(mock_mac3.method_calls), 2)
def create_rectangle_macro(self, x0, y0, x1, y1, color): # TODO Implement me! macro = Macro("Rectangle") for x in range(x0, x1 + 1): for y in range(y0, y1 + 1): macro.add(self.create_cell_command(x, y, color)) return macro
class MacroTest(unittest.TestCase): def setUp(self): self.mac1 = Macro("Sample Macro 1") for i in range(1, 6): self.mac1.add( Command(lambda: None, lambda: None, "Sample Command {}".format(i))) def test_init(self): self.assertEqual(self.mac1.description, "Sample Macro 1") self.assertEqual(len(self.mac1), 5) def test_add(self): with self.assertRaises(TypeError): self.mac1.add(Macro()) self.mac1.add(Command(lambda: None, lambda: None, "Test Add")) self.assertEqual(len(self.mac1), 6) # How to (mock) test do() and undo() in Macro? def test_call(self): self.mac2 = Macro("Sample Macro 2") self.mac3 = Macro("Sample Macro 3") for i in range(1, 6): self.mac2.add( Command(lambda: None, lambda: None, "Sample Command {}".format(i))) for i in range(6, 11): self.mac3.add( Command(lambda: None, lambda: None, "Sample Command {}".format(i))) mock_mac2 = MagicMock(self.mac2) mock_mac3 = MagicMock(self.mac3) mock_mac2() mock_mac2.undo() mock_mac3.do() mock_mac3.undo() self.assertTrue(mock_mac2.called) self.assertTrue(mock_mac2.undo.called) self.assertTrue(mock_mac3.do.called) self.assertTrue(mock_mac3.undo.called) self.assertEqual(mock_mac2.call_count, 1) self.assertEqual(len(mock_mac2.method_calls), 1) self.assertEqual(len(mock_mac3.method_calls), 2)
class MacroTest(unittest.TestCase): def setUp(self): self.mac1 = Macro("Sample Macro 1") for i in range(1, 6): self.mac1.add( Command(lambda: None, lambda: None, "Sample Command {}".format(i))) def test_init(self): self.assertEqual(self.mac1.description, "Sample Macro 1") self.assertEqual(len(self.mac1), 5) def test_add(self): with self.assertRaises(TypeError): self.mac1.add(Macro()) self.mac1.add(Command(lambda: None, lambda: None, "Test Add")) self.assertEqual(len(self.mac1), 6)
def test_add(self): with self.assertRaises(TypeError): self.mac1.add(Macro()) self.mac1.add(Command(lambda: None, lambda: None, "Test Add")) self.assertEqual(len(self.mac1), 6)