def test_success(self, open_file_mock): self.create_score() self.install_fancy_segment_maker() self.create_segment('test_segment') self.illustrate_segments() self.collect_segments() self.create_build_target() script = abjad.cli.ManageBuildTargetScript() command = ['--render', 'letter-portrait'] with abjad.TemporaryDirectoryChange(str(self.score_path)): try: script(command) except SystemExit: raise RuntimeError('SystemExit') command = ['--distribute', 'letter-portrait'] with abjad.RedirectedStreams(stdout=self.string_io): with abjad.TemporaryDirectoryChange(str(self.score_path)): try: script(command) except SystemExit: raise RuntimeError('SystemExit') self.compare_captured_output(r''' Distributing 'letter-portrait' score.pdf --> letter-portrait-score.pdf parts-cello.pdf --> letter-portrait-parts-cello.pdf parts-viola.pdf --> letter-portrait-parts-viola.pdf parts-violin-i.pdf --> letter-portrait-parts-violin-i.pdf parts-violin-ii.pdf --> letter-portrait-parts-violin-ii.pdf ''') self.compare_path_contents( self.distribution_path, self.expected_files, )
def test_list(self): self.create_score() script = abjad.cli.ManageBuildTargetScript() command = ['--new', 'big-version'] with abjad.TemporaryDirectoryChange(str(self.score_path)): try: script(command) except SystemExit: raise RuntimeError('SystemExit') command = ['--new', 'medium-version'] with abjad.TemporaryDirectoryChange(str(self.score_path)): try: script(command) except SystemExit: raise RuntimeError('SystemExit') command = ['--new', 'small-version'] with abjad.TemporaryDirectoryChange(str(self.score_path)): try: script(command) except SystemExit: raise RuntimeError('SystemExit') command = ['--list'] with abjad.RedirectedStreams(stdout=self.string_io): with abjad.TemporaryDirectoryChange(str(self.score_path)): try: script(command) except SystemExit: raise RuntimeError('SystemExit') self.compare_captured_output(r''' Available build targets: big-version medium-version small-version ''')
def test_diff(self): script = abjad.cli.DoctestScript() command = ['--diff', str(self.failing_module_path)] with abjad.TemporaryDirectoryChange(str(self.test_path)): with abjad.RedirectedStreams(stdout=self.string_io): with self.assertRaises(SystemExit) as context_manager: script(command) assert context_manager.exception.code == 1 script_output = self.ansi_escape.sub('', self.string_io.getvalue()) script_output = abjad.String.normalize(script_output) expected = abjad.String.normalize(''' doctest_test/doctest_fail.py FAILED ********************************************************************** File ".../doctest_test/doctest_fail.py", line 7, in doctest_fail.py Failed example: True is False Differences (ndiff with -expected +actual): - True + False ********************************************************************** 1 items had failures: 1 of 1 in doctest_fail.py ***Test Failed*** 1 failures. FAILED: doctest_test/doctest_fail.py 0 passed, 1 failed out of 1 test in 1 module. '''.replace('/', os.path.sep)) self.compare_strings(expected, script_output)
def test_both(self): script = abjad.cli.DoctestScript() command = [str(self.doctest_path)] with abjad.TemporaryDirectoryChange(str(self.test_path)): with abjad.RedirectedStreams(stdout=self.string_io): with self.assertRaises(SystemExit) as context_manager: script(command) assert context_manager.exception.code == 1 script_output = self.ansi_escape.sub('', self.string_io.getvalue()) script_output = abjad.String.normalize(script_output) expected = abjad.String.normalize(''' doctest_test/doctest_fail.py FAILED doctest_test/doctest_pass.py OK ********************************************************************** File ".../doctest_test/doctest_fail.py", line 7, in doctest_fail.py Failed example: True is False Expected: True Got: False ********************************************************************** 1 items had failures: 1 of 1 in doctest_fail.py ***Test Failed*** 1 failures. FAILED: doctest_test/doctest_fail.py 1 passed, 1 failed out of 2 tests in 2 modules. '''.replace('/', os.path.sep)) self.compare_strings(expected, script_output)
def create_segment( self, segment_name='test_segment', force=False, expect_error=False, ): script = abjad.cli.ManageSegmentScript() command = ['--new', segment_name] if force: command.insert(0, '-f') with abjad.TemporaryDirectoryChange(str(self.score_path)): if expect_error: with self.assertRaises(SystemExit) as context_manager: script(command) assert context_manager.exception.code == 1 else: try: script(command) except SystemExit: raise RuntimeError('SystemExit') return self.score_path.joinpath( self.score_path.name, 'segments', segment_name, )
def test_success_front_cover(self, open_file_mock): expected_files = [ 'test_score/test_score/builds/letter-portrait/back-cover.tex', 'test_score/test_score/builds/letter-portrait/front-cover.pdf', 'test_score/test_score/builds/letter-portrait/front-cover.tex', 'test_score/test_score/builds/letter-portrait/music.ly', 'test_score/test_score/builds/letter-portrait/parts.ly', 'test_score/test_score/builds/letter-portrait/preface.tex', 'test_score/test_score/builds/letter-portrait/score.tex', ] if platform.system().lower() == 'windows': expected_files = [ _.replace('/', os.path.sep) for _ in expected_files ] self.create_score() self.create_segment('test_segment') self.illustrate_segments() self.collect_segments() target_path = self.create_build_target() script = abjad.cli.ManageBuildTargetScript() command = [ '--render', 'letter-portrait', '--front-cover', ] #with abjad.RedirectedStreams(stdout=self.string_io): with abjad.TemporaryDirectoryChange(str(self.score_path)): try: script(command) except SystemExit: raise RuntimeError('SystemExit') self.compare_path_contents(target_path, expected_files) assert open_file_mock.called
def test_python_cannot_illustrate(self): """ Handle un-illustrables. """ self.create_score() material_path = self.create_material('test_material') definition_path = material_path.joinpath('definition.py') with open(str(definition_path), 'w') as file_pointer: file_pointer.write( abjad.String.normalize(r''' test_material = None ''')) script = abjad.cli.ManageMaterialScript() command = ['--illustrate', 'test_material'] with abjad.RedirectedStreams(stdout=self.string_io): with abjad.TemporaryDirectoryChange(str(self.score_path)): with self.assertRaises(SystemExit) as context_manager: script(command) assert context_manager.exception.code == 1 self.compare_captured_output(r''' Illustration candidates: 'test_material' ... Illustrating test_score/materials/test_material/ Importing test_score.materials.test_material.definition Cannot illustrate material of type NoneType. '''.replace('/', os.path.sep))
def test_success_one_segment(self, open_file_mock): self.create_score() self.create_segment('test_segment') script = abjad.commandlinetools.ManageSegmentScript() command = ['--illustrate', 'test_segment'] with abjad.RedirectedStreams(stdout=self.string_io): with abjad.TemporaryDirectoryChange(str(self.score_path)): try: script(command) except SystemExit as e: raise RuntimeError('SystemExit: {}'.format(e.code)) self.compare_captured_output(r''' Illustration candidates: 'test_segment' ... Reading test_score/segments/metadata.json ... OK! Illustrating test_score/segments/test_segment/ Reading test_score/segments/metadata.json ... OK! Reading test_score/segments/test_segment/metadata.json ... JSON does not exist. Importing test_score.segments.test_segment.definition Writing test_score/segments/test_segment/metadata.json Abjad runtime: ... second... Writing test_score/segments/test_segment/illustration.ly ... OK! Writing test_score/segments/test_segment/illustration.pdf ... OK! LilyPond runtime: ... second... Illustrated test_score/segments/test_segment/ '''.replace('/', os.path.sep)) self.compare_path_contents(self.segments_path, self.expected_files) illustration_path = self.segments_path.joinpath( 'test_segment', 'illustration.ly') self.compare_lilypond_contents( illustration_path, self.expected_illustration_contents, )
def test_list_segments_unstaged(self): self.create_score() self.create_segment('segment_one') self.create_segment('segment_two') self.create_segment('segment_three') script = abjad.cli.ManageSegmentScript() segment_names = script._read_segments_list_json( self.score_path, verbose=False, ) segment_names.remove('segment_two') script._write_segments_list_json( segment_names, score_path=self.score_path, verbose=False, ) command = ['--list'] with abjad.RedirectedStreams(stdout=self.string_io): with abjad.TemporaryDirectoryChange(str(self.score_path)): with self.assertRaises(SystemExit) as context_manager: script(command) assert context_manager.exception.code == 2 self.compare_captured_output(r''' Available segments: Reading test_score/segments/metadata.json ... OK! segment_one [1] segment_three [2] segment_two '''.replace('/', os.path.sep))
def test_success(self): self.create_score() script = abjad.cli.ManageSegmentScript() try: names = script._read_segments_list_json( self.score_path, verbose=False, ) assert names == [] except SystemExit: raise RuntimeError('SystemExit') command = ['--new', 'test_segment'] with abjad.RedirectedStreams(stdout=self.string_io): with abjad.TemporaryDirectoryChange(str(self.score_path)): try: script(command) except SystemExit: raise RuntimeError('SystemExit') self.compare_captured_output(r''' Creating segment subpackage 'test_segment' ... Reading test_score/metadata.json ... OK! Reading test_score/segments/metadata.json ... JSON does not exist. Writing test_score/segments/metadata.json Created test_score/segments/test_segment/ '''.replace('/', os.path.sep)) assert self.segments_path.joinpath('test_segment').exists() self.compare_path_contents(self.segments_path, self.expected_files) try: names = script._read_segments_list_json( self.score_path, verbose=False, ) assert names == ['test_segment'] except SystemExit: raise RuntimeError('SystemExit')
def test_success_one_material(self, open_file_mock): self.create_score() self.create_material('test_material') script = abjad.cli.ManageMaterialScript() command = ['--illustrate', 'test_material'] with abjad.RedirectedStreams(stdout=self.string_io): with abjad.TemporaryDirectoryChange(str(self.score_path)): try: script(command) except SystemExit as e: raise RuntimeError('SystemExit: {}'.format(e.code)) self.compare_captured_output(r''' Illustration candidates: 'test_material' ... Illustrating test_score/materials/test_material/ Importing test_score.materials.test_material.definition Abjad runtime: ... second... Writing test_score/materials/test_material/illustration.ly ... OK! Writing test_score/materials/test_material/illustration.pdf ... OK! LilyPond runtime: ... second... Illustrated test_score/materials/test_material/ '''.replace('/', os.path.sep)) self.compare_path_contents(self.materials_path, self.expected_files) illustration_path = self.materials_path.joinpath( 'test_material', 'illustration.ly') self.compare_lilypond_contents( illustration_path, self.expected_illustration_contents, )
def test_python_error_on_illustrate(self): """ Handle exceptions inside the Python module on __call__(). """ self.create_score() material_path = self.create_material('test_material') definition_path = material_path.joinpath('definition.py') with open(str(definition_path), 'w') as file_pointer: file_pointer.write( abjad.String.normalize(r''' from abjad.tools import abctools class Foo(object): def __illustrate__(self): raise TypeError('This is fake.') test_material = Foo() ''')) script = abjad.cli.ManageMaterialScript() command = ['--illustrate', 'test_material'] with abjad.RedirectedStreams(stdout=self.string_io): with abjad.TemporaryDirectoryChange(str(self.score_path)): with self.assertRaises(SystemExit) as context_manager: script(command) assert context_manager.exception.code == 1 self.compare_captured_output(r''' Illustration candidates: 'test_material' ... Illustrating test_score/materials/test_material/ Importing test_score.materials.test_material.definition '''.replace('/', os.path.sep))
def illustrate_segment(self, segment_name): script = abjad.cli.ManageSegmentScript() command = ['--illustrate', segment_name] with abjad.TemporaryDirectoryChange(str(self.score_path)): try: script(command) except SystemExit as e: raise RuntimeError('SystemExit: {}'.format(e.code))
def test_success(self, call_subprocess_mock): call_subprocess_mock.return_value = 0 self.create_score() self.create_segment('segment_a') self.create_segment('segment_b') self.create_segment('segment_c') script = abjad.cli.ManageSegmentScript() command = ['--stage'] with abjad.RedirectedStreams(stdout=self.string_io): with abjad.TemporaryDirectoryChange(str(self.score_path)): try: script(command) except SystemExit as e: raise RuntimeError('SystemExit: {}'.format(e.code)) self.compare_captured_output(r''' Staging segments: Reading test_score/segments/metadata.json ... OK! Staged: segment_a segment_b segment_c '''.replace('/', os.path.sep)) call_subprocess_mock.assert_called_with( '{} segments.txt'.format(abjad_configuration.get_text_editor()), ) call_subprocess_mock.side_effect = self.side_effect self.reset_string_io() with abjad.RedirectedStreams(stdout=self.string_io): with abjad.TemporaryDirectoryChange(str(self.score_path)): try: script(command) except SystemExit as e: raise RuntimeError('SystemExit: {}'.format(e.code)) self.compare_captured_output(r''' Staging segments: Reading test_score/segments/metadata.json ... OK! Writing test_score/segments/metadata.json Staged: segment_c segment_b segment_a '''.replace('/', os.path.sep)) call_subprocess_mock.assert_called_with( '{} segments.txt'.format(abjad_configuration.get_text_editor()), )
def test_success_filtered_segments(self, open_file_mock): self.create_score() self.create_segment('segment_one') self.create_segment('segment_two') self.create_segment('segment_three') script = abjad.commandlinetools.ManageSegmentScript() command = ['--illustrate', 'segment_t*'] with abjad.RedirectedStreams(stdout=self.string_io): with abjad.TemporaryDirectoryChange(str(self.score_path)): try: script(command) except SystemExit as e: raise RuntimeError('SystemExit: {}'.format(e.code)) self.compare_captured_output(r''' Illustration candidates: 'segment_t*' ... Reading test_score/segments/metadata.json ... OK! Illustrating test_score/segments/segment_two/ Reading test_score/segments/metadata.json ... OK! Reading test_score/segments/segment_one/metadata.json ... JSON does not exist. Reading test_score/segments/segment_two/metadata.json ... JSON does not exist. Importing test_score.segments.segment_two.definition Writing test_score/segments/segment_two/metadata.json Abjad runtime: ... second... Writing test_score/segments/segment_two/illustration.ly ... OK! Writing test_score/segments/segment_two/illustration.pdf ... OK! LilyPond runtime: ... second... Illustrated test_score/segments/segment_two/ Illustrating test_score/segments/segment_three/ Reading test_score/segments/metadata.json ... OK! Reading test_score/segments/segment_two/metadata.json ... OK! Reading test_score/segments/segment_three/metadata.json ... JSON does not exist. Importing test_score.segments.segment_three.definition Writing test_score/segments/segment_three/metadata.json Abjad runtime: ... second... Writing test_score/segments/segment_three/illustration.ly ... OK! Writing test_score/segments/segment_three/illustration.pdf ... OK! LilyPond runtime: ... second... Illustrated test_score/segments/segment_three/ '''.replace('/', os.path.sep)) assert not self.segments_path.joinpath( 'segment_one', 'illustration.pdf', ).exists() assert self.segments_path.joinpath( 'segment_two', 'illustration.pdf', ).exists() assert self.segments_path.joinpath( 'segment_three', 'illustration.pdf', ).exists()
def test_list_segments_no_segments(self): self.create_score() script = abjad.cli.ManageSegmentScript() command = ['--list'] with abjad.RedirectedStreams(stdout=self.string_io): with abjad.TemporaryDirectoryChange(str(self.score_path)): with self.assertRaises(SystemExit) as context_manager: script(command) assert context_manager.exception.code == 2 self.compare_captured_output(r''' Available segments: Reading test_score/segments/metadata.json ... JSON does not exist. No segments available. '''.replace('/', os.path.sep))
def test_success_all_materials(self, open_file_mock): self.create_score() self.create_material('material_one') self.create_material('material_two') self.create_material('material_three') script = abjad.cli.ManageMaterialScript() command = ['--illustrate', '*'] with abjad.RedirectedStreams(stdout=self.string_io): with abjad.TemporaryDirectoryChange(str(self.score_path)): try: script(command) except SystemExit as e: raise RuntimeError('SystemExit: {}'.format(e.code)) self.compare_captured_output(r''' Illustration candidates: '*' ... Illustrating test_score/materials/material_one/ Importing test_score.materials.material_one.definition Abjad runtime: ... second... Writing test_score/materials/material_one/illustration.ly ... OK! Writing test_score/materials/material_one/illustration.pdf ... OK! LilyPond runtime: ... second... Illustrated test_score/materials/material_one/ Illustrating test_score/materials/material_three/ Importing test_score.materials.material_three.definition Abjad runtime: ... second... Writing test_score/materials/material_three/illustration.ly ... OK! Writing test_score/materials/material_three/illustration.pdf ... OK! LilyPond runtime: ... second... Illustrated test_score/materials/material_three/ Illustrating test_score/materials/material_two/ Importing test_score.materials.material_two.definition Abjad runtime: ... second... Writing test_score/materials/material_two/illustration.ly ... OK! Writing test_score/materials/material_two/illustration.pdf ... OK! LilyPond runtime: ... second... Illustrated test_score/materials/material_two/ '''.replace('/', os.path.sep)) assert self.materials_path.joinpath( 'material_one', 'illustration.pdf', ).exists() assert self.materials_path.joinpath( 'material_two', 'illustration.pdf', ).exists() assert self.materials_path.joinpath( 'material_three', 'illustration.pdf', ).exists()
def test_lilypond_error(self): """ Handle failing LilyPond rendering. """ self.create_score() material_path = self.create_material('test_material') definition_path = material_path.joinpath('definition.py') with open(str(definition_path), 'w') as file_pointer: file_pointer.write( abjad.String.normalize(r''' from abjad.tools import lilypondfiletools test_material = lilypondfiletools.LilyPondFile.new() test_material.items.append(r'\this-does-not-exist') ''')) script = abjad.cli.ManageMaterialScript() command = ['--illustrate', 'test_material'] with abjad.RedirectedStreams(stdout=self.string_io): with abjad.TemporaryDirectoryChange(str(self.score_path)): with self.assertRaises(SystemExit) as context_manager: script(command) assert context_manager.exception.code == 1 self.compare_captured_output(r''' Illustration candidates: 'test_material' ... Illustrating test_score/materials/test_material/ Importing test_score.materials.test_material.definition Abjad runtime: ... second... Writing test_score/materials/test_material/illustration.ly ... OK! Writing test_score/materials/test_material/illustration.pdf ... Failed! '''.replace('/', os.path.sep)) illustration_ly_path = material_path.joinpath('illustration.ly') assert illustration_ly_path.exists() self.compare_lilypond_contents( illustration_ly_path, abjad.String.normalize(r''' \language "english" \header { tagline = ##f } \layout {} \paper {} \this-does-not-exist '''))
def test_pass(self): script = abjad.cli.DoctestScript() command = [str(self.passing_module_path)] with abjad.TemporaryDirectoryChange(str(self.test_path)): with abjad.RedirectedStreams(stdout=self.string_io): with self.assertRaises(SystemExit) as context_manager: script(command) assert context_manager.exception.code == 0 script_output = self.ansi_escape.sub('', self.string_io.getvalue()) script_output = abjad.String.normalize(script_output) expected = abjad.String.normalize(''' doctest_test/doctest_pass.py OK 1 passed, 0 failed out of 1 test in 1 module. '''.replace('/', os.path.sep)) self.compare_strings(expected, script_output)
def test_success(self): self.create_score() script = abjad.cli.ManageMaterialScript() command = ['--new', 'test_material'] with abjad.RedirectedStreams(stdout=self.string_io): with abjad.TemporaryDirectoryChange(str(self.score_path)): try: script(command) except SystemExit: raise RuntimeError('SystemExit') self.compare_captured_output(r''' Creating material subpackage 'test_material' ... Reading test_score/metadata.json ... OK! Created test_score/materials/test_material/ '''.replace('/', os.path.sep)) assert self.materials_path.joinpath('test_material').exists() self.compare_path_contents(self.materials_path, self.expected_files)
def test_exists(self): self.create_score() script = abjad.cli.ManageBuildTargetScript() command = ['--new'] with abjad.TemporaryDirectoryChange(str(self.score_path)): try: script(command) except SystemExit: raise RuntimeError('SystemExit') with abjad.RedirectedStreams(stdout=self.string_io): with self.assertRaises(SystemExit) as context_manager: script(command) assert context_manager.exception.code == 1 self.compare_captured_output(r''' Creating build target 'letter-portrait' (8.5in x 11.0in) Path exists: test_score/builds/letter-portrait '''.replace('/', os.path.sep))
def test_internal_path(self): self.create_score() script = abjad.cli.ManageBuildTargetScript() command = ['--new'] internal_path = self.score_path.joinpath('test_score', 'builds') assert internal_path.exists() with abjad.RedirectedStreams(stdout=self.string_io): with abjad.TemporaryDirectoryChange(str(internal_path)): try: script(command) except SystemExit: raise RuntimeError('SystemExit') self.compare_captured_output(r''' Creating build target 'letter-portrait' (8.5in x 11.0in) Reading test_score/metadata.json ... OK! Created test_score/builds/letter-portrait '''.replace('/', os.path.sep))
def test_internal_path(self): self.create_score() script = abjad.cli.ManageSegmentScript() command = ['--new', 'test_segment'] internal_path = self.score_path.joinpath('test_score', 'builds') assert internal_path.exists() with abjad.RedirectedStreams(stdout=self.string_io): with abjad.TemporaryDirectoryChange(str(internal_path)): try: script(command) except SystemExit: raise RuntimeError('SystemExit') self.compare_captured_output(r''' Creating segment subpackage 'test_segment' ... Reading test_score/metadata.json ... OK! Reading test_score/segments/metadata.json ... JSON does not exist. Writing test_score/segments/metadata.json Created test_score/segments/test_segment/ '''.replace('/', os.path.sep))
def create_build_target( self, force=False, expect_error=False, ): script = abjad.cli.ManageBuildTargetScript() command = ['--new'] if force: command.insert(0, '-f') with abjad.TemporaryDirectoryChange(str(self.score_path)): if expect_error: with self.assertRaises(SystemExit) as context_manager: script(command) assert context_manager.exception.code == 1 else: try: script(command) except SystemExit: raise RuntimeError('SystemExit') return self.build_path.joinpath('letter-portrait')
def test_missing_definition(self): """ Handle missing definition. """ self.create_score() material_path = self.create_material('test_material') definition_path = material_path.joinpath('definition.py') definition_path.unlink() script = abjad.cli.ManageMaterialScript() command = ['--illustrate', 'test_material'] with abjad.RedirectedStreams(stdout=self.string_io): with abjad.TemporaryDirectoryChange(str(self.score_path)): with self.assertRaises(SystemExit) as context_manager: script(command) assert context_manager.exception.code == 1 self.compare_captured_output(r''' Illustration candidates: 'test_material' ... Illustrating test_score/materials/test_material/ Importing test_score.materials.test_material.definition '''.replace('/', os.path.sep))
def test_success(self, call_subprocess_mock): call_subprocess_mock.return_value = 0 self.create_score() material_path = self.create_material('test_material') script = abjad.cli.ManageMaterialScript() command = ['--edit', 'test_material'] with abjad.RedirectedStreams(stdout=self.string_io): with abjad.TemporaryDirectoryChange(str(self.score_path)): try: script(command) except SystemExit as e: raise RuntimeError('SystemExit: {}'.format(e.code)) self.compare_captured_output(r''' Edit candidates: 'test_material' ... ''') definition_path = material_path.joinpath('definition.py') command = '{} {!s}'.format( abjad_configuration.get_text_editor(), definition_path, ) call_subprocess_mock.assert_called_with(command)
def test_python_error_on_import(self): """ Handle exceptions inside the Python module on import. """ self.create_score() material_path = self.create_material('test_material') definition_path = material_path.joinpath('definition.py') with open(str(definition_path), 'a') as file_pointer: file_pointer.write('\n\nfailure = 1 / 0\n') script = abjad.cli.ManageMaterialScript() command = ['--illustrate', 'test_material'] with abjad.RedirectedStreams(stdout=self.string_io): with abjad.TemporaryDirectoryChange(str(self.score_path)): with self.assertRaises(SystemExit) as context_manager: script(command) assert context_manager.exception.code == 1 self.compare_captured_output(r''' Illustration candidates: 'test_material' ... Illustrating test_score/materials/test_material/ Importing test_score.materials.test_material.definition '''.replace('/', os.path.sep))
def test_success(self, call_subprocess_mock): call_subprocess_mock.return_value = 0 self.create_score() segment_path = self.create_segment('test_segment') script = abjad.cli.ManageSegmentScript() command = ['--edit', 'test_segment'] with abjad.RedirectedStreams(stdout=self.string_io): with abjad.TemporaryDirectoryChange(str(self.score_path)): try: script(command) except SystemExit as e: raise RuntimeError('SystemExit: {}'.format(e.code)) self.compare_captured_output(r''' Edit candidates: 'test_segment' ... Reading test_score/segments/metadata.json ... OK! '''.replace('/', os.path.sep)) definition_path = segment_path.joinpath('definition.py') command = '{} {!s}'.format( abjad_configuration.get_text_editor(), definition_path, ) call_subprocess_mock.assert_called_with(command)
def test_named(self): self.create_score() script = abjad.cli.ManageBuildTargetScript() command = [ '--new', 'World Premiere Version', '--paper-size', 'a3', '--orientation', 'landscape', ] with abjad.RedirectedStreams(stdout=self.string_io): with abjad.TemporaryDirectoryChange(str(self.score_path)): try: script(command) except SystemExit: raise RuntimeError('SystemExit') self.compare_captured_output(r''' Creating build target 'world-premiere-version' (297mm x 420mm) Reading test_score/metadata.json ... OK! Created test_score/builds/world-premiere-version '''.replace('/', os.path.sep))
def test_python_error_on_illustrate(self): """ Handle exceptions inside the Python module on __call__(). """ self.create_score() segment_path = self.create_segment('test_segment') definition_path = segment_path.joinpath('definition.py') with open(str(definition_path), 'w') as file_pointer: file_pointer.write( abjad.String.normalize(r''' from abjad.tools import abctools class FaultySegmentMaker(abctools.AbjadObject): def __call__( self, metadata=None, previous_metadata=None, ): raise TypeError('This is intentionally broken.') segment_maker = FaultySegmentMaker() ''')) script = abjad.commandlinetools.ManageSegmentScript() command = ['--illustrate', 'test_segment'] with abjad.RedirectedStreams(stdout=self.string_io): with abjad.TemporaryDirectoryChange(str(self.score_path)): with self.assertRaises(SystemExit) as context_manager: script(command) assert context_manager.exception.code == 1 self.compare_captured_output(r''' Illustration candidates: 'test_segment' ... Reading test_score/segments/metadata.json ... OK! Illustrating test_score/segments/test_segment/ Reading test_score/segments/metadata.json ... OK! Reading test_score/segments/test_segment/metadata.json ... JSON does not exist. Importing test_score.segments.test_segment.definition '''.replace('/', os.path.sep))