def test_parsers__get_blocks__json(): data = '```env\na=b\n```\n```bash#test1\nls\n```\n\n```bash#test2\nls -al\n```' input = io.StringIO() input.write(data) input.seek(0) got_blocks = rp.get_blocks(input) input.seek(0) expect = rp.parse_doc(input) assert json.loads(got_blocks) == expect.get_dict()
def test_parsers__parse_doc(): f = io.StringIO() data = '```env\na=b\n```\n```bash#test1\nls\n```\n\n```bash#test2\nls -al\n```' expected = rc.DocCommander() expected.add('ls\n', ['bash', 'test1']) expected.add('ls -al\n', ['bash', 'test2']) f.write(data) f.seek(0) c = rp.parse_doc(f, 'bash') assert c.get_dict() == expected.get_dict()
def test_parsers__parse_doc__single_session(): f = io.StringIO() data = '```env\na=b\n```\n```bash#test1\nls\n```\n\n```bash#test2\nls -al\n```' expected = rc.DocCommander() expected.add('ls\nls -al\n', ['bash']) expected.env.import_string("a=b") f.write(data) f.seek(0) c = rp.parse_doc(f, single_session='bash') assert c.get_dict() == expected.get_dict()
def test_parsers__parse_output(): data = '```env\na=b\n```\n```bash#test1\nls\n```\n\n```bash#test2\nls -al\n```' input = io.StringIO() input.write(data) input.seek(0) c1 = rp.parse_doc(input) json1 = json.dumps(c1.get_dict()) output = io.StringIO() output.name = 'test' c1.output = output c1.run() output.seek(0) c2 = rp.parse_output(output) json2 = json.dumps(c2.get_dict()) assert json1 == json2
def run(**kwargs): # pragma: no cover "Run code from markdown file." if kwargs['yes']: print( "{}Deprecated option: -y, --yes. See -a, --ask instead.{}".format( ansi.yellow, ansi.end)) try: commander = parsers.parse_doc(**kwargs) except rundoc.BadEnv as e: print("{}{}{}".format(ansi.red, e, ansi.end)) sys.exit(1) try: commander.run(**kwargs) except KeyboardInterrupt: commander.die_with_grace() sys.exit(1) except rundoc.BadEnv as e: print("{}{}{}".format(ansi.red, e, ansi.end)) sys.exit(1) except rundoc.CodeFailed as e: sys.exit(1)