diff --git a/patacrep/songs/chordpro/syntax.py b/patacrep/songs/chordpro/syntax.py index 6c8d2540..6379ca62 100644 --- a/patacrep/songs/chordpro/syntax.py +++ b/patacrep/songs/chordpro/syntax.py @@ -320,6 +320,5 @@ def parse_song(content, filename=None): ) if parsed_content is None: # There was a fatal error parsing the content - # TODO: implement error handling by looking into parser - raise Exception('The song could not be parsed') + raise SyntaxError('Fatal error during song parsing: {}'.format(filename)) return parsed_content diff --git a/test/test_chordpro/invalid_content.source b/test/test_chordpro/errors/invalid_content.source similarity index 100% rename from test/test_chordpro/invalid_content.source rename to test/test_chordpro/errors/invalid_content.source diff --git a/test/test_chordpro/invalid_content.sgc b/test/test_chordpro/invalid_content.sgc deleted file mode 100644 index 768ee9ee..00000000 --- a/test/test_chordpro/invalid_content.sgc +++ /dev/null @@ -1 +0,0 @@ -{lang: en} diff --git a/test/test_chordpro/test_parser.py b/test/test_chordpro/test_parser.py index 4315e241..d14bcb4d 100644 --- a/test/test_chordpro/test_parser.py +++ b/test/test_chordpro/test_parser.py @@ -91,6 +91,14 @@ class FileTest(unittest.TestCase, metaclass=dynamic.DynamicTest): cls._create_test(base, dest), ) + with files.chdir('errors'): + for source in sorted(glob.glob('*.source')): + base = source[:-len(".source")] + yield ( + "test_{}_failure".format(base), + cls._create_failure(base), + ) + @classmethod def _create_test(cls, base, dest): """Return a function testing that `base` compilation in `dest` format. @@ -105,6 +113,24 @@ class FileTest(unittest.TestCase, metaclass=dynamic.DynamicTest): ).format(base=os.path.basename(base), format=dest) return test_parse_render + @classmethod + def _create_failure(cls, base): + """Return a function testing that `base` fails. + """ + + def test_parse_render(self): + """Test that `base` parsing fails.""" + sourcename = "{}.source".format(base) + with self.chdir(): + with files.chdir('errors'): + parser = self.song_plugins[LANGUAGES['sgc']]['sgc'] + self.assertRaises(SyntaxError, parser, sourcename, self.config) + + test_parse_render.__doc__ = ( + "Test that '{base}' parsing fails." + ).format(base=os.path.basename(base)) + return test_parse_render + @classmethod def _overwrite_clrf(cls): """Overwrite `*.crlf.source` files to force the CRLF line endings.