def testReadV1WriteV1(self): print "Read Version 1, Write Version 1" fileglob = os.path.join("testdata", "v1", "*.brp") for testfile in glob.glob(fileglob): print testfile score = ScoreSerializer.loadScore(testfile) written = StringIO() ScoreSerializer.write(score, written, DBConstants.DBFF_1) with fileUtils.DataReader(testfile) as reader: data = reader.read().splitlines() written = written.getvalue().splitlines() self.assertEqual(data, written)
def testVersion0Files(self): print "Version 0" fileglob = os.path.join("testdata", "v0", "*.brp") for testfile in glob.glob(fileglob): print testfile score = ScoreSerializer.loadScore(testfile) written = StringIO() ScoreSerializer.write(score, written, DBConstants.DBFF_0) with fileUtils.DataReader(testfile) as reader: data = reader.read().splitlines() written = written.getvalue().splitlines() while True: try: self._compareData(data, written) break except self.NoFF: written = written[1:] except self.MCounts: written = [ x for x in written if not x.lstrip().startswith("MEASURECOUNTSVISIBLE") ] except self.Barline: data = [x.replace('NORMAL_BAR,', '') for x in data] except self.NoLilyFormat: written = [ x for x in written if not x.lstrip().startswith("LILYFORMAT") ] except self.NoLilySize: written = [ x for x in written if not x.lstrip().startswith("LILYSIZE") ] except self.NoLilyPages: written = [ x for x in written if not x.lstrip().startswith("LILYPAGES") ] except self.NoLilyFill: written = [ x for x in written if not x.lstrip().startswith("LILYFILL") ] except self.ShortNoteHeads: data, written = self._tidyShortNoteHeads(data, written) except self.OldTriplets: data = [x.replace("|^ea|", "|^+a|") for x in data] except self.NoNoteheads: written = [x for x in written if "NOTEHEAD" not in x] data = [x for x in data if "NOTEHEAD" not in x]
def loadScore(cls, filename): with fileUtils.DataReader(filename) as reader: score = cls.read(reader) return score