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(
                stringtools.normalize(r'''
            # -*- coding: utf-8 -*-

            test_material = None
            '''))
        script = commandlinetools.ManageMaterialScript()
        command = ['--illustrate', 'test_material']
        with systemtools.RedirectedStreams(stdout=self.string_io):
            with systemtools.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_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(
                stringtools.normalize(r'''
            # -*- coding: utf-8 -*-
            from abjad.tools import abctools


            class Foo(object):
                def __illustrate__(self):
                    raise TypeError('This is fake.')

            test_material = Foo()
            '''))
        script = commandlinetools.ManageMaterialScript()
        command = ['--illustrate', 'test_material']
        with systemtools.RedirectedStreams(stdout=self.string_io):
            with systemtools.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_list_segments_unstaged(self):
     self.create_score()
     self.create_segment('segment_one')
     self.create_segment('segment_two')
     self.create_segment('segment_three')
     script = commandlinetools.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 systemtools.RedirectedStreams(stdout=self.string_io):
         with systemtools.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, 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 = commandlinetools.ManageBuildTargetScript()
     command = ['--render', 'letter-portrait']
     with systemtools.TemporaryDirectoryChange(str(self.score_path)):
         try:
             script(command)
         except SystemExit:
             raise RuntimeError('SystemExit')
     command = ['--distribute', 'letter-portrait']
     with systemtools.RedirectedStreams(stdout=self.string_io):
         with systemtools.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,
     )
Beispiel #5
0
 def test_list(self):
     self.create_score()
     script = commandlinetools.ManageBuildTargetScript()
     command = ['--new', 'big-version']
     with systemtools.TemporaryDirectoryChange(str(self.score_path)):
         try:
             script(command)
         except SystemExit:
             raise RuntimeError('SystemExit')
     command = ['--new', 'medium-version']
     with systemtools.TemporaryDirectoryChange(str(self.score_path)):
         try:
             script(command)
         except SystemExit:
             raise RuntimeError('SystemExit')
     command = ['--new', 'small-version']
     with systemtools.TemporaryDirectoryChange(str(self.score_path)):
         try:
             script(command)
         except SystemExit:
             raise RuntimeError('SystemExit')
     command = ['--list']
     with systemtools.RedirectedStreams(stdout=self.string_io):
         with systemtools.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_explicit(self):
        self.create_score()
        script = commandlinetools.ManageBuildTargetScript()
        command = [
            '--new',
            '--paper-size', 'a3',
            '--orientation', 'landscape',
            ]
        with systemtools.RedirectedStreams(stdout=self.string_io):
            with systemtools.TemporaryDirectoryChange(str(self.score_path)):
                try:
                    script(command)
                except SystemExit:
                    raise RuntimeError('SystemExit')
        self.compare_captured_output(r'''
        Creating build target 'a3-landscape' (297mm x 420mm)
            Reading test_score/metadata.json ... OK!
            Created test_score/build/a3-landscape
        '''.replace('/', os.path.sep))
        path = self.build_path.joinpath('a3-landscape', 'score.tex')
        self.compare_lilypond_contents(path, r'''
            \documentclass{article}
            \usepackage[papersize={420mm, 297mm}]{geometry}
            \usepackage{pdfpages}
            \begin{document}

            \includepdf[pages=-]{front-cover.pdf}
            \includepdf[pages=-]{preface.pdf}
            \includepdf[angle=-90,pages=-]{music.pdf}
            \includepdf[pages=-]{back-cover.pdf}

            \end{document}
        ''')
Beispiel #7
0
    def test_diff(self):
        script = commandlinetools.DoctestScript()
        command = ['--diff', str(self.failing_module_path)]
        with systemtools.TemporaryDirectoryChange(str(self.test_path)):
            with systemtools.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 = stringtools.normalize(script_output)
        expected = stringtools.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_success(self):
     self.create_score()
     script = commandlinetools.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 systemtools.RedirectedStreams(stdout=self.string_io):
         with systemtools.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')
Beispiel #9
0
    def test_both(self):
        script = commandlinetools.DoctestScript()
        command = [str(self.doctest_path)]
        with systemtools.TemporaryDirectoryChange(str(self.test_path)):
            with systemtools.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 = stringtools.normalize(script_output)
        expected = stringtools.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)
