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 )
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)
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 )
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 )
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
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)
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)
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 == ''
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)'
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)
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
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
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)
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
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)
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)
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)
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)
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)
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)
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
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)
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
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)
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)
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)
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)