def test_main_nofile(self, mock): #setup myfile = 'nofile' mock.return_value = False #exercise with self.assertRaises(SystemExit): main(['./AnyMate.py', myfile])
def test_main_mockedfile(self, anymock, guimock, filemock): #setup myfile = 'nofile' filemock.return_value = True #exercise main(['./AnyMate.py', myfile]) #validate anymock.assert_called_once_with(myfile)
def test_main_four_wrong_file(self, mock): #setup myfile = 'nofile' conf = 'hello' anym = MagicMock() mock.return_value = anym #exercise with self.assertRaises(SystemExit): main(['./AnyMate.py', '--nogui', conf, myfile])
def test_main_four_wrong_param(self, mock): #setup myfile = 'template.anymate' conf = 'hello' anym = MagicMock() mock.return_value = anym #exercise with self.assertRaises(SystemExit): main(['./AnyMate.py', 'BAM', conf, myfile])
def test_main_two_real_param(self, mock, guimock): #setup myfile = 'template.anymate' mock.return_value = "Something" #exercise main(['./AnyMate.py', myfile]) #validate mock.assert_called_once_with(myfile) # We expect the gui to be called with the return value of AnyMate() guimock.assert_called_once_with("Something", myfile)
def test_main_four_real_param(self, mock): #setup myfile = 'template.anymate' conf = 'hello' anym = MagicMock() mock.return_value = anym #exercise main(['./AnyMate.py', '--nogui', conf, myfile]) #validate mock.assert_called_once_with(myfile) anym.execute.assert_called_once_with(conf)
def test_main_mainloop(self, anymock, guimock, filemock): #setup myfile = 'nofile' filemock.return_value = True #Anymate() returns an AnymateObject anymock.return_value = MagicMock(name='AnyMate') gui = MagicMock(name='AnyMateGui') guimock.return_value = gui #exercise main(['./AnyMate.py', myfile]) #validate anymock.assert_called_once_with(myfile) gui.rootwin.mainloop.assert_called_once_with()
def test_main_three_param(self): with self.assertRaises(SystemExit): main(["one", "two", "three"])
def test_main_fife_param(self): with self.assertRaises(SystemExit): main(["bad"] * 5)
def test_main_one_param(self): with self.assertRaises(SystemExit): main(["one"])
def test_main_listparam(self): with self.assertRaises(SystemExit): main([])
def test_main_intparam(self, mock): with self.assertRaises(SystemExit): main(88) mock.assert_called_once_with()
def test_main_help(self, mock): with self.assertRaises(SystemExit): main('') mock.assert_called_once_with()
def test_main_noparam(self): with self.assertRaises(TypeError): main()