Beispiel #10
0
 def test_success(self):
     with systemtools.RedirectedStreams(stdout=self.string_io):
         self.create_score()
     assert self.score_path.exists()
     self.compare_path_contents(self.score_path, self.expected_files)
     score_metadata_path = self.score_path.joinpath(
         self.score_path.name, 'metadata.json')
     assert score_metadata_path.exists()
     with open(str(score_metadata_path), 'r') as file_pointer:
         metadata = json.loads(file_pointer.read())
     assert metadata == {
         'composer_email': '*****@*****.**',
         'composer_github': 'josiah-wolf-oberholtzer',
         'composer_library': 'consort',
         'composer_name': 'Josiah Wolf Oberholtzer',
         'composer_website': 'www.josiahwolfoberholtzer.com',
         'title': 'Test Score',
         'year': 2016,
         }
     shutil.rmtree(str(self.score_path))
     for path in self.test_path.iterdir():
         assert path in self.directory_items
     self.compare_captured_output(r'''
         Creating score package 'Test Score'...
             Writing test_score/metadata.json
             Created test_score/
     '''.replace('/', os.path.sep))
Beispiel #11
0
 def test_success_one_segment(self, open_file_mock):
     self.create_score()
     self.create_segment('test_segment')
     script = commandlinetools.ManageSegmentScript()
     command = ['--illustrate', 'test_segment']
     with systemtools.RedirectedStreams(stdout=self.string_io):
         with systemtools.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,
     )
Beispiel #12
0
def process_literal_block_pairs(literal_block_pairs):
    environment = {
        '__builtins__': __builtins__,
        'print_function': print_function,
        }
    exec('from abjad import *\n', environment)
    try:
        experimental = importlib.import_module('experimental')
        environment.update(experimental.__dict__)
    except ImportError:
        pass
    string_io = StringIO()
    with systemtools.RedirectedStreams(stdout=string_io):
        for literal_block, all_lines in literal_block_pairs:
            original_lines = literal_block[0].splitlines()
            replacement_blocks = []
            lines_to_execute = []
            previous_line_number = 0
            for i, line in all_lines:
                lines_to_execute.append(line)
                if line.startswith('__abjad_book__ ='):
                    if '__abjad_book__' in environment:
                        del(environment['__abjad_book__'])
                    try:
                        exec('\n'.join(lines_to_execute), environment)
                    except Exception as e:
                        traceback.print_exc()
                    kind, obj = environment['__abjad_book__']
                    new_abjad_book_block = abjad_book_block()
                    new_abjad_book_block['kind'] = kind
                    if kind == 'lilypond':
                        lilypond_file = documentationtools.make_reference_manual_lilypond_file(obj)
                        new_abjad_book_block['code'] = format(lilypond_file)
                        new_abjad_book_block['raw_code'] = format(obj)
                    elif kind == 'graphviz':
                        graphviz_graph = documentationtools.make_reference_manual_graphviz_graph(obj)
                        new_abjad_book_block['code'] = graphviz_graph.graphviz_format
                    text = '\n'.join(original_lines[previous_line_number:i + 1])
                    new_literal_block = literal_block.deepcopy()
                    new_literal_block.rawsource = text
                    new_literal_block[0].rawsource = text
                    new_literal_block[0].text = text
                    replacement_blocks.extend([new_literal_block, new_abjad_book_block])
                    lines_to_execute = []
                    previous_line_number = i + 1
            if lines_to_execute:
                try:
                    exec('\n'.join(lines_to_execute), environment)
                except:
                    pass
                if replacement_blocks:
                    text = '\n'.join(original_lines[previous_line_number:])
                    new_literal_block = literal_block.deepcopy()
                    new_literal_block.rawsource = text
                    new_literal_block[0].rawsource = text
                    new_literal_block[0].text = text
                    replacement_blocks.append(new_literal_block)
            if replacement_blocks:
                literal_block.replace_self(replacement_blocks)
Beispiel #13
0
 def test_exists(self):
     with systemtools.RedirectedStreams(stdout=self.string_io):
         self.create_score()
     assert self.score_path.exists()
     with systemtools.RedirectedStreams(stdout=self.string_io):
         self.create_score(expect_error=True)
     assert self.score_path.exists()
     shutil.rmtree(str(self.score_path))
     for path in self.test_path.iterdir():
         assert path in self.directory_items
     self.compare_captured_output(r'''
         Creating score package 'Test Score'...
             Writing test_score/metadata.json
             Created test_score/
         Creating score package 'Test Score'...
             Directory test_score already exists.
     '''.replace('/', os.path.sep))
 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 = commandlinetools.ManageSegmentScript()
     command = ['--stage']
     with systemtools.RedirectedStreams(stdout=self.string_io):
         with systemtools.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 systemtools.RedirectedStreams(stdout=self.string_io):
         with systemtools.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()),
         )
