+14
-13
@@ -29,6 +29,7 @@ import generator.pitch
|
||||
import generator.playback
|
||||
import tests.arrangement_fixtures
|
||||
import generator.score
|
||||
import generator.theme
|
||||
import tests.musicxml_roundtrip
|
||||
import tests.rhythm_fixtures
|
||||
import tests.test_musicxml
|
||||
@@ -48,13 +49,13 @@ class ScoreBundleTests(unittest.TestCase):
|
||||
original = {p.relative_to(output): p.read_bytes() for p in output.rglob('*') if p.is_file()}
|
||||
self.assertTrue(list(output.rglob('*.png')))
|
||||
(data / 'rhythms' / 'drafts').mkdir(parents=True)
|
||||
(data / 'sequences' / '3-4').mkdir(parents=True)
|
||||
(data / 'sequences/3-4/0001.xml').write_text(tests.test_musicxml.xml_score(tests.test_musicxml.xml_note()))
|
||||
for path in ('rhythms/0001.xml', 'rhythms/drafts/0002.xml', 'sequences/0001.xml', 'sequences/3-4/0002.xml'):
|
||||
(data / 'sequences' / '3_4').mkdir(parents=True)
|
||||
(data / 'sequences/3_4/0001.xml').write_text(tests.test_musicxml.xml_score(tests.test_musicxml.xml_note()))
|
||||
for path in ('rhythms/0001.xml', 'rhythms/drafts/0002.xml', 'sequences/0001.xml', 'sequences/3_4/0002.xml'):
|
||||
(data / path).write_text('<unfinished')
|
||||
generator.__main__.generate_assets(args)
|
||||
self.assertEqual(original, {p.relative_to(output): p.read_bytes() for p in output.rglob('*') if p.is_file()})
|
||||
scale = data / 'scales/major-scale-modes/0002.xml'
|
||||
scale = data / 'scales/major_scale_modes/0002.xml'
|
||||
previous = scale.read_bytes()
|
||||
scale.write_text('<unfinished')
|
||||
with self.assertRaisesRegex(ValueError, '0002.xml'):
|
||||
@@ -76,7 +77,7 @@ class ScoreBundleTests(unittest.TestCase):
|
||||
self.assertEqual(original, {p.relative_to(output): p.read_bytes() for p in output.rglob('*') if p.is_file()})
|
||||
dense = ''.join(tests.test_musicxml.xml_note('G', 1, '64th') for _ in range(64))
|
||||
source.write_text(tests.test_musicxml.xml_score(dense, divisions=16))
|
||||
with self.assertRaisesRegex(generator.engraving.types.EngravingError, r'songs/fixture-electric.json: measure 1 .*complete measure exceeds'):
|
||||
with self.assertRaisesRegex(generator.engraving.types.EngravingError, r'songs/fixture_electric.json: measure 1 .*complete measure exceeds'):
|
||||
generator.__main__.generate_assets(args)
|
||||
self.assertEqual(original, {p.relative_to(output): p.read_bytes() for p in output.rglob('*') if p.is_file()})
|
||||
source.write_text(tests.test_musicxml.xml_score(tests.test_musicxml.xml_note(extra='<accidental smufl="unavailableGlyph">other</accidental>')))
|
||||
@@ -93,7 +94,7 @@ class ScoreBundleTests(unittest.TestCase):
|
||||
generator.__main__.generate_assets(args)
|
||||
self.assertFalse(legacy_output.exists())
|
||||
self.assertFalse(list((output / 'songs').glob('fixture*')))
|
||||
self.assertEqual(len(list((output / 'songs').glob('renamed-*.json'))), 3)
|
||||
self.assertEqual(len(list((output / 'songs').glob('renamed_*.json'))), 3)
|
||||
source.unlink()
|
||||
generator.__main__.generate_assets(args)
|
||||
self.assertFalse(list(output.rglob('*.png')))
|
||||
@@ -151,7 +152,7 @@ class ScoreBundleTests(unittest.TestCase):
|
||||
tree = xml.etree.ElementTree.fromstring(tests.test_musicxml.xml_score(tests.test_musicxml.xml_note()))
|
||||
xml.etree.ElementTree.SubElement(tree.find('part'), 'measure', number='2').append(xml.etree.ElementTree.fromstring(tests.test_musicxml.xml_note()))
|
||||
source = tests.test_musicxml.parse(xml.etree.ElementTree.tostring(tree, encoding='unicode'))
|
||||
source['staves'][0]['octave_shifts'] = [{'id': 'octave-1', 'start': generator.model.rational(0), 'end': generator.model.rational(4), 'octaves': 1}]
|
||||
source['staves'][0]['octave_shifts'] = [{'id': 'octave_1', 'start': generator.model.rational(0), 'end': generator.model.rational(4), 'octaves': 1}]
|
||||
restored = self.round_trip(source)
|
||||
self.assertEqual(source['staves'][0]['octave_shifts'], restored['staves'][0]['octave_shifts'])
|
||||
def test_unequal_chord_tones_are_retained_but_never_silently_flattened(self):
|
||||
@@ -249,14 +250,14 @@ class ScoreBundleTests(unittest.TestCase):
|
||||
def test_audit_rejects_relocated_tuplet_brackets(self):
|
||||
modulation = '<time-modification><actual-notes>3</actual-notes><normal-notes>2</normal-notes></time-modification>'
|
||||
source = tests.test_musicxml.parse(tests.test_musicxml.xml_score(''.join(tests.test_musicxml.xml_note(duration=2, kind='quarter', extra=modulation) for _ in range(6)), divisions=3))
|
||||
span = {'id': 'tuplet-1', 'voice': '1', 'start': tests.test_musicxml.notes(source)[0]['id'], 'end': tests.test_musicxml.notes(source)[2]['id'], 'note_count': 3, 'space_count': 2, 'depth': 0, 'bracket': 'auto', 'show_number': 'actual'}
|
||||
span = {'id': 'tuplet_1', 'voice': '1', 'start': tests.test_musicxml.notes(source)[0]['id'], 'end': tests.test_musicxml.notes(source)[2]['id'], 'note_count': 3, 'space_count': 2, 'depth': 0, 'bracket': 'auto', 'show_number': 'actual'}
|
||||
source['staves'][0]['tuplets'] = [span]
|
||||
for note in tests.test_musicxml.notes(source)[:3]:
|
||||
note['tuplet_ids'] = ['tuplet-1']
|
||||
note['tuplet_ids'] = ['tuplet_1']
|
||||
changed = copy.deepcopy(source)
|
||||
changed['staves'][0]['tuplets'][0].update(start=tests.test_musicxml.notes(changed)[3]['id'], end=tests.test_musicxml.notes(changed)[5]['id'])
|
||||
for index, note in enumerate(tests.test_musicxml.notes(changed)):
|
||||
note['tuplet_ids'] = ['tuplet-1'] if index >= 3 else []
|
||||
note['tuplet_ids'] = ['tuplet_1'] if index >= 3 else []
|
||||
with tempfile.TemporaryDirectory() as temporary:
|
||||
before, after = pathlib.Path(temporary) / 'source.xml', pathlib.Path(temporary) / 'output.xml'
|
||||
generator.musicxml_writer.write_musicxml(before, source)
|
||||
@@ -268,7 +269,7 @@ class ScoreBundleTests(unittest.TestCase):
|
||||
root = pathlib.Path(temporary)
|
||||
assets = root / 'assets'
|
||||
assets.mkdir()
|
||||
data = pathlib.Path('tests/fixtures/engraving.png').read_bytes()
|
||||
data = pathlib.Path('tests/fixtures/engraving_python.png').read_bytes()
|
||||
page = assets / 'page.png'
|
||||
page.write_bytes(data)
|
||||
document = generator.musicxml.load_musicxml(pathlib.Path('tests/fixtures/engraving.xml'))
|
||||
@@ -304,7 +305,7 @@ class ScoreBundleTests(unittest.TestCase):
|
||||
with unittest.mock.patch('generator.engraving.validation.check_content', wraps=generator.engraving.validation.check_content) as decode:
|
||||
generator.score.validate_generated_tree(root)
|
||||
decode.assert_called_once()
|
||||
PIL.Image.new('RGB', (976, 484), 'white').save(page)
|
||||
PIL.Image.new('RGB', (976, 484), generator.theme.rgb('background')).save(page)
|
||||
path = root / 'songs/2.json'
|
||||
bundle = json.loads(path.read_text())
|
||||
bundle['presentation']['pages'][0]['sha256'] = hashlib.sha256(page.read_bytes()).hexdigest()
|
||||
@@ -323,7 +324,7 @@ class ScoreBundleTests(unittest.TestCase):
|
||||
self.assertEqual(bundle['music'], document)
|
||||
self.assertEqual(len(bundle['presentation']['pages']), 1)
|
||||
page = root / bundle['presentation']['pages'][0]['path']
|
||||
with PIL.Image.open(page) as actual, PIL.Image.open('tests/fixtures/engraving-python.png') as expected:
|
||||
with PIL.Image.open(page) as actual, PIL.Image.open('tests/fixtures/engraving_python.png') as expected:
|
||||
self.assertIsNone(PIL.ImageChops.difference(actual.convert('RGB'), expected.convert('RGB')).getbbox())
|
||||
if before is not None:
|
||||
self.assertEqual(bundle, before)
|
||||
|
||||
Reference in New Issue
Block a user