示例#1
0
 def test_app_static_routes(self, verbose, internal):
     sv = inspect.StringVisitor(verbose, internal)
     app = inspect.inspect_app(make_app())
     app.static_routes.clear()
     assert inspect.StringVisitor(verbose, internal).process(app) == self.make(
         sv, app, verbose, internal, sr=False
     )
示例#2
0
    def test_app(self, verbose, internal):
        sv = inspect.StringVisitor(verbose, internal)
        app = inspect.inspect_app(make_app())

        assert inspect.StringVisitor(verbose,
                                     internal).process(app) == self.make(
                                         sv, app, verbose, internal)
示例#3
0
 def test_app_no_errors(self, verbose, internal):
     sv = inspect.StringVisitor(verbose, internal)
     app = inspect.inspect_app(make_app())
     app.error_handlers.clear()
     assert inspect.StringVisitor(verbose, internal).process(app) == self.make(
         sv, app, verbose, internal, e=False
     )
示例#4
0
 def test_app_no_sink(self, verbose, internal):
     sv = inspect.StringVisitor(verbose, internal)
     app = inspect.inspect_app(make_app())
     app.sinks.clear()
     assert inspect.StringVisitor(verbose, internal).process(app) == self.make(
         sv, app, verbose, internal, s=False
     )
示例#5
0
    def test_middleware_verbose(self, internal):
        sv = inspect.StringVisitor(True, internal)
        m = inspect.inspect_middlewares(make_app())

        mt = sv.process(m.middleware_tree)
        sv.indent += 4
        mc = '\n'.join(sv.process(cls) for cls in m.middleware_classes)
        exp = '{}\n- Middlewares classes:\n{}'.format(mt, mc)
        assert inspect.StringVisitor(True).process(m) == exp
示例#6
0
 def test_app_no_middleware(self, verbose, internal):
     sv = inspect.StringVisitor(verbose, internal)
     app = inspect.inspect_app(make_app())
     app.middleware.middleware_classes.clear()
     app.middleware.middleware_tree.request.clear()
     app.middleware.middleware_tree.resource.clear()
     app.middleware.middleware_tree.response.clear()
     assert inspect.StringVisitor(verbose, internal).process(app) == self.make(
         sv, app, verbose, internal, m=False)
示例#7
0
    def test_route_method_verbose(self, internal):
        sv = inspect.StringVisitor(True, internal)
        rm = inspect.inspect_routes(make_app())[0].methods[0]

        assert sv.process(
            rm) == '{0.method} - {0.function_name} ({0.source_info})'.format(
                rm)
示例#8
0
def test_string_visitor_class():
    assert issubclass(inspect.StringVisitor, inspect.InspectVisitor)

    sv = inspect.StringVisitor()
    assert sv.verbose is False
    assert sv.internal is False
    assert sv.name == ''
示例#9
0
    def test_app_name(self, internal):
        sv = inspect.StringVisitor(False, internal, name='foo')
        app = inspect.inspect_app(make_app())

        s = sv.process(app).splitlines()[0]
        assert s == 'foo (WSGI)'
        assert app.to_string(name='bar').splitlines()[0] == 'bar (WSGI)'
示例#10
0
    def test_middleware_method_verbose(self, internal):
        sv = inspect.StringVisitor(True, internal)
        mm = inspect.inspect_middlewares(
            make_app()).middleware_classes[0].methods[0]

        assert sv.process(mm) == '{0.function_name} ({0.source_info})'.format(
            mm)
示例#11
0
 def test_static_route(self, verbose, internal):
     sv = inspect.StringVisitor(verbose, internal)
     sr = inspect.inspect_static_routes(make_app())
     no_file = sr[1]
     assert sv.process(no_file) == '↦ {0.prefix} {0.directory}'.format(no_file)
     with_file = sr[0]
     exp = '↦ {0.prefix} {0.directory} [{0.fallback_filename}]'.format(with_file)
     assert sv.process(with_file) == exp
示例#12
0
    def test_middleware_class_verbose(self, internal):
        sv = inspect.StringVisitor(True, internal)
        mc = inspect.inspect_middlewares(make_app()).middleware_classes[0]

        mml = ['   ├── {}'.format(sv.process(m)) for m in mc.methods][:-1]
        mml += ['   └── {}'.format(sv.process(m)) for m in mc.methods][-1:]

        exp = '↣ {0.name} ({0.source_info}):\n{1}'.format(mc, '\n'.join(mml))
        assert sv.process(mc) == exp
示例#13
0
 def test_middleware_tree_item(self, verbose, internal):
     sv = inspect.StringVisitor(verbose, internal)
     mt = inspect.inspect_middleware(make_app()).middleware_tree
     for r, s in (
         (mt.request[0], '→'),
         (mt.resource[0], '↣'),
         (mt.response[0], '↢'),
     ):
         assert sv.process(r) == '{0} {1.class_name}.{1.name}'.format(s, r)
