<s> import os <EOL> from nagcat . unittests . queries import QueryTestCase <EOL> from nagcat import errors <EOL> class SubprocessQueryTestCase ( QueryTestCase ) : <EOL> def testBasic ( self ) : <EOL> q , d = self . startQuery2 ( type = '<STR_LIT>' , command = '<STR_LIT>' ) <EOL> d . addCallback ( self . assertEquals , "<STR_LIT>" ) <EOL> d . addCallback ( lambda x : self . assert_ ( '<STR_LIT>' not in q . saved ) ) <EOL> return d <EOL> def testStderr ( self ) : <EOL> q , d = self . startQuery2 ( type = '<STR_LIT>' , command = '<STR_LIT>' ) <EOL> d . addCallback ( self . assertEquals , "<STR_LIT>" ) <EOL> d . addCallback ( lambda x : self . assertEquals ( q . saved [ '<STR_LIT>' ] , "<STR_LIT>" ) ) <EOL> return d <EOL> def testTrue ( self ) : <EOL> d = self . startQuery ( type = '<STR_LIT>' , command = '<STR_LIT:true>' ) <EOL> d . addCallback ( self . assertEquals , "<STR_LIT>" ) <EOL> return d <EOL> def testFalse ( self ) : <EOL> def check ( result ) : <EOL> self . assertIsInstance ( result , errors . Failure ) <EOL> self . assertIsInstance ( result . value , errors . TestCritical ) <EOL> d = self . startQuery ( type = '<STR_LIT>' , command = '<STR_LIT:false>' ) <EOL> d . addBoth ( check ) <EOL> return d <EOL> def testEnvGood ( self ) : <EOL> c = { '<STR_LIT:type>' : "<STR_LIT>" , <EOL> '<STR_LIT>' : "<STR_LIT>" , <EOL> '<STR_LIT>' : { <EOL> '<STR_LIT>' : os . path . dirname ( __file__ ) } } <EOL> d = self . startQuery ( c ) <EOL> d . addCallback ( self . assertEquals , "<STR_LIT>" ) <EOL> return d <EOL> def testEnvBad ( self ) : <EOL> def check ( result ) : <EOL> self . assertIsInstance ( result , errors . Failure ) <EOL> self . assertIsInstance ( result . value , errors . TestCritical ) <EOL> d = self . startQuery ( type = '<STR_LIT>' , command = '<STR_LIT>' ) <EOL> d . addBoth ( check ) <EOL> return d <EOL> class NagiosPluginQueryTestCase ( QueryTestCase ) : <EOL> def testOK ( self ) : <EOL> d = self . startQuery ( type = '<STR_LIT>' , command = '<STR_LIT>' ) <EOL> d . addCallback ( self . assertEquals , "<STR_LIT>" ) <EOL> return d <EOL> def testWarning ( self ) : <EOL> def check ( reason ) : <EOL> self . assertIsInstance ( reason , errors . Failure ) <EOL> self . assertIsInstance ( reason . value , errors . TestWarning ) <EOL> self . assertEquals ( reason . result , "<STR_LIT>" ) <EOL> d = self . startQuery ( type = '<STR_LIT>' , command = '<STR_LIT>' ) <EOL> d . addBoth ( check ) <EOL> return d <EOL> def testCritical ( self ) : <EOL> def check ( reason ) : <EOL> self . assertIsInstance ( reason , errors . Failure ) <EOL> self . assertIsInstance ( reason . value , errors . TestCritical ) <EOL> self . assertEquals ( reason . result , "<STR_LIT>" ) <EOL> d = self . startQuery ( type = '<STR_LIT>' , command = '<STR_LIT>' ) <EOL> d . addBoth ( check ) <EOL> return d <EOL> def testUnknown ( self ) : <EOL> def check ( reason ) : <EOL> self . assertIsInstance ( reason , errors . Failure ) <EOL> self . assertIsInstance ( reason . value , errors . TestUnknown ) <EOL> self . assertEquals ( reason . result , "<STR_LIT>" ) <EOL> d = self . startQuery ( type = '<STR_LIT>' , command = '<STR_LIT>' ) <EOL> d . addBoth ( check ) <EOL> return d <EOL> def testUnknown2 ( self ) : <EOL> def check ( reason ) : <EOL> self . assertIsInstance ( reason , errors . Failure ) <EOL> self . assertIsInstance ( reason . value , errors . TestUnknown ) <EOL> self . assertEquals ( reason . result , "<STR_LIT>" ) <EOL> d = self . startQuery ( type = '<STR_LIT>' , command = '<STR_LIT>' ) <EOL> d . addBoth ( check ) <EOL> return d </s>
