def test_yesno_choose_default(self): """Default is No""" yes_callback = Mock() no_callback = Mock() inter = YesNo("Content?", yes_callback, no_callback) inter.choose("") self.assertTrue(no_callback.called) self.assertFalse(yes_callback.called)
def test_yesno_choose_default_overriden(self): """Default is No""" yes_callback = Mock() no_callback = Mock() inter = YesNo("Content?", yes_callback, no_callback, default_is_yes=True) inter.choose("") self.assertTrue(yes_callback.called) self.assertFalse(no_callback.called)
def test_yesno_run_answers(self): """Yes runs yes in different ways""" yes_callback = Mock() no_callback = Mock() inter = YesNo("Content?", yes_callback, no_callback) self.assertEquals(inter.choose(choice_id=0), yes_callback.return_value) self.assertEquals(inter.choose(choice_id=1), no_callback.return_value) self.assertEquals(inter.choose(answer='Y'), yes_callback.return_value) self.assertEquals(inter.choose(answer='N'), no_callback.return_value) self.assertEquals(inter.choose(answer='yEs'), yes_callback.return_value) self.assertEquals(inter.choose(answer='nO'), no_callback.return_value)
def confirm_path(self, path_dir=""): """Confirm path dir""" if not path_dir: logger.debug("No installation path provided. Requesting one.") UI.display( InputText("Choose installation path:", self.confirm_path, self.install_path)) return logger.debug("Installation path provided. Checking if exists.") with suppress(FileNotFoundError): if os.listdir(path_dir): # we already told we were ok to overwrite as it was the previous install path if path_dir not in self._paths_to_clean: if path_dir == "/": logger.error( "This doesn't seem wise. We won't let you shoot in your feet." ) self.confirm_path() return self.install_path = path_dir # we don't set it before to not repropose / as installation path UI.display( YesNo( "{} isn't an empty directory, do you want to remove its content and install " "there?".format(path_dir), self.set_installdir_to_clean, UI.return_main_screen)) return self.install_path = path_dir self.download_provider_page()
def test_yesno(self): """We can instantiate a YesNo""" inter = YesNo("Content?", lambda: "", lambda: "") self.assertEquals(inter.content, "Content?") self.assertEquals(len(inter.choices), 2, str(inter.choices)) self.assertEquals(inter.prompt, "Content? [Yes (y)/No (N)] ")
def setup(self, install_path=None, auto_accept_license=False): self.arg_install_path = install_path self.auto_accept_license = auto_accept_license super().setup() # first step, check if installed if self.is_installed: UI.display(YesNo("{} is already installed on your system, do you want to reinstall " "it anyway?".format(self.name), self.reinstall, UI.return_main_screen)) else: self.confirm_path(self.arg_install_path)
def test_yesno_run_answers(self): """Yes runs yes in different ways""" yes_callback = Mock() no_callback = Mock() inter = YesNo("Content?", yes_callback, no_callback) self.assertEqual(inter.choose(choice_id=0), yes_callback.return_value) self.assertEqual(inter.choose(choice_id=1), no_callback.return_value) self.assertEqual(inter.choose(answer='Y'), yes_callback.return_value) self.assertEqual(inter.choose(answer='N'), no_callback.return_value) self.assertEqual(inter.choose(answer='yEs'), yes_callback.return_value) self.assertEqual(inter.choose(answer='nO'), no_callback.return_value)