Esempio n. 1
0
    def test_validate_bool(self):
        p1 = Prompt('symlink', 'one file per hook?', 'y', 'boolean')
        p2 = Prompt('symlink', 'one file per hook?', 'y', 'bool')

        self.assertTrue(p1.validate('True'))
        self.assertTrue(p1.validate('Yes'))
        self.assertTrue(p1.validate('y'))
        self.assertFalse(p2.validate('False'))
        self.assertFalse(p2.validate('No'))
        self.assertFalse(p2.validate('n'))
Esempio n. 2
0
    def test_init(self):
        p = Prompt('symlink', 'one file per hook?', 'y')

        self.assertEqual(p.name, 'symlink')
        self.assertEqual(p.prompt, 'one file per hook? ')
        self.assertEqual(p.default, 'y')
        self.assertEqual(p.type_, 'string')
Esempio n. 3
0
    def test_get_user_config_from_defaults(self):
        self.c.opts.accept_defaults = True
        with patch.object(self.c.plugin, 'prompts') as prompts:
            prompts.return_value = [
                Prompt('symlink', 'symlink hooks?', 'y', 'bool')]
            config = self.c._get_user_config()

            self.assertEqual(config, {'symlink': True})
Esempio n. 4
0
    def test_get_user_config_from_prompts(self, raw_input_):
        raw_input_.return_value = 'Yes'
        with patch.object(self.c.plugin, 'prompts') as prompts:
            prompts.return_value = [
                Prompt('symlink', 'symlink hooks?', 'y', 'bool')]
            config = self.c._get_user_config()

            self.assertEqual(config, {'symlink': True})
Esempio n. 5
0
    def test_prompt_valid_input(self, raw_input_):
        raw_input_.return_value = 'Joe'
        prompt = Prompt('name', 'your name?', 'Name')

        self.assertEqual(self.c._prompt(prompt, {}), 'Joe')
        self.assertEqual(raw_input_.call_count, 1)
Esempio n. 6
0
    def test_prompt_invalid_input(self, raw_input_):
        raw_input_.side_effect = ['foo', '18']
        prompt = Prompt('age', 'your age?', '42', 'int')

        self.assertEqual(self.c._prompt(prompt, {}), 18)
        self.assertEqual(raw_input_.call_count, 2)
Esempio n. 7
0
    def test_prompt_no_input(self, raw_input_):
        raw_input_.return_value = ''
        prompt = Prompt('symlink', 'symlink hooks?', 'y', 'bool')

        self.assertTrue(self.c._prompt(prompt, {}))
Esempio n. 8
0
    def test_prompt_accept_default(self):
        self.c.opts.accept_defaults = True
        prompt = Prompt('symlink', 'symlink hooks?', 'y', 'bool')

        self.assertTrue(self.c._prompt(prompt, {}))
Esempio n. 9
0
    def test_validate_float(self):
        p1 = Prompt('temp', 'temperature?', '0', 'float')

        self.assertEqual(98.6, p1.validate('98.6'))
        self.assertEqual(100.0, p1.validate('100'))
Esempio n. 10
0
    def test_validate_int(self):
        p1 = Prompt('age', 'your age?', '0', 'integer')
        p2 = Prompt('age', 'your age?', '0', 'int')

        self.assertEqual(18, p1.validate('18'))
        self.assertEqual(18, p2.validate('18'))
Esempio n. 11
0
    def test_validate_string(self):
        p1 = Prompt('name', 'your name?', 'Name', 'string')
        p2 = Prompt('name', 'your name?', 'Name', 'str')

        self.assertEqual('Joe', p1.validate('Joe'))
        self.assertEqual('Joe', p2.validate('Joe'))