def test_method_run_output_stdout(self): watch = cwatcher.Watch(config_file=CONF, service_name='test') with Capturing() as output: process = watch.run(self.cmd_stdout) self.assertEqual(process.subprocess.returncode, 0) self.assertEqual(len(output), 3) self.assertIn('STDOUT', output[1]) self.assertIn('One line to stdout!', output[1]) self.assertIn('Execution time: ', output[2])
def test_method_run_output_stderr(self): watch = cwatcher.Watch( config_file=CONF, service_name='test', raise_exceptions=False, ) with Capturing(stream='stderr') as output: process = watch.run(self.cmd_stderr) self.assertEqual(process.subprocess.returncode, 1) # On travis # ['Exception in thread Thread-59:', 'Trace[993 chars][0m'] != '' # self.assertEqual(len(output), 1) self.assertIn('STDERR', output.tostring()) self.assertIn('One line to stderr!', output.tostring())
def test_stdout(self): with Capturing() as output: print('line 1') print('line 2') self.assertEqual(output, ['line 1', 'line 2'])
def test_argument_clean_ansi_false(self): with Capturing(clean_ansi=False) as output: cprint('line 1', color='red') self.assertEqual(output, ['\x1b[31mline 1\x1b[0m'])
def test_argument_clean_ansi_true(self): with Capturing(clean_ansi=True) as output: cprint('line 1', color='red') self.assertEqual(output, ['line 1'])
def test_argument_stream_stderr_with_stderr(self): with Capturing(stream='stderr') as output: print('line 1', file=sys.stderr) self.assertEqual(output, ['line 1'])
def test_argument_stream_stderr_with_stdout(self): with Capturing(stream='stderr') as output: print('line 1') self.assertEqual(output, [])
def test_method_tostring(self): with Capturing() as output: print('line 1') self.assertEqual(output.tostring(), 'line 1')
def test_debug(self): with Capturing() as output: self.logger.debug('DEBUG 10') self.assertEqual( output[0][20:], '\x1b[7m\x1b[37m DEBUG \x1b[0m \x1b[37mDEBUG 10\x1b[0m')
def test_info(self): with Capturing() as output: self.logger.info('INFO 20') self.assertEqual( output[0][20:], '\x1b[7m\x1b[32m INFO \x1b[0m \x1b[32mINFO 20\x1b[0m')
def test_warning(self): with Capturing() as output: self.logger.warning('WARNING 30') self.assertEqual( output[0][20:], '\x1b[7m\x1b[33m WARNING \x1b[0m \x1b[33mWARNING 30\x1b[0m')
def test_stderr(self): with Capturing(stream='stderr') as output: self.logger.stderr('STDERR 35') self.assertEqual( output[0][20:], '\x1b[2m\x1b[7m\x1b[31m STDERR ' '\x1b[0m \x1b[2m\x1b[31mSTDERR 35\x1b[0m')
def test_error(self): with Capturing(stream='stderr') as output: self.logger.error('ERROR 40') self.assertEqual( output[0][20:], '\x1b[7m\x1b[31m ERROR \x1b[0m \x1b[31mERROR 40\x1b[0m')
def test_critical(self): with Capturing(stream='stderr') as output: self.logger.critical('CRITICAL 50') self.assertEqual( output[0][20:], '\x1b[1m\x1b[7m\x1b[31m CRITICAL ' '\x1b[0m \x1b[1m\x1b[31mCRITICAL 50\x1b[0m')
def test_noset(self): with Capturing() as output: self.logger.log(1, 'NOTSET 0') self.assertEqual( output[0][20:], '\x1b[7m\x1b[30m Level 1 \x1b[0m \x1b[30mNOTSET 0\x1b[0m')
def test_stdout(self): with Capturing() as output: self.logger.stdout('STDOUT 5') self.assertEqual( output[0][20:], '\x1b[2m\x1b[7m\x1b[37m STDOUT \x1b[0m ' '\x1b[2m\x1b[37mSTDOUT 5\x1b[0m')