def setUp(self): self.updater = Updater() self.updater.download = dummy_download()
class TestUpdater(unittest.TestCase): def setUp(self): self.updater = Updater() self.updater.download = dummy_download() def test_can_update_download_is_newer(self): # given with patch.dict('whyteboard.misc.meta.__dict__', {'version': "0.3"}): # when can_update = self.updater.can_update() # then self.assertTrue(can_update) def test_can_update_download_is_same_version(self): # given with patch.dict('whyteboard.misc.meta.__dict__', {'version': "0.4"}): # when can_update = self.updater.can_update() # then self.assertFalse(can_update) def test_can_update_download_is_older(self): # given with patch.dict('whyteboard.misc.meta.__dict__', {'version': "0.5"}): # when can_update = self.updater.can_update() # then self.assertFalse(can_update) @patch('whyteboard.updater.updater.is_exe') def test_restart_args_windows_exe(self, is_exe): # given is_exe.return_value = True argv = ['whyteboard.exe'] current_dir = os.path.dirname(os.path.abspath(sys.argv[1])) with patch.dict('sys.__dict__', {'argv': argv}): # when arguments = self.updater.restart_args() # then expected = os.path.join(current_dir, argv[0]) self.assertEqual([expected, [expected]], arguments) @patch('whyteboard.updater.updater.is_exe') def test_restart_args_windows_exe_with_file(self, is_exe): # given is_exe.return_value = True _file = u"c:\test\whyteboard file.wtbd" argv = ['whyteboard.exe'] current_dir = os.path.dirname(os.path.abspath(sys.argv[1])) with patch.dict('sys.__dict__', {'argv': argv}): # when arguments = self.updater.restart_args(_file) # then expected = os.path.join(current_dir, argv[0]) self.assertEqual([expected, [expected, u"--file", '"%s"' % _file]], arguments) @patch('whyteboard.updater.updater.is_exe') @patch('whyteboard.updater.updater.logger') def test_restart_args_windows_exe_with_debug_enabled(self, logger, is_exe): # given is_exe.return_value = True logger.is_enabled_for.return_value = True argv = ['whyteboard.exe'] current_dir = os.path.dirname(os.path.abspath(sys.argv[1])) with patch.dict('sys.__dict__', {'argv': argv}): # when arguments = self.updater.restart_args() # then expected = os.path.join(current_dir, argv[0]) self.assertEqual([expected, [expected, u"--debug"]], arguments) @patch('whyteboard.updater.updater.is_exe') def test_restart_args_source(self, is_exe): # given is_exe.return_value = False argv = ['whyteboard.py'] with patch.dict('sys.__dict__', {'argv': argv}): # when arguments = self.updater.restart_args() # then self.assertEqual(['python', ['python', argv[0]]], arguments) @patch('whyteboard.updater.updater.is_exe') def test_restart_args_source_with_filename(self, is_exe): # given is_exe.return_value = False argv = ['whyteboard.py'] _file = "c:\test\whyteboard test.wtbd" with patch.dict('sys.__dict__', {'argv': argv}): # when arguments = self.updater.restart_args(_file) # then self.assertEqual(['python', ['python', argv[0], "--file", '"%s"' % _file]], arguments) @patch('whyteboard.updater.updater.is_exe') @patch('whyteboard.updater.updater.logger') def test_restart_args_source_with_debug_and_filename(self, logger, is_exe): # given is_exe.return_value = False logger.is_enabled_for.return_value = True argv = ['whyteboard.py'] _file = "c:\test\whyteboard test.wtbd" with patch.dict('sys.__dict__', {'argv': argv}): # when arguments = self.updater.restart_args(_file) # then self.assertEqual(['python', ['python', argv[0], "--file", '"%s"' % _file, "--debug"]], arguments)