#!/www/python/bin/python

"""
Test script for jwzthreading.

"""

import unittest
import jwzthreading, rfc822, StringIO

tested_modules = ["jwzthreading"]

def make_rfc822_message (S):
    input = StringIO.StringIO(S)
    return rfc822.Message(input)


class JWZTest (unittest.TestCase):

    def test_container (self):
        c = jwzthreading.Container()
        c2 = jwzthreading.Container()
        self.assertTrue(c.is_dummy())
        self.assertEquals(c.children, [])
        self.assertEquals(c.parent, None)
        self.assertFalse(c.has_descendant(c2))

        # Add a child
        c3 = jwzthreading.Container()
        c.add_child(c2)
        c2.add_child(c3)
        self.assertEquals(c.children, [c2])
        self.assertEquals(c2.parent, c)
        self.assertTrue(c.has_descendant(c2))
        self.assertTrue(c.has_descendant(c3))

        # Remove a child
        c.remove_child(c2)
        self.assertEquals(c.children, [])
        self.assertEquals(c2.parent, None)
        self.assertFalse(c.has_descendant(c3))
        self.assertTrue(c2.has_descendant(c3))

    def test_make_message (self):
        msg_templ = """Subject: %(subject)s
Message-ID: %(msg_id)s

Message body
"""
        m = make_rfc822_message("""Subject: random

Body.""")
        self.assertRaises(ValueError, jwzthreading.make_message, m)

        # Verify that repr() works

    def test_basic_message(self):
        msg = make_rfc822_message("""Subject: random
Message-ID: <message1>
References: <ref1> <ref2>
In-Reply-To: <reply>

Body.""")
        m = jwzthreading.make_message(msg)
        self.assertTrue(repr(m))
        self.assertEquals(m.subject, 'random')
        self.assertEquals(m.references,
                          ['ref1', 'ref2', 'reply'])


if __name__ == "__main__":
    unittest.main()

@@ -342,32 +342,49 @@
 ing.Container()%0A
+        repr(c)%0A%0A
         c2 = jwz
@@ -397,32 +397,32 @@
 ing.Container()%0A
-
         self.ass
@@ -855,24 +855,69 @@
 cendant(c3))
+%0A        self.assertTrue(c.has_descendant(c))
 %0A%0A        # 
@@ -1082,32 +1082,32 @@
 descendant(c3))%0A
-
         self.ass
@@ -1134,24 +1134,296 @@
 ndant(c3))%0A%0A
+        # Add child of one container to another%0A        c3 = jwzthreading.Container()%0A        c.add_child(c3)%0A        c2.add_child(c3)%0A        self.assertEquals(c3.parent, c2)%0A%0A    def test_uniq(self):%0A        self.assertEquals(jwzthreading.uniq((1,2,3,1,2,3)), %5B1,2,3%5D)%0A%0A
     def test

Test a few more lines in the Container class, and the uniq() function