示例#1
0
 def test_generation_modules(self):
     ds = self.get_filled_docstorage_modules()
     lg = DirectPaste()
     tempdir = temppath.ensure('module_api', dir=True)
     r = RestGen(ds, lg, DirWriter(tempdir))
     r.write()
     basenames = [p.basename for p in tempdir.listdir('*.txt')]
     expected = [
         'class_somemodule.SomeClass.txt',
         'class_someothermodule.SomeSubClass.txt',
         'function_someothermodule.fun.txt',
         'index.txt',
         'method_somemodule.SomeClass.__init__.txt',
         'method_somemodule.SomeClass.method.txt',
         'method_someothermodule.SomeSubClass.__init__.txt',
         'method_someothermodule.SomeSubClass.method.txt',
         'module_Unknown module.txt',
         'module_somemodule.txt',
         'module_someothermodule.txt',
         'traceback_somemodule.SomeClass.__init__.0.txt',
         'traceback_someothermodule.SomeSubClass.__init__.0.txt',
         'traceback_someothermodule.SomeSubClass.method.0.txt',
         'traceback_someothermodule.fun.0.txt',
         'traceback_someothermodule.fun.1.txt',
     ]
     print sorted(basenames)
     assert sorted(basenames) == expected
示例#2
0
    def test_check_internal_links(self):
        ds = self.get_filled_docstorage()
        lg = DirectFS()
        tempdir = temppath.ensure('internal_links', dir=True)
        r = RestGen(ds, lg, DirWriter(tempdir))
        r.write()
        index = tempdir.join('module_Unknown module.txt')
        assert index.check(file=True)
        data = _nl(index.read())
        assert data.find('.. _`fun`: function_fun.html\n') > -1
        assert data.find('.. _`fun`: #function-fun\n') == -1

        tempfile = temppath.ensure('internal_links.txt',
                                  file=True)
        r = RestGen(ds, lg, FileWriter(tempfile))
        r.write()
        data = _nl(tempfile.read())
        assert data.find('.. _`fun`: #function-fun\n') > -1
        assert data.find('.. _`fun`: function_fun.html') == -1
        tempfile = temppath.ensure("internal_links_ps.txt", file=True)
        if 0:
            ps = PermaDocStorage(ds)
            r = RestGen(ps, lg, FileWriter(tempfile))
            r.write()
            data = _nl(tempfile.read())
            assert data.find('.. _`fun`: #function-fun\n') > -1
            assert data.find('.. _`fun`: function_fun.html') == -1
            pickle.dumps(ps)
示例#3
0
 def test_som_fun(self):
     descs = {'fun_': fun_}
     ds = DocStorage().from_dict(descs)
     t = Tracer(ds)
     t.start_tracing()
     fun_()
     t.end_tracing()
     lg = DirectPaste()
     tempdir = temppath.ensure("some_fun", dir=True)
     r = RestGen(DocStorageAccessor(ds), lg, DirWriter(tempdir))
     r.write()
     self.check_rest(tempdir)
示例#4
0
    def test_sourceview_fun(self):
        def f():
            pass

        descs = {'f':f}
        ds = DocStorage().from_dict(descs)
        t = Tracer(ds)
        t.start_tracing()
        f()
        t.end_tracing()
        tempdir = temppath.ensure("sourceview_fun", dir=True)
        lg = SourceView('http://localhost:8000')
        r = RestGen(DocStorageAccessor(ds), lg, DirWriter(tempdir))
        r.write()
        self.check_rest(tempdir)
        assert tempdir.join('function_f.txt').open().read().find(
            '.. _`/py/apigen/rest/testing/test\_rest.py\:f`: http://localhost:8000/py/apigen/rest/testing/test_rest.py#f') != -1
示例#5
0
 def test_sourceview(self):
     class A:
         def method(self):
             pass
     
     descs = {'A':A}
     ds = DocStorage().from_dict(descs)
     t = Tracer(ds)
     t.start_tracing()
     A().method()
     t.end_tracing()
     lg = SourceView('http://localhost:8000')
     tempdir = temppath.ensure("sourceview", dir=True)
     r = RestGen(DocStorageAccessor(ds), lg, DirWriter(tempdir))
     r.write()
     self.check_rest(tempdir)
     assert tempdir.join('traceback_A.method.0.txt').open().read().find(
        '.. _`/py/apigen/rest/testing/test\_rest.py\:A.method`: http://localhost:8000/py/apigen/rest/testing/test_rest.py#A.method') != -1
示例#6
0
 def test_nonexist_origin(self):
     class A:
         def method(self):
             pass
     
     class B(A):
         pass
     
     descs = {'B':B}
     ds = DocStorage().from_dict(descs)
     t = Tracer(ds)
     t.start_tracing()
     B().method()
     t.end_tracing()
     lg = DirectPaste()
     tempdir = temppath.ensure("nonexit_origin", dir=True)
     r = RestGen(DocStorageAccessor(ds), lg, DirWriter(tempdir))
     r.write()
     self.check_rest(tempdir)
