def test_redirect_all(self): with io.StringIO() as o, redirect_all(o): import sys sys.stdout.write("YAY!") sys.stderr.write("EEK!") stdall = o.getvalue() self.assertEqual(stdall, "YAY!EEK!")
def test_redirect_all_separate(self): with io.StringIO() as o, io.StringIO() as e, redirect_all(o, e): import sys sys.stdout.write("YAY!") sys.stderr.write("EEK!") stdout = o.getvalue() stderr = e.getvalue() self.assertEqual(stdout, "YAY!") self.assertEqual(stderr, "EEK!")
def _test_run_command(self): """ with no args, runner reads config, but does not setup app help msg is printed to stdout """ from aio import app conf = os.path.join( test_dir, "resources", "test-2.conf") with io.StringIO() as out, redirect_all(out): yield from runner(['run'], configfile=conf) stdout = out.getvalue() self.assertEqual(stdout, "") # config has been loaded self.assertIsInstance(app.config, ConfigParser) # signals have been added self.assertIsInstance(app.signals, Signals)
def test_runner_no_command(self): """ with no args, runner reads config, but does not setup app help msg is printed to stdout """ from aio import app with io.StringIO() as o, io.StringIO() as e, redirect_all(o, e): runner([]) stdout = o.getvalue() # print help msg self.assertTrue( stdout.startswith( 'usage: aio [-h] [-c [C]] {run,config,test}\n\naio')) # config has been loaded self.assertIsInstance(app.config, ConfigParser) # no signals have been set up self.assertIsNone(getattr(app, 'signals', None))
def test_runner_bad_command(self): from aio import app with io.StringIO() as o, io.StringIO() as e, redirect_all(o, e): runner(['BAD']) stdout = o.getvalue() stderr = e.getvalue() self.assertTrue( stderr.strip().endswith( "invalid choice: 'BAD' (choose from 'run', 'config', 'test')")) self.assertTrue( stdout.startswith( 'usage: aio [-h] [-c [C]] {run,config,test}')) # config is set up self.assertIsInstance(app.config, ConfigParser) # signals are not self.assertIsNone(app.signals) # builtin modules are set up self.assertEqual(app.modules, (aio.app, ))