From 2091d1638734022a9ff879148ed432556c99db0f Mon Sep 17 00:00:00 2001 From: Aldo Cortesi Date: Sat, 2 May 2015 17:19:48 +1200 Subject: [PATCH] test coverage: generators and websockets to 100% --- libpathod/language/base.py | 8 -------- libpathod/language/generators.py | 2 +- test/test_language_generators.py | 11 +++++++++++ test/test_language_websocket.py | 23 ++++++++++++++--------- 4 files changed, 26 insertions(+), 18 deletions(-) diff --git a/libpathod/language/base.py b/libpathod/language/base.py index 6de8c086e..eceeae263 100644 --- a/libpathod/language/base.py +++ b/libpathod/language/base.py @@ -11,14 +11,6 @@ from . import generators, exceptions TRUNCATE = 1024 - -def quote(s): - quotechar = s[0] - s = s[1:-1] - s = s.replace(quotechar, "\\" + quotechar) - return quotechar + s + quotechar - - v_integer = pp.Word(pp.nums)\ .setName("integer")\ .setParseAction(lambda toks: int(toks[0])) diff --git a/libpathod/language/generators.py b/libpathod/language/generators.py index ae6a05301..58be7130d 100644 --- a/libpathod/language/generators.py +++ b/libpathod/language/generators.py @@ -40,7 +40,7 @@ class TransformGenerator: return self.transform(a, d) def __repr__(self): - return "'%s'"%self.gen + return "'transform(%s)'"%self.gen class LiteralGenerator: diff --git a/test/test_language_generators.py b/test/test_language_generators.py index 3db1ac91d..854b84857 100644 --- a/test/test_language_generators.py +++ b/test/test_language_generators.py @@ -36,3 +36,14 @@ def test_filegenerator(): # remove all references to FileGenerator instance to close the file # handle. del g + + +def test_transform_generator(): + def trans(offset, data): + return "a" * len(data) + g = generators.LiteralGenerator("one") + t = generators.TransformGenerator(g, trans) + assert len(t) == len(g) + assert t[0] == "a" + assert t[:] == "a" * len(g) + assert repr(t) diff --git a/test/test_language_websocket.py b/test/test_language_websocket.py index 8a683d813..3b1d48528 100644 --- a/test/test_language_websocket.py +++ b/test/test_language_websocket.py @@ -8,13 +8,18 @@ def parse_request(s): class TestWebsocketFrame: - def test_spec(self): - e = websockets.WebsocketFrame.expr() - wf = e.parseString("wf:b'foo'") - assert wf - - assert parse_request("wf:b'foo'") - def test_values(self): - r = parse_request("wf:b'foo'") - assert r.values(language.Settings()) + specs = [ + "wf", + "wf:b'foo'" + ] + for i in specs: + wf = parse_request(i) + assert isinstance(wf, websockets.WebsocketFrame) + assert wf + assert wf.values(language.Settings()) + assert wf.resolve(language.Settings()) + + spec = wf.spec() + wf2 = parse_request(spec) + assert wf2.spec() == spec