]> mj.ucw.cz Git - moe.git/commitdiff
Fix in status parsing, add test, add update test
authorTomas Gavenciak <gavento@ucw.cz>
Sat, 27 Nov 2010 13:21:44 +0000 (14:21 +0100)
committerTomas Gavenciak <gavento@ucw.cz>
Sat, 27 Nov 2010 13:23:37 +0000 (14:23 +0100)
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
t/moe/status_test.py

index 3a5c34f6218a0d6da06e85330e6e9b76fc18b257..0cba45cb6eb029e3b100bd4dbdf7ae4adc03088c 100644 (file)
@@ -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")
index 7fbd6e07871d25f1d9789ae28ea2fde1cab6ca70..f4df2f6147fd1c51aebb2dd228fa1fef21f89962 100644 (file)
@@ -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(