예제 #1
0
 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
예제 #2
0
 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)
예제 #3
0
 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())
예제 #4
0
 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())
예제 #5
0
 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
예제 #6
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)
예제 #7
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)
예제 #8
0
 def testParseCommandLineVerboseDebug(self):
     a = app.NssCacheApp()
     a.Run(['-v', '-d'], {})
     self.assertEquals(logging.DEBUG, a.log.getEffectiveLevel())
예제 #9
0
 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)
예제 #10
0
 def testRun(self):
     return_code = app.NssCacheApp().Run([], {})
     self.assertEquals(os.EX_USAGE, return_code)