示例#7
0
 def test_exc_raising(self):
     def x():
         try:
             1/0
         except:
             pass
     
     descs = {'x':x}
     ds = DocStorage().from_dict(descs)
     t = Tracer(ds)
     t.start_tracing()
     x()
     t.end_tracing()
     lg = DirectPaste()
     tempdir = temppath.ensure("exc_raising", dir=True)
     r = RestGen(DocStorageAccessor(ds), lg, DirWriter(tempdir))
     r.write()
     source = tempdir.join('function_x.txt').open().read()
     assert source.find('ZeroDivisionError') < source.find('call sites\:')
示例#8
0
    def test_class_typedefs(self):
        class A(object):
            def __init__(self, x):
                pass

            def a(self):
                pass
        
        class B(A):
            def __init__(self, y):
                pass
        
        def xxx(x):
            return x
        
        descs = {'A': A, 'B': B, 'xxx':xxx}
        ds = DocStorage().from_dict(descs)
        t = Tracer(ds)
        t.start_tracing()
        xxx(A(3))
        xxx(B("f"))
        t.end_tracing()
        lg = DirectPaste()
        tempdir = temppath.ensure("classargs", dir=True)
        r = RestGen(DocStorageAccessor(ds), lg, DirWriter(tempdir))
        r.write()
        source = tempdir.join("function_xxx.txt").read()
        call_point = source.find("call sites\:")
        assert call_point != -1
        print source
        assert -1 < source.find("x \:\: <Instance of AnyOf( `Class B`_ , "
                                "`Class A`_ )>") < call_point
        source = tempdir.join('method_B.a.txt').read()
        py.test.skip('XXX needs to be fixed, clueless atm though')
        assert source.find('**origin** \: `A`_') > -1
        self.check_rest(tempdir)
示例#9
0
 def test_function_arguments(self):
     def blah(a, b, c):
         return "axx"
     
     class C:
         pass
     
     descs = {'blah':blah}
     ds = DocStorage().from_dict(descs)
     t = Tracer(ds)
     t.start_tracing()
     blah(3, "x", C())
     t.end_tracing()
     lg = DirectPaste()
     tempdir = temppath.ensure("function_args", dir=True)
     r = RestGen(DocStorageAccessor(ds), lg, DirWriter(tempdir))
     r.write()
     source = tempdir.join("function_blah.txt").read()
     call_point = source.find("call sites\:")
     assert call_point != -1
     assert source.find("a \:\: <Int>") < call_point
     assert source.find("b \:\: <String>") < call_point
     assert source.find("c \:\: <Instance of Class C>") < call_point
     self.check_rest(tempdir)
示例#10
0
 def test_function_source(self):
     def blah():
         a = 3
         b = 4
         return a + b
     
     descs = {'blah': blah}
     ds = DocStorage().from_dict(descs)
     t = Tracer(ds)
     t.start_tracing()
     blah()
     t.end_tracing()
     lg = DirectPaste()
     tempdir = temppath.ensure("function_source", dir=True)
     r = RestGen(DocStorageAccessor(ds), lg, DirWriter(tempdir))
     r.write()
     assert tempdir.join("function_blah.txt").read().find("a = 3") != -1
     self.check_rest(tempdir)
     ps = DocStorageAccessor(ds)
     r = RestGen(ps, lg, DirWriter(tempdir))
     r.write()
     assert tempdir.join("function_blah.txt").read().find("a = 3") != -1
示例#11
0
 def test_generation_simple_api(self):
     ds = self.get_filled_docstorage()
     lg = DirectPaste()
     tempdir = temppath.ensure("simple_api", dir=True)
     r = RestGen(ds, lg, DirWriter(tempdir))
     r.write()
     basenames = [p.basename for p in tempdir.listdir('*.txt')]
     expected = [
         'class_SomeClass.txt',
         'class_SomeSubClass.txt',
         'function_fun.txt',
         'index.txt',
         'method_SomeClass.__init__.txt',
         'method_SomeClass.method.txt',
         'method_SomeSubClass.__init__.txt',
         'method_SomeSubClass.method.txt',
         'module_Unknown module.txt',
         'traceback_SomeClass.__init__.0.txt',
         'traceback_SomeSubClass.__init__.0.txt',
         'traceback_SomeSubClass.method.0.txt',
         'traceback_fun.0.txt',
         'traceback_fun.1.txt',
     ]
     print sorted(basenames)
     assert sorted(basenames) == expected
     # now we check out...
     self.check_rest(tempdir)
     tempdir = temppath.ensure("simple_api_ps", dir=True)
     if 0:
         ps = PermaDocStorage(ds)
         r = RestGen(ps, lg, DirWriter(tempdir))
         r.write()
         basenames = [p.basename for p in tempdir.listdir('*.txt')]
         assert sorted(basenames) == expected
         self.check_rest(tempdir)
         pickle.dumps(ps)