diff options
| author | ianb <devnull@localhost> | 2005-08-22 19:25:29 +0000 |
|---|---|---|
| committer | ianb <devnull@localhost> | 2005-08-22 19:25:29 +0000 |
| commit | 16c6ef405b64ac295ff3529e90c9b7fadaa0b9a1 (patch) | |
| tree | 1fc8df07dc33a7f223bd719283cda95f754c7644 /paste | |
| parent | 15bbe53452d6e2c6f846429fc9b369645455d87b (diff) | |
| download | paste-16c6ef405b64ac295ff3529e90c9b7fadaa0b9a1.tar.gz | |
More moving around of stuff
Diffstat (limited to 'paste')
| -rw-r--r-- | paste/exceptions/test_error_middleware.py | 72 | ||||
| -rw-r--r-- | paste/exceptions/tests/test_formatter.py | 170 | ||||
| -rw-r--r-- | paste/exceptions/tests/test_reporter.py | 46 | ||||
| -rw-r--r-- | paste/tests/conftest.py | 4 |
4 files changed, 4 insertions, 288 deletions
diff --git a/paste/exceptions/test_error_middleware.py b/paste/exceptions/test_error_middleware.py deleted file mode 100644 index 956aa26..0000000 --- a/paste/exceptions/test_error_middleware.py +++ /dev/null @@ -1,72 +0,0 @@ -from fixture import * -from paste.errormiddleware import ErrorMiddleware -from paste import lint - -def do_request(app, expect_status=500): - app = lint.middleware(app) - app = ErrorMiddleware(app, {}, debug=True) - testapp = TestApp(app) - res = TestApp.get('', status=expect_status) - return res - -############################################################ -## Applications that raise exceptions -############################################################ - -def bad_app(): - "No argument list!" - return None - -def start_response_app(environ, start_response): - "raise error before start_response" - raise ValueError("hi") - -def after_start_response_app(environ, start_response): - start_response("200 OK", [('Content-type', 'text/plain')]) - raise ValueError('error2') - -def iter_app(environ, start_response): - start_response("200 OK", [('Content-type', 'text/plain')]) - return yielder(['this', ' is ', ' a', None]) - -def yielder(args): - for arg in args: - if arg is None: - raise ValueError("None raises error") - yield arg - -############################################################ -## Tests -############################################################ - -def test_makes_exception(): - res = do_request(bad_app) - print res - assert '<html' in res - assert 'bad_app() takes no arguments (2 given' in res - assert 'iterator = application(environ, start_response_wrapper)' in res - assert 'lint.py' in res - assert 'errormiddleware.py' in res - -def test_start_res(): - res = do_request(start_response_app) - print res - assert 'ValueError: hi' in res - assert 'test_error_middleware.py' in res - assert 'line 17 in <tt>start_response_app</tt>' in res - -def test_after_start(): - res = do_request(after_start_response_app, 200) - print res - assert 'ValueError: error2' in res - assert 'line 21' in res - -def test_iter_app(): - res = do_request(iter_app, 200) - print res - assert 'None raises error' in res - assert 'yielder' in res - - - - diff --git a/paste/exceptions/tests/test_formatter.py b/paste/exceptions/tests/test_formatter.py deleted file mode 100644 index 53b0d10..0000000 --- a/paste/exceptions/tests/test_formatter.py +++ /dev/null @@ -1,170 +0,0 @@ -from paste.exceptions import formatter -from paste.exceptions import collector -import sys -import os -import difflib - -class Mock(object): - def __init__(self, **kw): - for name, value in kw.items(): - setattr(self, name, value) - -class Supplement(Mock): - - object = 'test_object' - source_url = 'http://whatever.com' - info = 'This is some supplemental information' - args = () - def getInfo(self): - return self.info - - def __call__(self, *args): - self.args = args - return self - -class BadSupplement(Supplement): - - def getInfo(self): - raise ValueError("This supplemental info is buggy") - -def call_error(sup): - 1 + 2 - __traceback_supplement__ = (sup, ()) - assert 0, "I am an error" - -def raise_error(sup='default'): - if sup == 'default': - sup = Supplement() - for i in range(10): - __traceback_info__ = i - if i == 5: - call_error(sup=sup) - -def hide(t, inner, *args, **kw): - __traceback_hide__ = t - return inner(*args, **kw) - -def pass_through(info, inner, *args, **kw): - """ - To add another frame to the call; detectable because - __tracback_info__ is set to `info` - """ - __traceback_info__ = info - return inner(*args, **kw) - -def format(type='html', **ops): - data = collector.collect_exception(*sys.exc_info()) - report = getattr(formatter, 'format_' + type)(data, **ops) - return report - -formats = ('text', 'html') - -def test_excersize(): - for f in formats: - try: - raise_error() - except: - format(f) - -def test_content(): - for f in formats: - try: - raise_error() - except: - result = format(f) - print result - assert 'test_object' in result - assert 'http://whatever.com' in result - assert 'This is some supplemental information' in result - assert 'raise_error' in result - assert 'call_error' in result - assert '5' in result - assert 'test_content' in result - else: - assert 0 - -def test_trim(): - current = os.path.abspath(os.getcwd()) - for f in formats: - try: - raise_error() - except: - result = format(f, trim_source_paths=[(current, '.')]) - assert current not in result - assert '/test_formatter.py' in result - else: - assert 0 - -def test_hide(): - for f in formats: - try: - hide(True, raise_error) - except: - result = format(f) - print result - assert 'in hide_inner' not in result - assert 'inner(*args, **kw)' not in result - else: - assert 0 - -def print_diff(s1, s2): - differ = difflib.Differ() - result = list(differ.compare(s1.splitlines(), s2.splitlines())) - print '\n'.join(result) - -def test_hide_supppressed(): - """ - When an error occurs and __traceback_stop__ is true for the - erroneous frame, then that setting should be ignored. - """ - for f in formats: - results = [] - for hide_value in (False, 'after'): - try: - pass_through( - 'a', - hide, - hide_value, - pass_through, - 'b', - raise_error) - except: - results.append(format(f)) - else: - assert 0 - if results[0] != results[1]: - print_diff(results[0], results[1]) - assert 0 - -def test_hide_after(): - for f in formats: - try: - pass_through( - 'AABB', - hide, 'after', - pass_through, 'CCDD', - hide, 'reset', - raise_error) - except: - result = format(f) - print result - assert 'AABB' in result - assert 'CCDD' not in result - assert 'raise_error' in result - else: - assert 0 - -def test_hide_before(): - for f in formats: - try: - pass_through( - 'AABB', - hide, 'before', - raise_error) - except: - result = format(f) - print result - assert 'AABB' not in result - assert 'raise_error' in result - else: - assert 0 diff --git a/paste/exceptions/tests/test_reporter.py b/paste/exceptions/tests/test_reporter.py deleted file mode 100644 index da6c470..0000000 --- a/paste/exceptions/tests/test_reporter.py +++ /dev/null @@ -1,46 +0,0 @@ -import sys -import os -from paste.exceptions.reporter import * -from paste.exceptions import collector - -def setup_file(fn, content=None): - fn = os.path.join(os.path.dirname(__file__), 'reporter_output', fn) - if os.path.exists(fn): - os.unlink(fn) - if content is not None: - f = open(fn, 'wb') - f.write(content) - f.close() - return fn - -def test_logger(): - fn = setup_file('test_logger.log') - rep = LogReporter( - filename=fn, - show_hidden_frames=False) - try: - int('a') - except: - exc_data = collector.collect_exception(*sys.exc_info()) - else: - assert 0 - rep.report(exc_data) - content = open(fn).read() - assert len(content.splitlines()) == 4 - assert 'ValueError' in content - assert 'int(): a' in content - assert 'test_reporter.py' in content - assert 'test_logger' in content - - try: - 1 / 0 - except: - exc_data = collector.collect_exception(*sys.exc_info()) - else: - assert 0 - rep.report(exc_data) - content = open(fn).read() - print content - assert len(content.splitlines()) == 8 - assert 'ZeroDivisionError' in content - diff --git a/paste/tests/conftest.py b/paste/tests/conftest.py new file mode 100644 index 0000000..93bca7d --- /dev/null +++ b/paste/tests/conftest.py @@ -0,0 +1,4 @@ +import sys +import os + +sys.insert(0, os.path.dirname(os.path.dirname(__file__))) |
