def testCombined(self): input = "foo bar" grammar = textwrap.dedent( r"""grammar T4; options { language = Python; } r returns [res]: (ID)+ EOF { $res = $text; }; ID: 'a'..'z'+; WS: ' '+ { $channel = HIDDEN; }; """) stdout = StringIO() lexerMod, parserMod = self.compileInlineGrammar(grammar, returnModule=True) parserMod.main( ['combined.py', '--rule', 'r'], stdin=StringIO(input), stdout=stdout ) stdout = stdout.getvalue() self.failUnlessEqual(len(stdout.splitlines()), 1, stdout)
def test_separators(self): testio = StringIO() dump_servers(self.servers, testio, '|') testio = testio.getvalue() assert '|' in testio for line in testio.splitlines(): if ':memory:' not in line: assert ':' not in line
def python(script): """Run a python script on the host""" script = StringIO(script) fab.run('mkdir -p ~/fab/scripts') script_path = '~/fab/scripts/{script_name}.py'.format(script_name=uuid.uuid1()) fab.put(script, script_path) output = StringIO() with fab.settings(warn_only=True): retval = fab.run( 'python {script_path}'.format(script_path=script_path), stdout=output, stderr=output ) output.seek(0) output = output.read() if retval.return_code != 0: logger.info(output) raise Exception('Error while running python script') return output.splitlines()