Attachment 'test_attrparse.py'

Download

   1 # -*- coding: utf-8 -*-
   2 """
   3 attribute parser tests
   4 """
   5 
   6 import unittest
   7 import attrparse        
   8 
   9 class ScanTestCase(unittest.TestCase):
  10     
  11     def setUp(self):
  12         self.parser = attrparse.Parser()
  13     
  14     def testPlain(self):
  15         """ parse text with no attribute """
  16         self.parser.scan("plain")
  17         expected = [('plain', [])]
  18         self.assertEqual(expected, self.parser.output)
  19 
  20     def testSingle(self):
  21         """ parse text with single attribute """
  22         self.parser.scan("'''strong'''")
  23         expected = [('strong', ['strong'])]
  24         self.assertEqual(expected, self.parser.output)
  25 
  26     def testPlainAndSingle(self):
  27         """ parse plain text then attributed """
  28         self.parser.scan("plain '''strong'''")
  29         expected = [
  30             ('plain ', []),
  31             ('strong', ['strong']),
  32             ]
  33         self.assertEqual(expected, self.parser.output)
  34 
  35     def testSingleAndPlain(self):
  36         """ parse attributed then plain text """
  37         self.parser.scan("'''strong''' plain")
  38         expected = [
  39             ('strong', ['strong']),
  40             (' plain', []),
  41             ]
  42         self.assertEqual(expected, self.parser.output)
  43 
  44     def testAllSingles(self):
  45         """ parse all single attributes """
  46         text = "plain '''strong''' ''em'' __u__ plain"
  47         self.parser.scan(text)
  48         expected = [
  49             ('plain ', []),
  50             ('strong', ['strong']),
  51             (' ', []),
  52             ('em', ['em']),
  53             (' ', []),
  54             ('u', ['u']),
  55             (' plain', []),
  56             ]
  57         self.assertEqual(expected, self.parser.output)
  58 
  59     def testMultipleAttribute(self):
  60         """ parse multiple attribute per run of text """
  61         text = "'''''__strong em u__'''''"
  62         self.parser.scan(text)
  63         expected = [
  64             ('strong em u', ['em', 'strong', 'u']),
  65             ]
  66         self.assertEqual(expected, self.parser.output)
  67 
  68     def testNestedAttribtues(self):
  69         """ parse nested attributes <a><b></b></a> """
  70         text = "'''strong ''strong em'''''"
  71         self.parser.scan(text)
  72         expected = [
  73             ('strong ', ['strong']),
  74             ('strong em', ['em', 'strong']),
  75             ]
  76         self.assertEqual(expected, self.parser.output)
  77 
  78     def testCrossedAttribtues(self):
  79         """ parse mixed attributes <a><b></a></b> """
  80         text = "'''strong ''strong em''' em''"
  81         self.parser.scan(text)
  82         expected = [
  83             ('strong ', ['strong']),
  84             ('strong em', ['em', 'strong']),
  85             (' em', ['em']),
  86             ]
  87         self.assertEqual(expected, self.parser.output)
  88 
  89     def testOpenAttribtue(self):
  90         """ parse open attribute <a> """
  91         text = "plain '''strong"
  92         self.parser.scan(text)
  93         expected = [
  94             ('plain ', []),
  95             ('strong', ['strong']),
  96             ]
  97         self.assertEqual(expected, self.parser.output)
  98 
  99 
 100 def suite():
 101     test_cases = [unittest.makeSuite(obj, 'test') 
 102         for name, obj in globals().items()
 103         if name.endswith('TestCase')]
 104     return unittest.TestSuite(test_cases)
 105     
 106 if __name__ == '__main__':
 107     unittest.TextTestRunner(verbosity=2).run(suite())

Attached Files

To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.
  • [get | view] (2004-11-11 08:34:02, 1.5 KB) [[attachment:attrparse.py]]
  • [get | view] (2004-11-11 05:37:19, 3.1 KB) [[attachment:test_attrparse.py]]
 All files | Selected Files: delete move to page copy to page

You are not allowed to attach a file to this page.