from unittest import TestCase

from pyparsing import ParseException
from regparser.grammar.atomic import *


class GrammarAtomicTests(TestCase):
    def test_em_digit_p(self):
        result = em_digit_p.parseString('(<E T="03">2</E>)')
        self.assertEqual('2', result.p5)

    def test_double_alpha(self):
        # Match (aa), (bb), etc.
        result = lower_p.parseString('(a)')
        self.assertEqual('a', result.p1)

        result = lower_p.parseString('(aa)')
        self.assertEqual('aa', result.p1)

        result = lower_p.parseString('(i)')
        self.assertEqual('i', result.p1)

        # Except for roman numerals
        with self.assertRaises(ParseException):
            result = lower_p.parseString('(ii)')
        with self.assertRaises(ParseException):
            result = lower_p.parseString('(iv)')


@@ -317,33 +317,115 @@
     
-# Match (aa), (bb), etc.%0A
+for text, p1 in %5B('(a)', 'a'),%0A                     ('(aa)', 'aa'),%0A                     ('(i)','i')%5D:%0A    
     
@@ -461,15 +461,18 @@
 ing(
-'(a)')%0A
+text)%0A    
     
@@ -492,19 +492,18 @@
 rtEqual(
-'a'
+p1
 , result
@@ -520,96 +520,72 @@
     
-result = lower_p.parseString('(aa)')%0A        self.assertEqual('aa', result.p1)%0A%0A
+for text in %5B'(ii)', '(iv)', '(vi)'%5D:%0A            try:%0A 
         
 resu
@@ -572,32 +572,39 @@
   try:%0A         
+       
 result = lower_p
@@ -616,21 +616,20 @@
 eString(
-'(i)'
+text
 )%0A      
@@ -634,50 +634,67 @@
     
-self.assertEqual('i', result.p1)%0A%0A
+    except ParseException:%0A                pass%0A   
         
 # Ex
@@ -693,164 +693,127 @@
     
-# E
+ e
 xcept 
-for roman numerals%0A        with self.assertRaises(ParseException):%0A            result = lower_p.parseString('(ii)')%0A        with self.assertR
+e:%0A                self.fail(%22Unexpected error:%22, e)%0A            else:%0A                self.fail(%22Didn't r
 aise
-s(
+ 
 Pars
@@ -826,57 +826,8 @@
 tion
-):%0A            result = lower_p.parseString('(iv)'
+%22
 )%0A%0A

Refactor test to eliminate assertRaises() error with Python 2.6