def test_push(self): pipeline = Pipeline([add, add]) assert 10 == pipeline(4, 6) pipeline.push(mul) assert 30 == pipeline(6, 5) assert 20 == pipeline(15, 5)
def test_add(self): pipeline_1 = Pipeline([add, add]) pipeline_2 = Pipeline([mul, mul]) pipeline_a = Pipeline([add, add, mul, mul]) assert pipeline_1 + pipeline_2 == pipeline_a
def test_override404(self): def overriding404(environ, start_response): return "overriding404" pipe = Pipeline( [ExceptionHandler({Http404: overriding404}), raise_404]) assert "overriding404" == pipe(None, None)
def test_default404(self): pipe = Pipeline([ExceptionHandler(), raise_404]) expected = "<html><title>404 Not Found</title><body><h1>404 Not Found</h1></body></html>" start_response = StartResponse(expected_status="404 Not Found") assert expected == pipe(None, start_response).next()
def __call__(self, environ, start_response): environ['pythia'] = { 'jinja_env': EnvironmentWrapper(self.jinja_env), 'app_settings': self.settings, } pipeline = Pipeline(self.chain) return pipeline(environ, CustomStartResponse(start_response))
def test_call(self): def func(pipeline, environ, start_response): assert environ['pythia']['url_params']['user_id'] == '1234' return "func" view_paths = [ (r"^/user/(\d+)/$", func, ("user_id", )), ] dispatcher = URLDispatcher(view_paths) environ = {"PATH_INFO": "/user/1234"} assert "func" == dispatcher(Pipeline(), environ, None)
def test_overrideCustom(self): class CustomException(Exception): pass def throw_custom(pipe, environ, start_response): raise CustomException def custom_handler(environ, start_response): return "custom_handler" pipe = Pipeline([ ExceptionHandler({CustomException: custom_handler}), throw_custom ]) assert "custom_handler" == pipe(None, None)
def test_methods(self): a = Adder(5) pipeline = Pipeline([a.add, a.add, a.add, identity]) assert 15 == pipeline(0)
def test_arg_insert(self): pipeline = Pipeline([inc, inc, inc, identity]) assert 3 == pipeline(0)
def test_last_non_func(self): pipeline = Pipeline([add, 4]) assert 10 == pipeline(4, 6) with pytest.raises(StopIteration): pipeline()
def test_non_function(self): pipeline = Pipeline([add, 32, 12, add, mul]) assert 10 == pipeline(4, 6) assert 20 == pipeline(15, 5) assert 30 == pipeline(6, 5)
def test_inequal(self): pipeline_1 = Pipeline([add, add]) pipeline_2 = Pipeline([mul, mul]) assert pipeline_1 != pipeline_2
def test_simple(self): pipeline = Pipeline([add, add, mul]) assert 10 == pipeline(4, 6) assert 20 == pipeline(15, 5) assert 30 == pipeline(6, 5)