Exemplo n.º 1
0
 def test_default_args(self):
     args = parse_args([])
     assert args.filename is None
     assert args.text_attribute == 'text'
     assert args.pretty == False
     assert args.indent == 2
     assert args.outputfile is None
Exemplo n.º 2
0
def main(argv=None, stdin=sys.stdin):
    if not argv:
        argv = sys.argv[1:]
    args = parse_args(argv)
    if args.filename:
        nodes = parse_file(args.filename, args.text_attribute)
    else:
        nodes = parse_string(stdin.read(), args.text_attribute)
    if args.pretty:
        try:
            output = '\n'.join(pprint(nodes, args.indent))
        except ValueError, e:
            errmsg = 'Error: %s' % e
            # prepend a newline before the error message if no filename was
            # given to distinguish it from the input
            if not args.filename:
                errmsg = '\n' + errmsg
            return errmsg
Exemplo n.º 3
0
 def test_indent_negative(self):
     args = parse_args(['-i', '-1337'])
     assert args.indent == 2
Exemplo n.º 4
0
 def test_indent_basic(self, argv):
     args = parse_args(argv)
     assert args.indent == 42
Exemplo n.º 5
0
 def test_filename_with_directory(self, option, tmpdir, capsys):
     with pytest.raises(SystemExit):
         parse_args([option, str(tmpdir)])
     out, err = capsys.readouterr()
     assert out == ''
     assert err.strip().endswith('is not a file')
Exemplo n.º 6
0
 def test_nonexistent_filename(self, argv, capsys):
     with pytest.raises(SystemExit):
         parse_args(argv)
     out, err = capsys.readouterr()
     assert out == ''
     assert err.strip().endswith('does not exist')