diff options
author | Olivier Cayrol (Logilab) <Olivier.Cayrol@logilab.fr> | 2009-08-26 14:47:05 +0200 |
---|---|---|
committer | Olivier Cayrol (Logilab) <Olivier.Cayrol@logilab.fr> | 2009-08-26 14:47:05 +0200 |
commit | d91784c06bac1975b22e0c56a1017332fd106536 (patch) | |
tree | df1551b3df1d47b1b0c76bcbcd92baf00ecde6d2 /test | |
parent | 1b31b5f655b08f3ba2112b3b4575ec92706498d9 (diff) | |
download | logilab-common-d91784c06bac1975b22e0c56a1017332fd106536.tar.gz |
Added a function for parsing processing instructions in XML data
Diffstat (limited to 'test')
-rw-r--r-- | test/unittest_xmlutils.py | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/test/unittest_xmlutils.py b/test/unittest_xmlutils.py new file mode 100644 index 0000000..12fafae --- /dev/null +++ b/test/unittest_xmlutils.py @@ -0,0 +1,58 @@ +# -*- coding: utf-8 -*- + +from logilab.common.testlib import TestCase, unittest_main +from logilab.common.xmlutils import parse_pi_data + + +class ProcessingInstructionDataParsingTest(TestCase): + def test_empty_pi(self): + """ + Tests the parsing of the data of an empty processing instruction. + """ + pi_data = u" \t \n " + data = parse_pi_data(pi_data) + self.assertEquals(data, {}) + + def test_simple_pi_with_double_quotes(self): + """ + Tests the parsing of the data of a simple processing instruction using + double quotes for embedding the value. + """ + pi_data = u""" \t att="value"\n """ + data = parse_pi_data(pi_data) + self.assertEquals(data, {u"att": u"value"}) + + def test_simple_pi_with_simple_quotes(self): + """ + Tests the parsing of the data of a simple processing instruction using + simple quotes for embedding the value. + """ + pi_data = u""" \t att='value'\n """ + data = parse_pi_data(pi_data) + self.assertEquals(data, {u"att": u"value"}) + + def test_complex_pi_with_different_quotes(self): + """ + Tests the parsing of the data of a complex processing instruction using + simple quotes or double quotes for embedding the values. + """ + pi_data = u""" \t att='value'\n att2="value2" att3='value3'""" + data = parse_pi_data(pi_data) + self.assertEquals(data, {u"att": u"value", u"att2": u"value2", + u"att3": u"value3"}) + + def test_pi_with_non_attribute_data(self): + """ + Tests the parsing of the data of a complex processing instruction + containing non-attribute data. + """ + pi_data = u""" \t keyword att1="value1" """ + data = parse_pi_data(pi_data) + self.assertEquals(data, {u"keyword": None, u"att1": u"value1"}) + + +# definitions for automatic unit testing + +if __name__ == '__main__': + unittest_main() + |