示例#14
0
    def test_route(self, internal):
        sv = inspect.StringVisitor(False, internal)
        r = inspect.inspect_routes(make_app())[0]

        ml = ['   ├── {}'.format(sv.process(m))
              for m in r.methods if not m.internal or internal][:-1]
        ml += ['   └── {}'.format(sv.process(m))
               for m in r.methods if not m.internal or internal][-1:]

        exp = '⇒ {0.path} - {0.class_name}:\n{1}'.format(r, '\n'.join(ml))
        assert sv.process(r) == exp
示例#15
0
 def test_routes_only(self, verbose, internal, monkeypatch):
     args = ['some-file.py', '{}:{}'.format(_MODULE, '_APP'), '-r']
     if verbose:
         args.append('-v')
     if internal:
         args.append('-i')
     monkeypatch.setattr('sys.argv', args)
     output = io.StringIO()
     with redirected(stdout=output):
         inspect_app.main()
     routes = inspect.inspect_routes(_APP)
     sv = inspect.StringVisitor(verbose, internal)
     expect = '\n'.join([sv.process(r) for r in routes])
     self.check(output.getvalue().strip(), expect)
示例#16
0
    def test_middleware_tree_response_only(self, internal):
        sv = inspect.StringVisitor(False, internal)
        mt = inspect.inspect_middlewares(make_app()).middleware_tree
        mt.request.clear()
        mt.resource.clear()
        lines = []
        space = '  ' * len(mt.response)
        lines.append('')
        lines.append(space + '  ├── Process route responder')
        lines.append('')
        for r in mt.response:
            space = space[:-2]
            lines.append(space + sv.process(r))

        assert sv.process(mt) == '\n'.join(lines)
示例#17
0
    def test_middleware_tree_no_response(self, internal):
        sv = inspect.StringVisitor(False, internal)
        mt = inspect.inspect_middlewares(make_app()).middleware_tree
        mt.response.clear()
        lines = []
        space = ''
        for r in mt.request:
            lines.append(space + sv.process(r))
            space += '  '
        lines.append('')
        for r in mt.resource:
            lines.append(space + sv.process(r))
            space += '  '
        lines.append('')
        lines.append(space + '  ├── Process route responder')

        assert sv.process(mt) == '\n'.join(lines)
示例#18
0
    def test_middleware_tree(self, verbose, internal):
        sv = inspect.StringVisitor(verbose, internal)
        mt = inspect.inspect_middleware(make_app()).middleware_tree
        lines = []
        space = ''
        for r in mt.request:
            lines.append(space + sv.process(r))
            space += '  '
        lines.append('')
        for r in mt.resource:
            lines.append(space + sv.process(r))
            space += '  '
        lines.append('')
        lines.append(space + '  ├── Process route responder')
        lines.append('')
        for r in mt.response:
            space = space[:-2]
            lines.append(space + sv.process(r))

        assert sv.process(mt) == '\n'.join(lines)
示例#19
0
    def test_sink_verbose(self, internal):
        sv = inspect.StringVisitor(True, internal)
        s = inspect.inspect_sinks(make_app())[0]

        assert sv.process(
            s) == '⇥ {0.prefix} {0.name} ({0.source_info})'.format(s)
示例#20
0
    def test_route_method(self, internal):
        sv = inspect.StringVisitor(False, internal)
        rm = inspect.inspect_routes(make_app())[0].methods[0]

        assert sv.process(rm) == '{0.method} - {0.function_name}'.format(rm)
示例#21
0
 def test_route_no_methods(self, internal):
     sv = inspect.StringVisitor(False, internal)
     r = inspect.inspect_routes(make_app())[0]
     r.methods.clear()
     exp = '⇒ {0.path} - {0.class_name}'.format(r)
     assert sv.process(r) == exp
示例#22
0
    def test_middleware(self, internal):
        sv = inspect.StringVisitor(False, internal)
        m = inspect.inspect_middlewares(make_app())

        assert sv.process(m) == sv.process(m.middleware_tree)
示例#23
0
 def test_middleware_class_no_methods(self, internal):
     sv = inspect.StringVisitor(False, internal)
     mc = inspect.inspect_middlewares(make_app()).middleware_classes[0]
     mc.methods.clear()
     exp = '↣ {0.name}'.format(mc)
     assert sv.process(mc) == exp
示例#24
0
    def test_sink(self, internal):
        sv = inspect.StringVisitor(False, internal)
        s = inspect.inspect_sinks(make_app())[0]

        assert sv.process(s) == '⇥ {0.prefix} {0.name}'.format(s)
示例#25
0
    def test_error_handler(self, internal):
        sv = inspect.StringVisitor(False, internal)
        e = inspect.inspect_error_handlers(make_app())[0]

        assert sv.process(e) == '⇜ {0.error} {0.name}'.format(e)
示例#26
0
    def test_middleware_method(self, internal):
        sv = inspect.StringVisitor(False, internal)
        mm = inspect.inspect_middlewares(
            make_app()).middleware_classes[0].methods[0]

        assert sv.process(mm) == '{0.function_name}'.format(mm)
示例#27
0
    def test_error_handler_verbose(self, internal):
        sv = inspect.StringVisitor(True, internal)
        e = inspect.inspect_error_handlers(make_app())[0]

        assert sv.process(
            e) == '⇜ {0.error} {0.name} ({0.source_info})'.format(e)