Пример #1
0
    def test_text(self):
        parser = ALEParser()
        parser.set_source(self.file_text)
        self.assertEqual(parser.source_name, '<string>')

        parser.set_source(self.file_text, 'this is the filename here')
        self.assertEqual(parser.source_name, 'this is the filename here')

        parser.parse()

        self.assertEqual(digest_data(parser.heading), '048ae109bcba60d3e85c8f5ece9011d8')
        self.assertEqual(digest_data(parser.columns), 'ca25e97621e22bc63d173c2fca7f729d')
        self.assertEqual(digest_data(parser.data), '985d69a6f00745a2528f1df6a478d212')

        file_text = self.file_text.replace('\n', '\r\n')
        parser.set_source(file_text)

        parser.parse()

        self.assertEqual(digest_data(parser.heading), '048ae109bcba60d3e85c8f5ece9011d8')
        self.assertEqual(digest_data(parser.columns), 'ca25e97621e22bc63d173c2fca7f729d')
        self.assertEqual(digest_data(parser.data), '985d69a6f00745a2528f1df6a478d212')


        file_text = self.file_text.replace('\n', '\r')
        parser.set_source(file_text)

        parser.parse()

        self.assertEqual(digest_data(parser.heading), '048ae109bcba60d3e85c8f5ece9011d8')
        self.assertEqual(digest_data(parser.columns), 'ca25e97621e22bc63d173c2fca7f729d')
        self.assertEqual(digest_data(parser.data), '985d69a6f00745a2528f1df6a478d212')
Пример #2
0
    def test_stream(self):
        from StringIO import StringIO
        parser = ALEParser()
        stream = StringIO(self.file_text)
        parser.set_source(stream)
        self.assertEqual(parser.source_name, '<stream>')

        parser.set_source(stream, 'this is the filename here')
        self.assertEqual(parser.source_name, 'this is the filename here')

        parser.parse()

        self.assertEqual(digest_data(parser.heading), '048ae109bcba60d3e85c8f5ece9011d8')
        self.assertEqual(digest_data(parser.columns), 'ca25e97621e22bc63d173c2fca7f729d')
        self.assertEqual(digest_data(parser.data), '985d69a6f00745a2528f1df6a478d212')
Пример #3
0
    def test_errors(self):
        with self.assertRaises(ALEError):
            parser = ALEParser(list())

        with self.assertRaises(ALEError):
            parser = ALEParser()
            parser.set_source(list())

        # Missing source
        parser = ALEParser(strict=True)
        with self.assertRaises(ALEError):
            parser.parse()

        # Missing required heading
        parser.set_source(self.file_text.replace('FPS\t29.97', ''))
        with self.assertRaises(ALESyntaxError):
            parser.parse()

        # Missing required column
        parser.set_source(self.file_text.replace('\tEnd\n', '\n'))
        with self.assertRaises(ALESyntaxError):
            parser.parse()

        # Excess heading items
        error_heading = ['FPS\t29.97'] + ['TEST {0}\t{0}'.format(i) for i in range(63)]
        parser.set_source(self.file_text.replace('FPS\t29.97', '\n'.join(error_heading)))
        with self.assertRaises(ALESyntaxError):
            parser.parse()

        # Excess column items
        excess_column = ['End'] + ['Test {0}'.format(i) for i in range(63)]
        parser.set_source(self.file_text.replace('End\n', '\t'.join(excess_column) + '\n'))
        with self.assertRaises(ALESyntaxError):
            parser.parse()

        # Malformed heading declaration
        parser.set_source(self.file_text.replace(
            'VIDEO_FORMAT\tNTSC',
            'VIDEO_FORMAT  NTSC'))
        with self.assertRaises(ALESyntaxError):
            parser.parse()

        # Malformed column declaration
        parser.set_source(self.file_text.replace(
            'Name\tTracks\tStart\tEnd',
            'Name  Tracks  Start  End'))
        with self.assertRaises(ALESyntaxError):
            parser.parse()

        # Columns already defined...
        parser.set_source(self.file_text.replace(
            'Name\tTracks\tStart\tEnd',
            'Name\tTracks\tStart\tEnd\nName\tTracks\tStart\tEnd'))
        with self.assertRaises(ALESyntaxError):
            parser.parse()

        # We cant parse PIZZA delimited files! :O
        parser.set_source(self.file_text.replace('TABS', 'PIZZA'))
        with self.assertRaises(ALESyntaxError):
            parser.parse()

        # Missing sections - no Heading
        parser.set_source(self.file_text.split('Heading', 1)[1])
        with self.assertRaises(ALESyntaxError):
            parser.parse()

        # Missing sections - no Column
        parser.set_source(self.file_text.split('Column', 1)[0])
        with self.assertRaises(ALESyntaxError):
            parser.parse()

        # Missing sections - no Data
        parser.set_source(self.file_text.split('Data', 1)[0])
        with self.assertRaises(ALESyntaxError):
            parser.parse()