def test_handle_custom_s3(self): cmd = ['s3', 'ls'] with captured_output() as (out, err): self.checker.check(cmd) expected = text_type( 'Checks for s3 file commands are not supported.\n') self.assertEqual(out.getvalue(), expected)
def test_level_formatter(self): with captured_output() as (out, err): self._init_level_formatter() log = logging.getLogger() log.setLevel(logging.DEBUG) log.warning('warning message') log.info('info message') log.debug('debug message') expected = ('default-> WARNING: warning message\n' 'info message\n' 'DEBUG: debug message\n') self.assertEqual(out.getvalue(), expected)
def check_command(self, cmd, args): with captured_output() as (out, err): self.pm.handle_command(cmd, args) return out.getvalue()
def test_handle_no_path(self, captured_log): self.argv[1] = '--bac-no-check' with captured_output() as (out, err): batch.CommandBatch(self.globals, self.argv, self.checker) check_logs(captured_log, 'bac.utils', 'ERROR', 'arguments')
def test_handle_no_commands(self, captured_log): self.argv = self.argv[:1] with captured_output() as (out, err): batch.CommandBatch(self.globals, self.argv, self.checker) check_logs(captured_log, 'bac.utils', 'ERROR', 'arguments')
def test_handle_output(self, execute_command): execute_command.return_value = (b'Some output', '', 0) with captured_output() as (out, err): batch.CommandBatch(self.globals, self.argv, self.checker) expected = text_type('Some output\n') self.assertEqual(out.getvalue(), expected)
def test_handle_missing_parameter(self): cmd = ['s3api', 'list-objects'] with captured_output() as (out, err): with self.assertRaises(errors.CLICheckerSyntaxError): self.checker.check(cmd)
def test_globals_parser_error(self, captured_log): parser = utils.GlobalsParser() with captured_output() as (out, err): parser.error('Error') check_logs(captured_log, 'bac.utils', 'WARNING', 'error: Error\n')
def test_globals_parser_help(self): parser = utils.GlobalsParser() argv = ['--help'] with captured_output() as (out, err): parser.parse_args(argv)
def test_arg_parser_help(self, captured_log): parser = utils.ArgumentParser() argv = ['--help'] with self.assertRaises(errors.ArgumentParserDoneException): with captured_output() as (out, err): parser.parse_args(argv)