Beispiel #15
0
 def test_exists(self):
     self.create_score()
     self.create_material('test_material')
     with systemtools.RedirectedStreams(stdout=self.string_io):
         self.create_material('test_material', expect_error=True)
     self.compare_captured_output(r'''
         Creating material subpackage 'test_material' ...
             Path exists: test_score/materials/test_material
     '''.replace('/', os.path.sep))
Beispiel #16
0
 def test_force_replace(self):
     self.create_score()
     self.create_material('test_material')
     with systemtools.RedirectedStreams(stdout=self.string_io):
         self.create_material('test_material', force=True)
     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))
Beispiel #17
0
 def test_list_materials_no_materials(self):
     self.create_score()
     script = commandlinetools.ManageMaterialScript()
     command = ['--list']
     with systemtools.RedirectedStreams(stdout=self.string_io):
         with systemtools.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 materials:
         No materials available.
     ''')
Beispiel #18
0
 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 = commandlinetools.ManageSegmentScript()
     command = ['--illustrate', 'segment_t*']
     with systemtools.RedirectedStreams(stdout=self.string_io):
         with systemtools.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 = commandlinetools.ManageSegmentScript()
     command = ['--list']
     with systemtools.RedirectedStreams(stdout=self.string_io):
         with systemtools.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 = commandlinetools.ManageMaterialScript()
     command = ['--illustrate', '*']
     with systemtools.RedirectedStreams(stdout=self.string_io):
         with systemtools.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()
Beispiel #21
0
    def test_pass(self):
        script = commandlinetools.DoctestScript()
        command = [str(self.passing_module_path)]
        with systemtools.TemporaryDirectoryChange(str(self.test_path)):
            with systemtools.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 = stringtools.normalize(script_output)
        expected = stringtools.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_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(
                stringtools.normalize(r'''
            # -*- coding: utf-8 -*-
            from abjad.tools import lilypondfiletools


            test_material = lilypondfiletools.make_basic_lilypond_file()
            test_material.items.append(r'\this-does-not-exist')
            '''))
        script = commandlinetools.ManageMaterialScript()
        command = ['--illustrate', 'test_material']
        with systemtools.RedirectedStreams(stdout=self.string_io):
            with systemtools.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,
            stringtools.normalize(r'''
            \language "english"

            \header {}

            \layout {}

            \paper {}

            \this-does-not-exist
            '''))
 def test_exists(self):
     self.create_score()
     script = commandlinetools.ManageBuildTargetScript()
     command = ['--new']
     with systemtools.TemporaryDirectoryChange(str(self.score_path)):
         try:
             script(command)
         except SystemExit:
             raise RuntimeError('SystemExit')
         with systemtools.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/build/letter-portrait
     '''.replace('/', os.path.sep))
 def test_internal_path(self):
     self.create_score()
     script = commandlinetools.ManageBuildTargetScript()
     command = ['--new']
     internal_path = self.score_path.joinpath('test_score', 'build')
     assert internal_path.exists()
     with systemtools.RedirectedStreams(stdout=self.string_io):
         with systemtools.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/build/letter-portrait
     '''.replace('/', os.path.sep))
Beispiel #25
0
 def test_success(self):
     self.create_score()
     script = commandlinetools.ManageMaterialScript()
     command = ['--new', 'test_material']
     with systemtools.RedirectedStreams(stdout=self.string_io):
         with systemtools.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_internal_path(self):
     self.create_score()
     script = commandlinetools.ManageSegmentScript()
     command = ['--new', 'test_segment']
     internal_path = self.score_path.joinpath('test_score', 'build')
     assert internal_path.exists()
     with systemtools.RedirectedStreams(stdout=self.string_io):
         with systemtools.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 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 = commandlinetools.ManageMaterialScript()
     command = ['--illustrate', 'test_material']
     with systemtools.RedirectedStreams(stdout=self.string_io):
         with systemtools.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_named(self):
     self.create_score()
     script = commandlinetools.ManageBuildTargetScript()
     command = [
         '--new',
         'World Premiere Version',
         '--paper-size', 'a3',
         '--orientation', 'landscape',
         ]
     with systemtools.RedirectedStreams(stdout=self.string_io):
         with systemtools.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/build/world-premiere-version
     '''.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 = commandlinetools.ManageMaterialScript()
     command = ['--edit', 'test_material']
     with systemtools.RedirectedStreams(stdout=self.string_io):
         with systemtools.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 = commandlinetools.ManageMaterialScript()
     command = ['--illustrate', 'test_material']
     with systemtools.RedirectedStreams(stdout=self.string_io):
         with systemtools.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))