def setUp(self):
     self.parser = PythonUnittestParser()
class PythonUnittestParser_Test(unittest.TestCase):


    def setUp(self):
        self.parser = PythonUnittestParser()


    def tearDown(self):
        del self.parser

    def test_validStatusLine(self):
        self.assertTrue(self.parser._validStatusLine("test_choice123 (__main__.TestSequenceFunctions123) ... ok"))
        self.assertTrue(self.parser._validStatusLine("test_error (__main__.TestSequenceFunctions) ... ERROR"))
        self.assertTrue(self.parser._validStatusLine("test_fail (__main__.TestSequenceFunctions) ... FAIL"))
        
    def test_validFailLine(self):
        self.assertTrue(self.parser._validFailLine("FAIL: test_fail123 (__main__.TestSequenceFunctions123)"))
        self.assertTrue(self.parser._validFailLine("ERROR: test_error (__main__.TestSequenceFunctions)"))
        
    def test_validFailInfoLine(self):
        self.assertTrue(self.parser._validFailInfoLine('  File "python_unittest_example.py", line 43, in test_error'))
        self.assertTrue(self.parser._validFailInfoLine('  File "python_unittest_example.123asd", line 40123, in test_fail'))
    
    def test_ParseFile(self):
        '''
        Make sure nothing explodes
        '''
        f = open(computeDataFilepath("./sample/python_unittest_sample", __file__))
        self.parser.parse(file = f)
        
    def test_ParseStringdata(self):
        '''
        Make sure nothing explodes
        '''
        f = open(computeDataFilepath("./sample/python_unittest_sample", __file__))
        self.parser.parse(stringData = f.read())
        
    def test_ParseNone(self):
        '''
        Test what happens when we don't give data to parse.
        '''
        self.assertRaises(ValueError, self.parser.parse, None)

    
    def test_Parse(self):
        '''
        Test and validate with real data.
        
        Everything is hardcoded. I did this b/c its easy, fast, simple and
        provides unobfuscated documentation.
        
        @date Jul 13, 2010
        '''
        data = open(computeDataFilepath("./sample/python_unittest_sample", __file__)).read()
        
        results = self.parser.parse(stringData = data)
        
        suites = results.getChildren()
        self.assertEquals(len(suites), 1)
        
        suite = suites[0]
        suiteData = suite.getRelevantDisplayData()
        self.assertTrue(('name', '__main__') in suiteData)
        
        subSuites = suite.getChildren()
        self.assertEqual(len(subSuites), 1)
        
        subSuite = subSuites[0]
        subSuiteData = subSuite.getRelevantDisplayData()
        self.assertTrue(('name', 'TestSequenceFunctions') in subSuiteData)
        
        tests = subSuite.getChildren()
        self.assertEqual(len(tests), 5)
        
        test0 = tests[0]
        test0_data = test0.getRelevantDisplayData()
        self.assertTrue(('name', 'test_choice') in test0_data)
        notice0 = test0.getChildren()[0] 
        self.assertEquals(notice0.type, "ok")
        
        test1 = tests[1]
        test1_data = test1.getRelevantDisplayData()
        self.assertTrue(('name', 'test_error') in test1_data)
        notice1 = test1.getChildren()[0]
        self.assertEquals(notice1.type, "error")
        notice1_data = notice1.getRelevantDisplayData()
        self.assertTrue(('file', 'python_unittest_example.py') in notice1_data)
        self.assertTrue(('line', '43') in notice1_data)
        self.assertTrue(('info', "NotImplementedError") in notice1_data)
        
        test2 =tests[2]
        test2_data = test2.getRelevantDisplayData()
        self.assertTrue(('name', 'test_fail') in test2_data)
        notice2 = test2.getChildren()[0]
        self.assertEquals(notice2.type, "fail")
        notice2_data = notice2.getRelevantDisplayData()
        self.assertTrue(('file', 'python_unittest_example.py') in notice2_data)
        self.assertTrue(('line', '40') in notice2_data)
        self.assertTrue(('info', "AssertionError: None") in notice2_data)
        
        test3 = tests[3]
        test3_data = test3.getRelevantDisplayData()
        self.assertTrue(('name', 'test_sample') in test3_data)
        notice3 = test3.getChildren()[0]
        self.assertEquals(notice3.type, "ok")
        
        test4 = tests[4]
        test4_data = test4.getRelevantDisplayData()
        self.assertTrue(('name', 'test_shuffle') in test4_data)
        notice4 = test4.getChildren()[0]
        self.assertEquals(notice4.type, "ok")
        
        
        
    def test_TestData_repr(self):
        '''
        Tests that TestData's __repr__() and __str__() don't explode
        '''
        from TestParser.Parser.PythonUnittestParser import TestData
        obj = TestData()
        str(obj)
        repr(obj)