Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Refactor aspen.tests into aspen.testing and tests/

Aspen should bundle helpers for testing Simplates. This commit is a step in
that direction. Now aspen.testing contains helpers and fixture and such, and
the new tests/ directory in the root contains Aspen's own test suite, which
uses the aspen.testing module. It turns out that the existing helpers aren't
that helpful for testing actual websites, so I'm not adding any documentation
as part of this commit.
  • Loading branch information...
commit 3b6936d06046f343b4e23532afb08fbd533ab1a5 1 parent bdea7b2
Chad Whitacre authored
Showing with 287 additions and 168 deletions.
  1. +1 −1  Makefile
  2. +90 −0 aspen/resources/negotiated_resource.py
  3. +46 −40 aspen/{tests → testing}/__init__.py
  4. +41 −13 aspen/{tests → testing}/fsfix.py
  5. +33 −0 aspen/testing/sockets.py
  6. +0 −4 aspen/tests/go-tdd
  7. 0  {aspen → }/tests/all-utf8.py
  8. 0  {aspen → }/tests/assert_test.py
  9. 0  {aspen → }/tests/except_test.py
  10. +4 −0 tests/go-tdd
  11. +2 −2 {aspen → }/tests/test_colonize.py
  12. +9 −9 {aspen → }/tests/test_configuration.py
  13. +22 −22 {aspen → }/tests/test_gauntlet.py
  14. +11 −10 {aspen → }/tests/test_hooks.py
  15. +6 −2 {aspen → }/tests/test_json_resources.py
  16. 0  {aspen → }/tests/test_mappings.py
  17. +2 −2 {aspen → }/tests/test_request.py
  18. +2 −18 {aspen → }/tests/test_resources.py
  19. +2 −2 {aspen → }/tests/test_response.py
  20. +1 −1  {aspen → }/tests/test_restarter.py
  21. +2 −2 {aspen → }/tests/test_sockets_.py
  22. +2 −2 {aspen → }/tests/test_sockets_buffer.py
  23. +3 −3 {aspen → }/tests/test_sockets_channel.py
  24. +1 −1  {aspen → }/tests/test_sockets_message.py
  25. +1 −1  {aspen → }/tests/test_sockets_packet.py
  26. +2 −29 {aspen → }/tests/test_sockets_socket.py
  27. +2 −2 {aspen → }/tests/test_sockets_transport.py
  28. +2 −2 {aspen → }/tests/test_website.py
