def test_multiple_keyvalue(self): self.setup_environment() cli = CommandLineClient() cli.keyvalue_pairs = True cli.setup_parser() options = cli.parse_args(["foo=bar", "baz=whatever"]) self.assertIn(("foo", "bar"), options.keyvalue_pairs.items()) self.assertIn(("baz", "whatever"), options.keyvalue_pairs.items())
def test_logging(self): self.setup_environment() cli = CommandLineClient() cli.keyvalue_pairs = True cli.setup_parser() options = cli.parse_args(["foo=bar", "--log-level", "info"]) cli.setup_logging() self.assertEquals(options.log_level, logging.INFO)
def test_fileinput_missing_file(self): self.setup_environment() filename = "missing" # the @ sign maps to an argparse.File cli = CommandLineClient() cli.keyvalue_pairs = True cli.default_mode = "rb" cli.setup_parser() # files in read-mode must exist at the time of the parse self.assertRaises(JujuError, cli.parse_args, ["foo=@%s" % filename])
def test_without_keyvalue_flag(self): self.setup_environment() output = self.capture_stream("stderr") cli = CommandLineClient() cli.keyvalue_pairs = False cli.setup_parser() # exit with the proper error code and make sure a message # appears on stderr error = self.assertRaises(SystemExit, cli.parse_args, ["foo=bar"]) self.assertEqual(error.code, 2) self.assertIn("unrecognized arguments: foo=bar", output.getvalue())
def test_fileinput(self): self.setup_environment() filename = self.makeFile("""This is config""") # the @ sign maps to an argparse.File cli = CommandLineClient() cli.keyvalue_pairs = True cli.default_mode = "rb" cli.setup_parser() options = cli.parse_args(["foo=@%s" % filename]) contents = options.keyvalue_pairs["foo"] self.assertEquals("This is config", contents)
def test_single_keyvalue(self): """ Verify that a single key/vaule setting can be properly read from the command line. """ self.setup_environment() cli = CommandLineClient() cli.keyvalue_pairs = True cli.setup_parser() options = cli.parse_args(["foo=bar"]) self.assertEqual(options.keyvalue_pairs["foo"], "bar") # need to verify this is akin to the sys.argv parsing that # will occur with single and double quoted strings around # foo's right hand side options = cli.parse_args(["foo=bar none"]) self.assertEqual(options.keyvalue_pairs["foo"], "bar none")