def testBadOptionsCauseNoExit(self): a = app.NssCacheApp() stderr_buffer = StringIO.StringIO() old_stderr = sys.stderr sys.stderr = stderr_buffer self.assertEquals(2, a.Run(['--invalid'], {})) sys.stderr = old_stderr
def testParseCommandLineConfigFile(self): a = app.NssCacheApp() (options, args) = a.parser.parse_args(['-c', 'file']) self.failIfEqual(None, options.config_file) self.assertEqual([], args) (options, args) = a.parser.parse_args(['--config-file', 'file']) self.failIfEqual(None, options.config_file) self.assertEqual([], args)
def testParseCommandLineDebug(self): a = app.NssCacheApp() (options, args) = a.parser.parse_args(['-d']) self.failIfEqual(None, options.debug) (options, args) = a.parser.parse_args(['--debug']) self.failIfEqual(None, options.debug) a.Run(['-d'], {}) self.assertEquals(logging.DEBUG, a.log.getEffectiveLevel())
def testParseCommandLineVerbose(self): a = app.NssCacheApp() (options, args) = a.parser.parse_args(['-v']) self.failIfEqual(None, options.verbose) self.assertEqual([], args) (options, args) = a.parser.parse_args(['--verbose']) self.failIfEqual(None, options.verbose) self.assertEqual([], args) a.Run(['-v'], {}) self.assertEquals(logging.INFO, a.log.getEffectiveLevel())
def testRunBadArgsPrintsGlobalHelp(self): # trap stdout into a StringIO stdout_buffer = io.StringIO() old_stdout = sys.stdout sys.stdout = stdout_buffer # verify bad arguments calls help return_code = app.NssCacheApp().Run(['blarg'], {}) sys.stdout = old_stdout assert return_code == 1 assert stdout_buffer.getvalue().find('enable debugging') >= 0
def testHelpCommandOutput(self): # trap stdout into a StringIO stdout_buffer = StringIO.StringIO() a = app.NssCacheApp() old_stdout = sys.stdout sys.stdout = stdout_buffer self.assertEquals(0, a.Run(['help'], {})) sys.stdout = old_stdout self.failIfEqual(0, stdout_buffer.tell()) self.failUnless( stdout_buffer.getvalue().find('nsscache synchronises') >= 0)
def testHelpOptionPrintsGlobalHelp(self): stdout_buffer = StringIO.StringIO() a = app.NssCacheApp() old_stdout = sys.stdout sys.stdout = stdout_buffer self.assertEquals(0, a.Run(['--help'], {})) sys.stdout = old_stdout self.failIfEqual(0, stdout_buffer.tell()) (prelude, usage, commands, options) = stdout_buffer.getvalue().split('\n\n') self.failUnless(prelude.startswith('nsscache synchronises')) expected_str = 'Usage: nsscache [global options] command [command options]' self.failUnlessEqual(expected_str, usage) self.failUnless(commands.startswith('commands:')) self.failUnless(options.startswith('Options:')) self.failUnless(options.find('show this help message and exit') >= 0)
def testParseCommandLineVerboseDebug(self): a = app.NssCacheApp() a.Run(['-v', '-d'], {}) self.assertEquals(logging.DEBUG, a.log.getEffectiveLevel())
def testParseGlobalOptions(self): a = app.NssCacheApp() (options, args) = a.parser.parse_args(['-d', '-v', 'command']) self.failIfEqual(None, options.debug) self.failIfEqual(None, options.verbose) self.assertEqual(['command'], args)
def testRun(self): return_code = app.NssCacheApp().Run([], {}) self.assertEquals(os.EX_USAGE, return_code)