2  Makefile
View
@@ -21,4 +21,4 @@ run: env
./env/bin/thrash ./env/bin/aspen -vDEBUG -a:5370 -rdoc/
test:
- ./env/bin/nosetests -sx aspen/tests/
+ ./env/bin/nosetests -sx tests/
90 aspen/resources/negotiated_resource.py
View
@@ -0,0 +1,90 @@
+"""Template resources.
+
+Problems with tornado.template:
+
+ - no option to fail silently
+ - Loader cache doesn't account for modtime
+ - Is this a bug?
+
+ {{ foo }}
+ {% for foo in [1,2,3] %}
+ {% end %}
+
+ - no loop counters, eh? must do it manually with {% set %}
+ - can't do this:
+
+ {% if ... %}
+ {% extends %}
+ {% else %}
+ {% extends %}
+ {% end %}
+
+"""
+import copy
+
+from aspen import Response
+from aspen.resources.dynamic_resource import DynamicResource
+from aspen._tornado.template import Template
+
+
+class TemplateResource(DynamicResource):
+ """This is a template resource. It has two or three pages.
+ """
+
+ min_pages = 2
+ max_pages = 4
+
+ def compile_third(self, one, two, three, padding):
+ """Given three bytestrings, return a Template instance.
+
+ This method depends on fs and website attributes on self.
+
+ We used to take advantage of padding, but:
+
+ a) Tornado templates have some weird error handling that we haven't
+ exposed yet.
+
+ b) It's counter-intuitive if your template resources show up in the
+ browser with tons of whitespace at the beginning of them.
+
+ """
+ return Template( self._trim_initial_newline(three)
+ , name = self.fs
+ , loader = self.website.template_loader
+ , compress_whitespace = False
+ )
+
+ def compile_fourth(self, one, two, three, four, padding):
+ """Given None, return None. Template resources have a noop fourth page.
+ """
+ four = four.replace('\r\n', '\n')
+ four = padding + four
+ four = compile(four, self.fs, 'exec')
+ return four
+
+ def _trim_initial_newline(self, template):
+ """Trim any initial newline from page three.
+
+ This is a convenience. It's nice to put ^L on a line by itself, but
+ really you want the template to start on the next line.
+
+ """
+ try:
+ if template[0] == '\r': # Windows
+ if template[1] == '\n':
+ template = template[2:]
+ elif template[0] == '\n': # Unix
+ template = template[1:]
+ except IndexError: # empty template
+ pass
+ return template
+
+
+ def get_response(self, namespace):
+ """Given a namespace dict, return a response object.
+ """
+ response = namespace['response']
+ response.body = self.three.generate(**namespace)
+ if response.headers.one('Content-Type') is None:
+ response.headers.set('Content-Type', self.mimetype)
+ return response
86 aspen/tests/__init__.py → aspen/testing/__init__.py
View
@@ -20,18 +20,16 @@ def _log(*a):
print
+from aspen import Response
from aspen.configuration import Configurable
from aspen.http.request import Request
+from aspen.resources import load
from aspen.website import Website
from aspen._tornado.template import Loader
+from aspen.testing.fsfix import fix, attach_teardown, FSFIX, mk, teardown
-def print_stack():
- """Print the current stack trace.
- """
- previous_frame = inspect.stack()[1][0] # strip off ourselves
- for line in traceback.format_stack(previous_frame):
- sys.stdout.write(line)
+__all__ = ['assert_raises', 'attach_teardown', 'fix', 'teardown']
class Stub:
@@ -58,13 +56,13 @@ def __call__(cls, path='/'):
@classmethod
def from_fs(cls, fs):
- """Takes a path under ./fsfix using / as the path separator.
+ """Takes a path under FSFIX using / as the path separator.
"""
fs = os.sep.join(fs.split(os.sep))
request = Request.from_wsgi(StubWSGIRequest(fs))
- website = Configurable.from_argv(['--root', 'fsfix'])
+ website = Configurable.from_argv(['--root', FSFIX])
website.copy_configuration_to(request)
- request.root = join(dirname(__file__), 'fsfix')
+ request.root = join(dirname(__file__), FSFIX)
request.fs = fs
request.namespace = {}
request.website = website
@@ -74,45 +72,53 @@ def from_fs(cls, fs):
StubRequest = StubRequest()
-def handle(path='/'):
- website = Website(['--root', 'fsfix'])
- request = StubRequest(path)
- request.website = website
- response = website.handle(request)
- return response
-
+class Handle(object):
+ """Stub out website.handle with set configuration.
+ """
-# Asserters
-# =========
-# The first two are useful if you want a test generator.
+ def __init__(self, argv):
+ """Takes an argv list.
+ """
+ self.argv = argv
-def assert_(expr):
- assert expr
+ def __call__(self, path='/'):
+ """Given an URL path, return
-def assert_actual(expected, actual):
- assert actual == expected, actual
+ This only allows you to simulate GET requests with no querystring, so
+ it's limited. But it's a something. Kind of. Almost.
-def assert_logs(*lines, **kw):
- if lines[0] is None:
- expected = ''
+ """
+ website = Website(self.argv)
+ request = StubRequest(path)
+ request.website = website
+ response = website.handle(request)
+ return response
+
+handle = Handle(['--root', FSFIX])
+
+
+def Resource(fs):
+ return load(StubRequest.from_fs(fs), 0)
+
+def check(content, filename="index.html", body=True, aspenconf="",
+ response=None):
+ mk(('.aspen/aspen.conf', aspenconf), (filename, content))
+ request = StubRequest.from_fs(filename)
+ response = response or Response()
+ resource = load(request, 0)
+ response = resource.respond(request, response)
+ if body:
+ return response.body
else:
- # when logged output is printed, system-specific newlines are used
- # when logged output is written to a file, universal newline support
- # kicks in, and we have to work around it here
- force_unix_EOL = kw.get('force_unix_EOL', False)
- linesep = force_unix_EOL and '\n' or os.linesep
- expected = linesep.join(lines) + linesep
- actual = kw.get('actual', open(LOG, 'r').read())
- assert actual == expected, actual.splitlines()
-
-def assert_prints(*args):
- args = list(args)
- expected = args[:-1]
- actual = args[-1]
- assert_logs(*expected, **{'actual':actual}) # a little goofy, yes
+ return response
def assert_raises(Exc, call, *arg, **kw):
"""Given an Exception, a callable, and its params, return an exception.
+
+ If the callable does not raise an exception then AssertionError will be
+ raised with a message indicating as much. Likewise if the callable raises a
+ different exception than what was expected.
+
"""
exc = None
try:
54 aspen/tests/fsfix.py → aspen/testing/fsfix.py
View
@@ -2,11 +2,21 @@
import os
import re
import sys
+import tempfile
+import traceback
from os.path import dirname, isdir, isfile, join, realpath
import aspen
from aspen import resources, sockets
-from nose.tools import with_setup
+try:
+ from nose.tools import with_setup
+except ImportError:
+ with_setup = None
+ nose_tb = traceback.format_exc()
+
+
+CWD = os.getcwd()
+FSFIX = os.path.realpath(os.path.join(tempfile.gettempdir(), 'fsfix'))
def convert_path(path):
@@ -20,7 +30,7 @@ def convert_paths(paths):
return tuple([convert_path(p) for p in paths])
def mk(*treedef, **kw):
- """Given a treedef, build a filesystem fixture in ./fsfix.
+ """Given a treedef, build a filesystem fixture in FSFIX.
treedef is a sequence of strings and tuples. If a string, it is interpreted
as a path to a directory that should be created. If a tuple, the first
@@ -28,11 +38,11 @@ def mk(*treedef, **kw):
it this way to ease cross-platform testing.
The one meaningful keyword argument is configure. If True, mk will call
- aspen.configure with ./fsfix as the root.
+ aspen.configure with FSFIX as the root.
"""
configure = kw.get('configure', False)
- root = realpath('fsfix')
+ root = FSFIX
os.mkdir(root)
for item in treedef:
if isinstance(item, basestring):
@@ -50,20 +60,20 @@ def mk(*treedef, **kw):
if configure is True:
aspen.configure(['--root', root])
-def expect(path=''):
- """Given a relative path, return an absolute path.
+def fix(path=''):
+ """Given a relative path, return an absolute path under FSFIX.
The incoming path is in UNIX form (/foo/bar.html). The outgoing path is in
native form, with symlinks removed.
"""
- path = os.sep.join([dirname(__file__), 'fsfix'] + path.split('/'))
+ path = os.sep.join([FSFIX] + path.split('/'))
return realpath(path)
def rm():
- """Remove the filesystem fixture at fsfix/.
+ """Remove the filesystem fixture at FSFIX.
"""
- root = realpath('fsfix')
+ root = FSFIX
if isdir(root):
for root, dirs, files in os.walk(root, topdown=False):
for name in dirs:
@@ -74,8 +84,16 @@ def rm():
def teardown():
"""Standard teardown function.
+
+ - reset the current working directory
+ - remove FSFIX = %{tempdir}/fsfix
+ - reset Aspen's global state
+ - remove '.aspen' from sys.path
+ - remove 'foo' from sys.modules
+ - remove logging handlers
+
"""
- os.chdir(dirname(__file__))
+ os.chdir(CWD)
rm()
# Reset some process-global caches. Hrm ...
resources.__cache__ = {}
@@ -89,11 +107,21 @@ def teardown():
teardown() # start clean
-def attach_teardown(context, prefix='test_'):
- """Given a namespace and a routine prefix, attach the teardown function.
+def attach_teardown(context):
+ """Given a namespace dictionary, attach the teardown function.
+
+ This function is designed for nose and will raise NotImplementedError at
+ runtime with an additional ImportError traceback if nose is not available.
+ To use it put this line at the end of your test modules:
+
+ attach_teardown(globals())
+
"""
+ if with_setup is None:
+ raise NotImplementedError("This function is designed for nose, which "
+ "couldn't be imported:" + os.sep + nose_tb)
for name, func in context.items():
- if name.startswith(prefix):
+ if name.startswith('test_'):
func = with_setup(teardown=teardown)(func) # non-destructive
def torndown(func):
33 aspen/testing/sockets.py
View
@@ -0,0 +1,33 @@
+import os
+
+from aspen.engines import ThreadedBuffer
+from aspen.http.request import Request
+from aspen.sockets.channel import Channel
+from aspen.sockets.socket import Socket
+from aspen.website import Website
+from aspen.testing import fix
+
+
+def make_request(filename='echo.sock'):
+ request = Request(url='/echo.sock')
+ request.website = Website([])
+ request.website.copy_configuration_to(request)
+ request.fs = fix(filename)
+ return request
+
+def make_socket(filename='echo.sock', channel=None):
+ request = make_request(filename='echo.sock')
+ if channel is None:
+ channel = Channel(request.path.raw, ThreadedBuffer)
+ socket = Socket(request, channel)
+ return socket
+
+class SocketInThread(object):
+
+ def __enter__(self, filename='echo.sock'):
+ self.socket = make_socket(filename)
+ self.socket.loop.start()
+ return self.socket
+
+ def __exit__(self, *a):
+ self.socket.loop.stop()
4 aspen/tests/go-tdd
View
@@ -1,4 +0,0 @@
-#!/bin/sh
-watch --color --interval 0.5 \
- '../../env/bin/nosetests --stop --with-snot '$@' 4>&1 | tail -n $(($LINES-2))'
-
0  aspen/tests/all-utf8.py → tests/all-utf8.py
View
File renamed without changes
0  aspen/tests/assert_test.py → tests/assert_test.py
View
File renamed without changes
0  aspen/tests/except_test.py → tests/except_test.py
View
File renamed without changes
4 tests/go-tdd
View
@@ -0,0 +1,4 @@
+#!/bin/sh
+watch --color --interval 0.5 \
+ '../env/bin/nosetests --stop --with-snot '$@' 4>&1 | tail -n $(($LINES-2))'
+
4 aspen/tests/test_colonize.py → tests/test_colonize.py
View
@@ -1,6 +1,6 @@
from aspen.configuration.colon import *
-from aspen.tests import assert_raises as _assert_raises
-from aspen.tests.fsfix import attach_teardown
+from aspen.testing import assert_raises as _assert_raises
+from aspen.testing.fsfix import attach_teardown
def assert_raises(name, Err):
18 aspen/tests/test_configuration.py → tests/test_configuration.py
View
@@ -4,8 +4,8 @@
from aspen.configuration import Configurable, ConfigurationError
from aspen.configuration.options import validate_address, callback_root
-from aspen.tests import assert_raises
-from aspen.tests.fsfix import attach_teardown, expect, mk
+from aspen.testing import assert_raises
+from aspen.testing.fsfix import attach_teardown, fix, FSFIX, mk
def test_nirvana():
@@ -17,7 +17,7 @@ def test_nirvana():
assert actual == expected, actual
def test_callback_root_fails_when_directory_doesnt_exist():
- assert_raises(ConfigurationError, callback_root, None, None, 'fsfix', None)
+ assert_raises(ConfigurationError, callback_root, None, None, FSFIX, None)
def test_root_defaults_to_cwd():
mk()
@@ -29,7 +29,7 @@ def test_root_defaults_to_cwd():
def test_ConfigurationError_raised_if_no_cwd():
mk()
- os.chdir('fsfix')
+ os.chdir(FSFIX)
os.rmdir(os.getcwd())
c = Configurable()
assert_raises(ConfigurationError, c.configure, [])
@@ -37,7 +37,7 @@ def test_ConfigurationError_raised_if_no_cwd():
def test_ConfigurationError_NOT_raised_if_no_cwd_but_do_have___root():
mk()
foo = os.getcwd()
- os.chdir('fsfix')
+ os.chdir(FSFIX)
os.rmdir(os.getcwd())
c = Configurable()
c.configure(['--root', foo])
@@ -48,21 +48,21 @@ def test_ConfigurationError_NOT_raised_if_no_cwd_but_do_have___root():
def test_configurable_sees_root_option():
mk()
c = Configurable()
- c.configure(['--root', 'fsfix'])
+ c.configure(['--root', FSFIX])
expected = os.getcwd()
actual = c.root
assert actual == expected, actual
def test_callback_root_finds_root():
mk()
- expected = expect()
+ expected = fix()
class Values():
pass
class Parser:
values = Values()
parser = Parser()
- callback_root(None, None, 'fsfix', parser)
- expected = os.path.realpath("fsfix")
+ callback_root(None, None, FSFIX, parser)
+ expected = os.path.realpath(FSFIX)
actual = parser.values.root
assert actual == expected, actual
44 aspen/tests/test_gauntlet.py → tests/test_gauntlet.py
View
@@ -3,8 +3,8 @@
from aspen import gauntlet, Response
from aspen.http.request import Request
-from aspen.tests import assert_raises, handle, NoException, StubRequest
-from aspen.tests.fsfix import attach_teardown, expect, mk
+from aspen.testing import assert_raises, handle, NoException, StubRequest
+from aspen.testing import attach_teardown, fix, FSFIX, mk
from aspen.configuration import Configurable
@@ -20,13 +20,13 @@ def check_index(path):
def test_index_is_found():
mk(('index.html', "Greetings, program!"))
- expected = expect('index.html')
+ expected = fix('index.html')
actual = check_index('/').fs
assert actual == expected, actual
def test_alternate_index_is_not_found():
mk(('default.html', "Greetings, program!"))
- expected = expect('')
+ expected = fix('')
actual = check_index('/').fs
assert actual == expected, actual
@@ -34,7 +34,7 @@ def test_alternate_index_is_found():
mk( ('.aspen/aspen.conf', '[aspen]\ndefault_filenames = default.html')
, ('default.html', "Greetings, program!")
)
- expected = expect('default.html')
+ expected = fix('default.html')
actual = check_index('/').fs
assert actual == expected, actual
@@ -42,7 +42,7 @@ def test_index_conf_setting_overrides_and_doesnt_extend():
mk( ('.aspen/aspen.conf', '[aspen]\ndefault_filenames = default.html')
, ('index.html', "Greetings, program!")
)
- expected = expect('')
+ expected = fix('')
actual = check_index('/').fs
assert actual == expected, actual
@@ -52,7 +52,7 @@ def test_index_conf_setting_takes_first():
, ('index.html', "Greetings, program!")
, ('default.html', "Greetings, program!")
)
- expected = expect('index.html')
+ expected = fix('index.html')
actual = check_index('/').fs
assert actual == expected, actual
@@ -61,7 +61,7 @@ def test_index_conf_setting_takes_second_if_first_is_missing():
, '[aspen]\ndefault_filenames = index.html default.html')
, ('default.html', "Greetings, program!")
)
- expected = expect('default.html')
+ expected = fix('default.html')
actual = check_index('/').fs
assert actual == expected, actual
@@ -70,7 +70,7 @@ def test_index_conf_setting_strips_commas():
, '[aspen]\ndefault_filenames: index.html, default.html')
, ('default.html', "Greetings, program!")
)
- expected = expect('default.html')
+ expected = fix('default.html')
actual = check_index('/').fs
assert actual == expected, actual
@@ -79,7 +79,7 @@ def test_index_conf_setting_strips_many_commas():
, '[aspen]\ndefault_filenames: index.html,,,,,,, default.html')
, ('default.html', "Greetings, program!")
)
- expected = expect('default.html')
+ expected = fix('default.html')
actual = check_index('/').fs
assert actual == expected, actual
@@ -88,7 +88,7 @@ def test_index_conf_setting_ignores_blanks():
, '[aspen]\ndefault_filenames: index.html,, ,, ,,, default.html')
, ('default.html', "Greetings, program!")
)
- expected = expect('default.html')
+ expected = fix('default.html')
actual = check_index('/').fs
assert actual == expected, actual
@@ -97,7 +97,7 @@ def test_index_conf_setting_works_with_only_comma():
, '[aspen]\ndefault_filenames: index.html,default.html')
, ('default.html', "Greetings, program!")
)
- expected = expect('default.html')
+ expected = fix('default.html')
actual = check_index('/').fs
assert actual == expected, actual
@@ -114,20 +114,20 @@ def check_virtual_paths(path):
def test_virtual_path_can_passthrough():
mk(('foo.html', "Greetings, program!"))
- expected = expect('foo.html')
+ expected = fix('foo.html')
actual = check_virtual_paths('foo.html').fs
assert actual == expected, actual
def test_unfound_virtual_path_passes_through():
mk(('%bar/foo.html', "Greetings, program!"))
request = check_virtual_paths('/blah/flah.html')
- expected = expect('/blah/flah.html')
+ expected = fix('/blah/flah.html')
actual = request.fs
assert actual == expected, actual
def test_virtual_path_is_virtual():
mk(('%bar/foo.html', "Greetings, program!"))
- expected = expect('%bar/foo.html')
+ expected = fix('%bar/foo.html')
actual = check_virtual_paths('/blah/foo.html').fs
assert actual == expected, actual
@@ -169,31 +169,31 @@ def test_virtual_path_matches_the_first():
mk( ('%first/foo.html', "Greetings, program!")
, ('%second/foo.html', "WWAAAAAAAAAAAA!!!!!!!!")
)
- expected = expect('%first/foo.html')
+ expected = fix('%first/foo.html')
actual = check_virtual_paths('/1999/foo.html').fs
assert actual == expected, actual
def test_virtual_path_directory():
mk(('%first/index.html', "Greetings, program!"))
- expected = expect('%first')
+ expected = fix('%first')
actual = check_virtual_paths('/foo/').fs
assert actual == expected, actual
def test_virtual_path_file():
mk(('foo/%bar.html', "Greetings, program!"))
- expected = expect('foo/%bar.html')
+ expected = fix('foo/%bar.html')
actual = check_virtual_paths('/foo/blah.html').fs
assert actual == expected, actual
def test_virtual_path_file_only_last_part():
mk(('foo/%bar.html', "Greetings, program!"))
- expected = expect('foo/blah.html/baz')
+ expected = fix('foo/blah.html/baz')
actual = check_virtual_paths('/foo/blah.html/baz').fs
assert actual == expected, actual
def test_virtual_path_file_only_last_part____no_really():
mk(('foo/%bar.html', "Greetings, program!"))
- expected = expect('foo/blah.html/')
+ expected = fix('foo/blah.html/')
actual = check_virtual_paths('/foo/blah.html/').fs
assert actual == expected, actual
@@ -228,13 +228,13 @@ def check_trailing_slash(path):
def test_trailing_slash_passes_files_through():
mk(('foo/index.html', "Greetings, program!"))
- expected = expect('/foo/537.html')
+ expected = fix('/foo/537.html')
actual = check_trailing_slash('/foo/537.html').fs
assert actual == expected, actual
def test_trailing_slash_passes_dirs_with_slash_through():
mk('foo')
- expected = expect('/foo/')
+ expected = fix('/foo/')
actual = check_trailing_slash('/foo/').fs
assert actual == expected, actual
21 aspen/tests/test_hooks.py → tests/test_hooks.py
View
@@ -1,8 +1,7 @@
import os
import sys
-from aspen.tests import assert_raises
-from aspen.tests.fsfix import mk, attach_teardown
+from aspen.testing import assert_raises, attach_teardown, fix, FSFIX, mk
from aspen.configuration.exceptions import *
from aspen.configuration.hooks import HooksConf
@@ -14,13 +13,15 @@
import string
lib_python = os.path.join('.aspen', 'lib', 'python%s' % sys.version[:3])
-sys.path.insert(0, os.path.join('fsfix', lib_python))
+sys.path.insert(0, os.path.join(FSFIX, lib_python))
class Paths:
pass
def load(*also):
- return HooksConf(chr(12), 'fsfix/.aspen/hooks.conf', *also)
+ also = ['.aspen/hooks.conf'] + list(also)
+ also = [fix(p) for p in also]
+ return HooksConf(chr(12), *also)
# No hooks configured
@@ -56,8 +57,8 @@ def test_something():
def test_must_be_callable():
mk('.aspen', ('.aspen/hooks.conf', 'string:digits'))
err = assert_raises(ConfFileError, load)
- assert err.msg == ("'string:digits' is not callable. [fsfix/.aspen"
- "/hooks.conf, line 1]"), err.msg
+ assert err.msg.startswith("'string:digits' is not callable. ["), err.msg
+ assert err.msg.endswith("fsfix/.aspen/hooks.conf, line 1]"), err.msg
def test_order():
mk('.aspen', ('.aspen/hooks.conf', 'random:choice\nrandom:seed'))
@@ -169,7 +170,7 @@ def test_layering():
, []
, []
]
- actual = load('fsfix/first.conf', 'fsfix/second.conf')
+ actual = load('first.conf', 'second.conf')
assert actual == expected, actual
@@ -198,7 +199,7 @@ def test_form_feeds_on_same_line():
, [random.gauss]
, [random.shuffle]
]
- actual = load('fsfix/foo.conf')
+ actual = load('foo.conf')
assert actual == expected, actual
@@ -226,7 +227,7 @@ def test_all_six():
, []
, []
]
- actual = load('fsfix/foo.conf')
+ actual = load('foo.conf')
assert actual == expected, actual
@@ -247,7 +248,7 @@ def test_equal_sections_dont_screw_up_parsing():
random:shuffle
"""))
expected = [[],[],[],[],[random.shuffle],[]]
- actual = load('fsfix/hooks.conf')
+ actual = load('hooks.conf')
assert actual == expected, actual
8 aspen/tests/test_json_resources.py → tests/test_json_resources.py
View
@@ -1,6 +1,6 @@
from aspen.exceptions import LoadError
-from aspen.tests import assert_raises
-from aspen.tests.test_resources import check
+from aspen.testing import assert_raises, check
+from aspen.testing.fsfix import attach_teardown
def test_json_basically_works():
@@ -106,3 +106,7 @@ def test_json_raises_TypeError_on_unknown_types():
)
+# Teardown
+# ========
+
+attach_teardown(globals())
0  aspen/tests/test_mappings.py → tests/test_mappings.py
View
File renamed without changes
4 aspen/tests/test_request.py → tests/test_request.py
View
@@ -2,8 +2,8 @@
from aspen.http.mapping import Mapping
from aspen.http.request import Request
from aspen.http.headers import Headers
-from aspen.tests import assert_raises, StubRequest
-from aspen.tests.fsfix import attach_teardown
+from aspen.testing import assert_raises, StubRequest
+from aspen.testing.fsfix import attach_teardown
def test_blank_by_default():
20 aspen/tests/test_resources.py → tests/test_resources.py
View
@@ -4,27 +4,11 @@
from aspen import Response
from aspen.configuration import Configurable
from aspen.exceptions import LoadError
-from aspen.resources import load
-from aspen.resources.template_resource import TemplateResource
-from aspen.tests import assert_raises, StubRequest
-from aspen.tests.fsfix import attach_teardown, mk
+from aspen.testing import assert_raises, check
+from aspen.testing.fsfix import attach_teardown
from aspen._tornado.template import Template, Loader
-def Resource(fs):
- return load(StubRequest.from_fs(fs), 0)
-
-def check(content, filename="index.html", body=True, aspenconf="", response=None):
- mk(('.aspen/aspen.conf', aspenconf), (filename, content))
- request = StubRequest.from_fs(filename)
- response = response or Response()
- resource = load(request, 0)
- response = resource.respond(request, response)
- if body:
- return response.body
- else:
- return response
-
# Tests
# =====
4 aspen/tests/test_response.py → tests/test_response.py
View
@@ -1,6 +1,6 @@
from aspen import Response
-from aspen.tests import assert_raises
-from aspen.tests.fsfix import attach_teardown
+from aspen.testing import assert_raises
+from aspen.testing.fsfix import attach_teardown
def test_response_is_a_wsgi_callable():
2  aspen/tests/test_restarter.py → tests/test_restarter.py
View
@@ -1,5 +1,5 @@
from aspen import restarter
-from aspen.tests.fsfix import attach_teardown
+from aspen.testing.fsfix import attach_teardown
class Foo:
pass
4 aspen/tests/test_sockets_.py → tests/test_sockets_.py
View
@@ -1,7 +1,7 @@
from aspen import sockets
from aspen.http.request import Request
-from aspen.tests.fsfix import mk, attach_teardown
-from aspen.tests.test_sockets_socket import make_request
+from aspen.testing import mk, attach_teardown
+from aspen.testing.sockets import make_request
def test_sockets_get_nonsock_returns_None():
4 aspen/tests/test_sockets_buffer.py → tests/test_sockets_buffer.py
View
@@ -1,8 +1,8 @@
from aspen.sockets import FFFD
from aspen.sockets.buffer import ThreadedBuffer as Buffer
from aspen.sockets.message import Message
-from aspen.tests.test_sockets_socket import make_socket
-from aspen.tests.fsfix import mk, attach_teardown
+from aspen.testing.sockets import make_socket
+from aspen.testing.fsfix import mk, attach_teardown
def test_buffer_is_instantiable():
6 aspen/tests/test_sockets_channel.py → tests/test_sockets_channel.py
View
@@ -3,9 +3,9 @@
from aspen.sockets.buffer import ThreadedBuffer
from aspen.sockets.channel import Channel
from aspen.sockets.message import Message
-from aspen.tests.test_sockets_socket import make_socket
-from aspen.tests import assert_raises
-from aspen.tests.fsfix import mk, attach_teardown
+from aspen.testing.sockets import make_socket
+from aspen.testing import assert_raises
+from aspen.testing.fsfix import mk, attach_teardown
def test_channel_is_instantiable():
2  aspen/tests/test_sockets_message.py → tests/test_sockets_message.py
View
@@ -1,4 +1,4 @@
-from aspen.tests import assert_raises
+from aspen.testing import assert_raises
from aspen.sockets.message import Message
2  aspen/tests/test_sockets_packet.py → tests/test_sockets_packet.py
View
@@ -1,7 +1,7 @@
from aspen.sockets import FFFD
from aspen.sockets.packet import Packet
from aspen.sockets.message import Message
-from aspen.tests import assert_raises
+from aspen.testing import assert_raises
def test_packet_Packetable_with_unframed_bytes():
31 aspen/tests/test_sockets_socket.py → tests/test_sockets_socket.py
View
@@ -2,39 +2,12 @@
import os
import time
-from aspen.engines import ThreadedBuffer, ThreadedLoop
from aspen.http.request import Request
from aspen.sockets import FFFD
-from aspen.sockets.channel import Channel
from aspen.sockets.socket import Socket
from aspen.sockets.message import Message
-from aspen.tests.fsfix import mk, attach_teardown
-from aspen.website import Website
-
-
-def make_request(filename='echo.sock'):
- request = Request(url='/echo.sock')
- request.website = Website([])
- request.website.copy_configuration_to(request)
- request.fs = os.sep.join([os.path.dirname(__file__), 'fsfix', filename])
- return request
-
-def make_socket(filename='echo.sock', channel=None):
- request = make_request(filename='echo.sock')
- if channel is None:
- channel = Channel(request.path.raw, ThreadedBuffer)
- socket = Socket(request, channel)
- return socket
-
-class SocketInThread(object):
-
- def __enter__(self, filename='echo.sock'):
- self.socket = make_socket(filename)
- self.socket.loop.start()
- return self.socket
-
- def __exit__(self, *a):
- self.socket.loop.stop()
+from aspen.testing.fsfix import mk, attach_teardown
+from aspen.testing.sockets import make_socket, SocketInThread
def test_socket_is_instantiable():
4 aspen/tests/test_sockets_transport.py → tests/test_sockets_transport.py
View
@@ -6,8 +6,8 @@
from aspen.sockets import FFFD
from aspen.sockets.transport import XHRPollingTransport
from aspen.sockets.message import Message
-from aspen.tests.test_sockets_socket import make_socket, make_request
-from aspen.tests.fsfix import attach_teardown, mk
+from aspen.testing.sockets import make_socket, make_request
+from aspen.testing.fsfix import attach_teardown, mk
def make_transport(content='', state=0):
4 aspen/tests/test_website.py → tests/test_website.py
View
@@ -3,8 +3,8 @@
from aspen._tornado.template import Loader
from aspen.http.request import Request
-from aspen.tests import handle, StubRequest
-from aspen.tests.fsfix import attach_teardown, mk
+from aspen.testing import handle, StubRequest
+from aspen.testing.fsfix import attach_teardown, mk
from aspen.website import Website
Please sign in to comment.
Something went wrong with that request. Please try again.