From 00c8bef0ff21794e622b7f442408e29c644b7002 Mon Sep 17 00:00:00 2001 From: Aldo Cortesi Date: Sat, 9 Jun 2012 15:08:51 +1200 Subject: [PATCH] Port test suite over to Nose. --- .coveragerc | 3 +++ .gitignore | 1 + libpathod/rparse.py | 4 +-- libpathod/test.py | 1 + test/test_pathod.py | 16 +++--------- test/test_rparse.py | 64 +++++++++++++++++++-------------------------- test/test_test.py | 20 ++++++-------- test/test_utils.py | 24 ++++++----------- test/tutils.py | 57 ++++++++++++++++++++++++++++++++++++++++ 9 files changed, 110 insertions(+), 80 deletions(-) create mode 100644 .coveragerc create mode 100644 test/tutils.py diff --git a/.coveragerc b/.coveragerc new file mode 100644 index 000000000..a2e5ffc51 --- /dev/null +++ b/.coveragerc @@ -0,0 +1,3 @@ +[report] +omit = *contrib* +include = *libpathod* diff --git a/.gitignore b/.gitignore index 08d66342a..64280a20b 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ MANIFEST # Vim swap files *.swp /doc +.coverage diff --git a/libpathod/rparse.py b/libpathod/rparse.py index 87eff563d..aa59d021f 100644 --- a/libpathod/rparse.py +++ b/libpathod/rparse.py @@ -393,10 +393,8 @@ class Response: def add_timeout(self, s, callback): if TESTING: callback() - # begin nocover - else: + else: # pragma: no cover tornado.ioloop.IOLoop.instance().add_timeout(time.time() + s, callback) - # end nocover def write_values(self, fp, vals, actions, sofar=0, skip=0, blocksize=BLOCKSIZE): while vals: diff --git a/libpathod/test.py b/libpathod/test.py index 508605bf9..b7475bc9b 100644 --- a/libpathod/test.py +++ b/libpathod/test.py @@ -1,6 +1,7 @@ import json, threading, Queue import requests import pathod, utils +import tutils IFACE = "127.0.0.1" diff --git a/test/test_pathod.py b/test/test_pathod.py index e4d959eb3..3fd2388ad 100644 --- a/test/test_pathod.py +++ b/test/test_pathod.py @@ -1,8 +1,7 @@ -import libpry from libpathod import pathod from tornado import httpserver -class uApplication(libpry.AutoTree): +class TestApplication: def test_anchors(self): a = pathod.PathodApp(staticdir=None) a.add_anchor("/foo", "200") @@ -31,13 +30,6 @@ class uApplication(libpry.AutoTree): assert not a.log_by_id(0) -class u_make_server(libpry.AutoTree): - def test_simple(self): - app = pathod.PathodApp() - assert pathod.make_server(app, 0, "127.0.0.1", None) - - -tests = [ - uApplication(), - u_make_server() -] +def test_make_server(): + app = pathod.PathodApp() + assert pathod.make_server(app, 0, "127.0.0.1", None) diff --git a/test/test_rparse.py b/test/test_rparse.py index a2a83c617..f0db75fdb 100644 --- a/test/test_rparse.py +++ b/test/test_rparse.py @@ -1,11 +1,11 @@ import os -import libpry from libpathod import rparse, utils +import tutils rparse.TESTING = True -class uMisc(libpry.AutoTree): +class TestMisc: def test_generators(self): v = rparse.Value.parseString("'val'")[0] g = v.get_generator({}) @@ -26,16 +26,16 @@ class uMisc(libpry.AutoTree): assert g[1] == "n" def test_filegenerator(self): - t = self.tmpdir() - path = os.path.join(t, "foo") - f = open(path, "w") - f.write("x"*10000) - f.close() - g = rparse.FileGenerator(path) - assert len(g) == 10000 - assert g[0] == "x" - assert g[-1] == "x" - assert g[0:5] == "xxxxx" + with tutils.tmpdir() as t: + path = os.path.join(t, "foo") + f = open(path, "w") + f.write("x"*10000) + f.close() + g = rparse.FileGenerator(path) + assert len(g) == 10000 + assert g[0] == "x" + assert g[-1] == "x" + assert g[0:5] == "xxxxx" def test_valueliteral(self): v = rparse.ValueLiteral("foo") @@ -50,17 +50,17 @@ class uMisc(libpry.AutoTree): v = rparse.Value.parseString("