Example #1
0
    def _pretty_export_import_pretty_test(self, part1):
        # pretty print the part
        pstring1 = part1.pretty()

        with TemporaryFile() as f:
            # save part to musicxml
            save_musicxml(part1, f)
            f.flush()
            f.seek(0)
            _tmp = f.read().decode('utf8')
            f.seek(0)
            # load part from musicxml
            part2 = load_musicxml(f)

        # pretty print saved/loaded part:
        pstring2 = part2.pretty()

        # test pretty printed strings for equality
        equal = pstring1 == pstring2

        if not equal:
            print(pstring1)
            print(pstring2)
            print(_tmp)
            show_diff(pstring1, pstring2)
        msg = 'Exported and imported score does not yield identical pretty printed representations'
        self.assertTrue(equal, msg)
Example #2
0
    def test_unfold_timeline(self):
        for fn, fn_target_1, fn_target_2 in MUSICXML_UNFOLD_TESTPAIRS:
            part = load_musicxml(fn, validate=False)
            part = score.unfold_part_maximal(part)
            result = save_musicxml(part).decode("UTF-8")
            with open(fn_target_1) as f:
                target = f.read()
            equal = target == result
            if not equal:
                show_diff(result, target)
            msg = "Unfolding part of MusicXML file {} does not yield expected result".format(
                fn)
            self.assertTrue(equal, msg)

            # check unfold with update_id
            part = score.unfold_part_maximal(part, update_ids=True)
            result = save_musicxml(part).decode("UTF-8")
            with open(fn_target_2) as f:
                target = f.read()
            equal = target == result
            if not equal:
                show_diff(result, target)
            msg = "Unfolding part of MusicXML file {} does not yield expected result".format(
                fn)
            self.assertTrue(equal, msg)
Example #3
0
 def test_import_export(self):
     for fn in MUSICXML_IMPORT_EXPORT_TESTFILES:
         with open(fn) as f:
             parts = load_musicxml(f, validate=False)
             result = save_musicxml(parts).decode('UTF-8')
             f.seek(0)
             target = f.read()
             equal = target == result
             if not equal:
                 show_diff(result, target)
             msg = "Import and export of MusicXML of file {} does not yield identical result".format(fn)
             self.assertTrue(equal, msg)
Example #4
0
    def test_export_import_pprint(self):
        # create a part
        part1 = score.Part('My Part')

        # create contents
        divs = 10
        ts = score.TimeSignature(3, 4)
        page1 = score.Page(1)
        system1 = score.System(1)
        measure1 = score.Measure(number=1)
        note1 = score.Note(step='A', octave=4, voice=1, staff=1)
        rest1 = score.Rest(voice=1, staff=1)
        note2 = score.Note(step='C', octave=5, alter=-1, voice=2, staff=1)
        
        # and add the contents to the part:
        part1.set_quarter_duration(0, divs)
        part1.add(ts, 0)
        part1.add(measure1, 0, 30)
        part1.add(page1, 0)
        part1.add(system1, 0)
        part1.add(note1, 0, 15)
        part1.add(rest1, 15, 30)
        part1.add(note2, 0, 30)
        
        score.set_end_times(part1)
        
        # pretty print the part
        pstring1 = part1.pretty()

        with TemporaryFile() as f:
            # save part to musicxml
            save_musicxml(part1, f)
            f.flush()
            f.seek(0)
            # load part from musicxml
            part2 = load_musicxml(f)

        # pretty print saved/loaded part:
        pstring2 = part2.pretty()

        # test pretty printed strings for equality
        equal = pstring1 == pstring2

        if not equal:
            show_diff(pstring1, pstring2)
        msg = 'Exported and imported score does not yield identical pretty printed representations'
        self.assertTrue(equal, msg)