def test_collect_command_errors(self): sys.argv = ['lowatt-collect', 'collect', join(THIS_DIR, 'sources.yml')] stream = StringIO() with redirect_stdout(stream), self.assertRaises(SystemExit) as cm: run() self.assertEqual(cm.exception.code, 2)
def test_collect_specific_source_extra_args(self): sys.argv = ['lowatt-collect', 'collect', join(THIS_DIR, 'sources.yml'), 's2', '--hop', 'extra'] stream = StringIO() with redirect_stdout(stream), self.assertRaises(SystemExit) as cm: run() self.assertEqual(cm.exception.code, 0)
def test_collect_error_unexisting_specific_source(self): sys.argv = ['lowatt-collect', 'collect', join(THIS_DIR, 'sources.yml'), 's3'] stream = StringIO() with redirect_stderr(stream), self.assertRaises(SystemExit) as cm: run() self.assertEqual(cm.exception.code, 2) self.assertIn('unexisting source s3', stream.getvalue())
def test_no_command(self): sys.argv = ['lowatt-collect'] stream = StringIO() with redirect_stdout(stream), self.assertRaises(SystemExit) as cm: run() self.assertEqual(cm.exception.code, 1) self.assertTrue( stream.getvalue().startswith('usage:'), stream.getvalue().splitlines()[0] + '...', )
def test_unexisting_sources_file(self): sys.argv = ['lowatt-collect', 'collect', 'unexisting_sources.yml'] stream = StringIO() with redirect_stdout(stream), self.assertRaises(SystemExit) as cm: run() self.assertEqual(cm.exception.code, 1) output = stream.getvalue() self.assertTrue( output.startswith('An error occured while reading sources file:'), output.splitlines()[0] + '...', )