def test_both_text_arguments(self): """Provide both -text and -textfile.""" expected_error = "'-text' and '-textfile' cannot both be used" with self.assertRaisesRegex(ValueError, expected_error): parse(['-text:hello', '-textfile:/some/path'], self.generator_factory)
def test_unrecognized_argument(self): """Provide an argument that doesn't exist.""" expected_error = "Argument '-no_such_arg' is unrecognized" for invalid_arg in ('-no_such_arg', '-no_such_arg:hello'): with self.assertRaisesRegex(ValueError, expected_error): parse([invalid_arg], self.generator_factory)
def test_parse(self): """Basic argument parsing.""" args = parse(['-text:"hello world"'], self.generator_factory) self.assertEqual('"hello world"', args['text']) self.assertFalse(args['up']) self.assertTrue(args['reorder']) args = parse(['-text:hello', '-up', '-noreorder'], self.generator_factory) self.assertEqual('hello', args['text']) self.assertTrue(args['up']) self.assertFalse(args['reorder'])
def test_argument_prompt(self, input_mock): """Reqest an argument that requres a prompt.""" input_mock.return_value = 'hello world' args = parse(['-text'], self.generator_factory) self.assertEqual('hello world', args['text']) input_mock.assert_called_with('What text do you want to add?')
def test_neither_text_argument(self): """Don't provide either -text or -textfile.""" expected_error = "Either the '-text' or '-textfile' is required" with self.assertRaisesRegex(ValueError, expected_error): parse(['-noreorder'], self.generator_factory)