From a2b67db58687090326fd51af7db278c194692977 Mon Sep 17 00:00:00 2001 From: Tomas Gavenciak Date: Sat, 27 Nov 2010 14:21:44 +0100 Subject: [PATCH] Fix in status parsing, add test, add update test Status parser did not check for all subtrees to be closed, fix Add test for the above bug Add tests for status update --- t/moe/status.py | 2 ++ t/moe/status_test.py | 17 ++++++++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/t/moe/status.py b/t/moe/status.py index 3a5c34f..0cba45c 100644 --- a/t/moe/status.py +++ b/t/moe/status.py @@ -151,3 +151,5 @@ class Status: this = stk.pop() else: raise InvalidStatusFile("Parse error: malformed line") + if stk: + raise InvalidStatusFile("Parse error: not all subtrees closed") diff --git a/t/moe/status_test.py b/t/moe/status_test.py index 7fbd6e0..f4df2f6 100644 --- a/t/moe/status_test.py +++ b/t/moe/status_test.py @@ -24,6 +24,7 @@ class TestStatus(unittest.TestCase): assert(st['a']['z'] == '\n') s.assertRaises(InvalidStatusFile, s.parse, "a") s.assertRaises(InvalidStatusFile, s.parse, "a\n(\n)") + s.assertRaises(InvalidStatusFile, s.parse, "a.b:c") def test_unique(s): s.assertRaises(InvalidStatusFile, s.parse, "a:1\na:1") @@ -37,6 +38,9 @@ class TestStatus(unittest.TestCase): # the continuation of entry must be at consecutive lines s.assertRaises(InvalidStatusFile, s.parse, "a:\n:\n\n:z") s.assertRaises(InvalidStatusFile, s.parse, "a:\n#\n:\n") + # All subtrees must be closed + s.assertRaises(InvalidStatusFile, s.parse, "a(") + s.assertRaises(InvalidStatusFile, s.parse, "a(\nb(\n)\n") # Valid entries st = s.parse("a:\t\n\t \t : \t\n:"); assert(st['a'] == '\t\n \t\n') st = s.parse(" a : \n :x"); assert(st['a'] == ' \nx') @@ -48,6 +52,17 @@ class TestStatus(unittest.TestCase): s.assertRaises(InvalidStatusFile, s.parse, "a( #comm\n)") s.assertRaises(InvalidStatusFile, s.parse, "a(\n)#comm") + def test_update(s): + st1 = s.parse('a:1\nb(\nc:3\n:4\nz:0\n)\nd:5') + st2 = s.parse('a:A\nb(\nc:C\nx:y\n)\ne:E') + st12 = s.parse('a:A\nb(\nc:C\nx:y\nz:0\n)\nd:5\ne:E') + st3 = s.parse('a(\n)') + st4 = s.parse('b:0') + st1.update(st2) + assert(st1 == st12) + s.assertRaises(TypeError, st1.update, st3) + s.assertRaises(TypeError, st1.update, st4) + def test_file_utf8(s): st = Status() f = tempfile.TemporaryFile(mode='w+t') @@ -56,7 +71,7 @@ class TestStatus(unittest.TestCase): st.read(f=f) assert(st['a'] == '\xc3\xa1\xc5\xa1\xc4\x8f\xc3\xab\xc3\xa5') - def test_file_wr_eq_l2(s): + def test_file_w_r_eq_l2(s): st = s.parse('a:' + u'ášďě'.encode('l2') + """ b( c( -- 2.39.2