Mercurial > sjsbox
changeset 3:b935781e3f89
added tests
author | Atul Varma <avarma@mozilla.com> |
---|---|
date | Mon, 31 May 2010 09:35:42 -0700 |
parents | 70d20a057e84 |
children | 0203cae3947f |
files | example.py sjsbox/server.py tests/test_server.py |
diffstat | 3 files changed, 24 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/example.py Mon May 31 05:27:25 2010 -0700 +++ b/example.py Mon May 31 09:35:42 2010 -0700 @@ -3,10 +3,12 @@ from wsgiref.simple_server import make_server import sjsbox.server +import sjsbox.fs if __name__ == '__main__': + directory = sjsbox.fs.Dir(os.path.abspath('./boxes')) logging.basicConfig(level=logging.DEBUG) - boxes = sjsbox.server.Boxes(os.path.abspath('./boxes')) + boxes = sjsbox.server.Boxes(directory) app = sjsbox.server.App(boxes) port = 8000 httpd = make_server('', port, app)
--- a/sjsbox/server.py Mon May 31 05:27:25 2010 -0700 +++ b/sjsbox/server.py Mon May 31 09:35:42 2010 -0700 @@ -5,16 +5,20 @@ except ImportError: import simplejson as json -import sjsbox.fs from sjsbox.box import BoxParent class Boxes(object): - def __init__(self, rootdir): - self.dir = sjsbox.fs.Dir(rootdir) + def __init__(self, directory, boxfactory=BoxParent): + self.boxfactory = boxfactory + self.dir = directory self.boxes = {} self.box_mtimes = {} self.update() + def shutdown(self): + for box in self.boxes.itervalues(): + box.shutdown() + def update(self): visited = {} for f in self.dir: @@ -22,7 +26,7 @@ if boxname not in self.boxes: logging.info('creating box %s' % boxname) self.box_mtimes[boxname] = f.mtime - self.boxes[boxname] = BoxParent(f) + self.boxes[boxname] = self.boxfactory(f) else: box_mtime = f.mtime if box_mtime > self.box_mtimes[boxname]:
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/test_server.py Mon May 31 09:35:42 2010 -0700 @@ -0,0 +1,13 @@ +import sjsbox.server + +def test_boxes(): + class MockFile(object): + mtime = 0 + name = 'foo.js' + contents = 'function handle() { return 404; }' + + boxes = sjsbox.server.Boxes([MockFile()]) + boxes.shutdown() + +def test_app(): + sjsbox.server.App(None)