Ejemplo n.º 1
0
def test_browser():
    tmp = py.test.ensuretemp("sourcebrowser")
    tmp.ensure("a.py").write(py.code.Source("""
    def f():
        pass
    
    def g():
        pass
        
    class X:
        pass
        
    class Z(object):
        x = 1
        def zzz(self):
            1
            2
            3
            4
    """))
    mod = parse_path(tmp.join("a.py"))
    assert isinstance(mod.g, Function)
    assert isinstance(mod.Z, Class)
    py.test.raises(AttributeError, "mod.zzz")
    assert mod.g.firstlineno == 5
    assert mod.g.name == "g"
    assert mod.g.endlineno == 6
    assert mod.X.firstlineno == 8
    assert mod.X.endlineno == 9
    assert mod.Z.bases == ["object"]
    assert isinstance(mod.Z.zzz, Method)
    assert mod.Z.zzz.firstlineno == 13
    assert mod.Z.zzz.endlineno == 17
Ejemplo n.º 2
0
def test_bases():
    tmp = py.test.ensuretemp("sourcebrowser")
    tmp.ensure("c.py").write(py.code.Source("""
    import py
    class Dir(py.test.collect.Directory):
        pass
    """))
    mod = parse_path(tmp.join("c.py"))
Ejemplo n.º 3
0
 def f(rev='HEAD'):
     path = py.path.svnurl(url, rev)
     # some try.. except.. here
     if path.check(file=True):
         return unicode(create_html(parse_path(path)))
     elif path.check(dir=True):
         return create_dir_html(path)
     else:
         return create_unknown_html(path)
Ejemplo n.º 4
0
def test_importing_goes_wrong():
    tmp = py.test.ensuretemp("sourcebrowserimport")
    tmp.ensure("x.py").write(py.code.Source("""
        import aslkdjaslkdjasdl
    """))
    mod = parse_path(tmp.join("x.py"))

    tmp.ensure("y.py").write(py.code.Source("""
        raise KeyboardInterrupt 
    """))
    py.test.raises(KeyboardInterrupt, 'parse_path(tmp.join("y.py"))')
Ejemplo n.º 5
0
def test_if_browser():
    tmp = py.test.ensuretemp("sourcebrowser")
    tmp.ensure("b.py").write(py.code.Source("""
        if 1:
            def f():
                pass
        if 0:
            def g():
                pass
    """))
    mod = parse_path(tmp.join("b.py"))
    assert isinstance(mod.f, Function)
    py.test.raises(AttributeError, 'mod.g')
Ejemplo n.º 6
0
def prepare_module(path, tokenizer, encoding):
    path = py.path.local(path)
    try:
        mod = parse_path(path)
    except:
        # XXX don't try to catch SystemExit: it's actually raised by one
        # of the modules in the py lib on import :(
        exc, e, tb = py.std.sys.exc_info()
        del tb
        raise CompilationException('while compiling %s: %s - %s' % (
                                    path, e.__class__.__name__, e))
    lines = [unicode(l, encoding) for l in path.readlines()]
    
    enchanter = HtmlEnchanter(mod)
    ret = []
    for i, line in enumerate(lines):
        text = enchanter.enchant_row(i + 1, line)
        if text == ['']:
            text = [raw(' ')]
        else:
            text = prepare_line(text, tokenizer, encoding)
        ret.append(text)
    return ret
Ejemplo n.º 7
0
def create_html_and_show(path):
    mod = parse_path(path)
    html = create_html(mod)
    testfile = py.test.ensuretemp("htmloutput").ensure("test.html")
    testfile.write(unicode(html))
    return testfile