def test_01(self):
        source = r'''
        ..  abjad::
            :hide:
            :no-stylesheet:

            show(Staff("c'4 d'4 e'4 f'4"))
        '''
        source = systemtools.TestManager.clean_string(source)
        handler = abjadbooktools.SphinxDocumentHandler()
        document = handler.parse_rst(source)
        handler.on_doctree_read(self.app, document)
        node = document[0]
        try:
            abjadbooktools.SphinxDocumentHandler.visit_abjad_output_block_html(
                self.app, node)
        except docutils.nodes.SkipNode:
            pass
        handler.on_build_finished(self.app, None)
        actual = '\n'.join(self.app.body)
        expected = systemtools.TestManager.clean_string(r'''
            <div class="abjad-book-image">
                <a href="../_images/abjadbook/lilypond-0088e89b7def5c05b2a96e22136edef1cd638d75.ly">
                    <img src="../_images/abjadbook/lilypond-0088e89b7def5c05b2a96e22136edef1cd638d75.png" alt="View source." title="View source." />
                </a>
            </div>
            ''')
        self.assertEqual(actual, expected)
        assert len(os.listdir(self.abjadbook_images_directory)) == 2
        for name in (
            'lilypond-0088e89b7def5c05b2a96e22136edef1cd638d75.ly',
            'lilypond-0088e89b7def5c05b2a96e22136edef1cd638d75.png',
            ):
            path = os.path.join(self.images_directory, 'abjadbook', name)
            assert os.path.exists(path)
    def test_on_doctree_read_01(self):
        handler = abjadbooktools.SphinxDocumentHandler()
        document = handler.parse_rst(self.source_one)
        handler.on_doctree_read(self.app, document)
        actual = stringtools.normalize(document.pformat())
        target = stringtools.normalize(r"""
            <document source="test">
                <literal_block xml:space="preserve">
                    >>> string = 'Hello, world!'
                <literal_block xml:space="preserve">
                    def example_function(expr):
                        r'''This is a multiline docstring.

                        This is the third line of the docstring.
                        '''
                        # This is a comment.
                        print('Entering example function.')
                        try:
                            expr = expr + 1
                        except TypeError:
                            print('Wrong type!')
                        print(expr)
                        print('Leaving example function.')
                <literal_block xml:space="preserve">
                    >>> print(string)
                    Hello, world!
                <literal_block xml:space="preserve">
                    >>> example_function(23)
                    Entering example function.
                    24
                    Leaving example function.
            """)
        assert actual == target
Esempio n. 3
0
    def test_02(self):
        source = r'''
        ..  abjad::
            :hide:
            :no-stylesheet:
            :no-trim:

            show(Staff("c'4 d'4 e'4 f'4"))
        '''
        source = stringtools.normalize(source)
        handler = abjadbooktools.SphinxDocumentHandler()
        document = handler.parse_rst(source)
        handler.on_doctree_read(self.app, document)
        node = document[0]
        try:
            abjadbooktools.SphinxDocumentHandler.visit_abjad_output_block_html(
                self.app, node)
        except docutils.nodes.SkipNode:
            pass
        handler.on_build_finished(self.app, None)
        actual = '\n'.join(self.app.body)
        expected = stringtools.normalize(r'''
            <a href="../_images/abjadbook/lilypond-32d88a2354ecb601e788a6d43e67625f59dc61d1.ly" title="" class="abjadbook">
                <img src="../_images/abjadbook/lilypond-32d88a2354ecb601e788a6d43e67625f59dc61d1.png" alt=""/>
            </a>
            ''')
        self.assertEqual(actual, expected)
        assert len(os.listdir(self.abjadbook_images_directory)) == 2
        for name in (
                'lilypond-32d88a2354ecb601e788a6d43e67625f59dc61d1.ly',
                'lilypond-32d88a2354ecb601e788a6d43e67625f59dc61d1.png',
        ):
            path = os.path.join(self.images_directory, 'abjadbook', name)
            assert os.path.exists(path)
    def test_10(self):
        source = r'''
        ..  abjad::
            :hide:
            :no-resize:
            :no-stylesheet:
            :with-thumbnail:

            staff = Staff("c'1 d'1 e'1 f'1 g'1")
            for note in staff[:-1]:
                attach(indicatortools.PageBreak(), note)

            show(staff)
        '''
        source = systemtools.TestManager.clean_string(source)
        handler = abjadbooktools.SphinxDocumentHandler()
        document = handler.parse_rst(source)
        handler.on_doctree_read(self.app, document)
        node = document[0]
        try:
            abjadbooktools.SphinxDocumentHandler.visit_abjad_output_block_html(
                self.app, node)
        except docutils.nodes.SkipNode:
            pass
        handler.on_build_finished(self.app, None)
        actual = '\n'.join(self.app.body)
        expected = systemtools.TestManager.clean_string(r'''
            <a data-lightbox="group-lilypond-224663e00b24b652df759bda64c86bca48933457.ly" href="../_images/abjadbook/lilypond-224663e00b24b652df759bda64c86bca48933457-page1.png" class="">
                <img src="../_images/abjadbook/lilypond-224663e00b24b652df759bda64c86bca48933457-page1-thumbnail.png"/>
            </a>
            <a data-lightbox="group-lilypond-224663e00b24b652df759bda64c86bca48933457.ly" href="../_images/abjadbook/lilypond-224663e00b24b652df759bda64c86bca48933457-page2.png" class="">
                <img src="../_images/abjadbook/lilypond-224663e00b24b652df759bda64c86bca48933457-page2-thumbnail.png"/>
            </a>
            <a data-lightbox="group-lilypond-224663e00b24b652df759bda64c86bca48933457.ly" href="../_images/abjadbook/lilypond-224663e00b24b652df759bda64c86bca48933457-page3.png" class="">
                <img src="../_images/abjadbook/lilypond-224663e00b24b652df759bda64c86bca48933457-page3-thumbnail.png"/>
            </a>
            <a data-lightbox="group-lilypond-224663e00b24b652df759bda64c86bca48933457.ly" href="../_images/abjadbook/lilypond-224663e00b24b652df759bda64c86bca48933457-page4.png" class="">
                <img src="../_images/abjadbook/lilypond-224663e00b24b652df759bda64c86bca48933457-page4-thumbnail.png"/>
            </a>
            <a data-lightbox="group-lilypond-224663e00b24b652df759bda64c86bca48933457.ly" href="../_images/abjadbook/lilypond-224663e00b24b652df759bda64c86bca48933457-page5.png" class="">
                <img src="../_images/abjadbook/lilypond-224663e00b24b652df759bda64c86bca48933457-page5-thumbnail.png"/>
            </a>
            ''')
        self.assertEqual(actual, expected)
        assert len(os.listdir(self.abjadbook_images_directory)) == 11
        for name in (
            'lilypond-224663e00b24b652df759bda64c86bca48933457.ly',
            'lilypond-224663e00b24b652df759bda64c86bca48933457-page1.png',
            'lilypond-224663e00b24b652df759bda64c86bca48933457-page1-thumbnail.png',
            'lilypond-224663e00b24b652df759bda64c86bca48933457-page2.png',
            'lilypond-224663e00b24b652df759bda64c86bca48933457-page2-thumbnail.png',
            'lilypond-224663e00b24b652df759bda64c86bca48933457-page3.png',
            'lilypond-224663e00b24b652df759bda64c86bca48933457-page3-thumbnail.png',
            'lilypond-224663e00b24b652df759bda64c86bca48933457-page4.png',
            'lilypond-224663e00b24b652df759bda64c86bca48933457-page4-thumbnail.png',
            'lilypond-224663e00b24b652df759bda64c86bca48933457-page5.png',
            'lilypond-224663e00b24b652df759bda64c86bca48933457-page5-thumbnail.png',
            ):
            path = os.path.join(self.images_directory, 'abjadbook', name)
            assert os.path.exists(path)
    def test_10(self):
        source = r'''
        ..  abjad::
            :hide:
            :no-resize:
            :no-stylesheet:
            :with-thumbnail:

            staff = Staff("c'1 d'1 e'1 f'1 g'1")
            for note in staff[:-1]:
                attach(indicatortools.PageBreak(), note)

            show(staff)
        '''
        source = stringtools.normalize(source)
        handler = abjadbooktools.SphinxDocumentHandler()
        document = handler.parse_rst(source)
        handler.on_doctree_read(self.app, document)
        node = document[0]
        try:
            abjadbooktools.SphinxDocumentHandler.visit_abjad_output_block_html(
                self.app, node)
        except docutils.nodes.SkipNode:
            pass
        handler.on_build_finished(self.app, None)
        actual = '\n'.join(self.app.body)
        expected = stringtools.normalize(r'''
            <a data-lightbox="group-lilypond-de10d0db01d2644c7aea9703f6ed8c78d8dbb89a.ly" href="../_images/abjadbook/lilypond-de10d0db01d2644c7aea9703f6ed8c78d8dbb89a-page1.png" title="" data-title="" class="abjadbook thumbnail">
                <img src="../_images/abjadbook/lilypond-de10d0db01d2644c7aea9703f6ed8c78d8dbb89a-page1-thumbnail.png" alt=""/>
            </a>
            <a data-lightbox="group-lilypond-de10d0db01d2644c7aea9703f6ed8c78d8dbb89a.ly" href="../_images/abjadbook/lilypond-de10d0db01d2644c7aea9703f6ed8c78d8dbb89a-page2.png" title="" data-title="" class="abjadbook thumbnail">
                <img src="../_images/abjadbook/lilypond-de10d0db01d2644c7aea9703f6ed8c78d8dbb89a-page2-thumbnail.png" alt=""/>
            </a>
            <a data-lightbox="group-lilypond-de10d0db01d2644c7aea9703f6ed8c78d8dbb89a.ly" href="../_images/abjadbook/lilypond-de10d0db01d2644c7aea9703f6ed8c78d8dbb89a-page3.png" title="" data-title="" class="abjadbook thumbnail">
                <img src="../_images/abjadbook/lilypond-de10d0db01d2644c7aea9703f6ed8c78d8dbb89a-page3-thumbnail.png" alt=""/>
            </a>
            <a data-lightbox="group-lilypond-de10d0db01d2644c7aea9703f6ed8c78d8dbb89a.ly" href="../_images/abjadbook/lilypond-de10d0db01d2644c7aea9703f6ed8c78d8dbb89a-page4.png" title="" data-title="" class="abjadbook thumbnail">
                <img src="../_images/abjadbook/lilypond-de10d0db01d2644c7aea9703f6ed8c78d8dbb89a-page4-thumbnail.png" alt=""/>
            </a>
            <a data-lightbox="group-lilypond-de10d0db01d2644c7aea9703f6ed8c78d8dbb89a.ly" href="../_images/abjadbook/lilypond-de10d0db01d2644c7aea9703f6ed8c78d8dbb89a-page5.png" title="" data-title="" class="abjadbook thumbnail">
                <img src="../_images/abjadbook/lilypond-de10d0db01d2644c7aea9703f6ed8c78d8dbb89a-page5-thumbnail.png" alt=""/>
            </a>
            ''')
        self.assertEqual(actual, expected)
        assert len(os.listdir(self.abjadbook_images_directory)) == 11
        for name in (
            'lilypond-de10d0db01d2644c7aea9703f6ed8c78d8dbb89a.ly',
            'lilypond-de10d0db01d2644c7aea9703f6ed8c78d8dbb89a-page1.png',
            'lilypond-de10d0db01d2644c7aea9703f6ed8c78d8dbb89a-page1-thumbnail.png',
            'lilypond-de10d0db01d2644c7aea9703f6ed8c78d8dbb89a-page2.png',
            'lilypond-de10d0db01d2644c7aea9703f6ed8c78d8dbb89a-page2-thumbnail.png',
            'lilypond-de10d0db01d2644c7aea9703f6ed8c78d8dbb89a-page3.png',
            'lilypond-de10d0db01d2644c7aea9703f6ed8c78d8dbb89a-page3-thumbnail.png',
            'lilypond-de10d0db01d2644c7aea9703f6ed8c78d8dbb89a-page4.png',
            'lilypond-de10d0db01d2644c7aea9703f6ed8c78d8dbb89a-page4-thumbnail.png',
            'lilypond-de10d0db01d2644c7aea9703f6ed8c78d8dbb89a-page5.png',
            'lilypond-de10d0db01d2644c7aea9703f6ed8c78d8dbb89a-page5-thumbnail.png',
            ):
            path = os.path.join(self.images_directory, 'abjadbook', name)
            assert os.path.exists(path)
    def test_on_doctree_read_06(self):
        source = u'''
        This example demonstrates the power of exploiting redundancy to model
        musical structure. The piece that concerns us here is Ligeti's *Désordre*:
        the first piano study from Book I. Specifically, we will focus on modeling
        the first section of the piece.

        ..  abjad::

            print('Désordre')
        '''
        source = stringtools.normalize(source)
        handler = abjadbooktools.SphinxDocumentHandler()
        document = handler.parse_rst(source)
        handler.on_doctree_read(self.app, document)
        actual = stringtools.normalize(document.pformat())
        target = stringtools.normalize(u"""
            <document source="test">
                <paragraph>
                    This example demonstrates the power of exploiting redundancy to model
                    musical structure. The piece that concerns us here is Ligeti's
                    <emphasis>
                        Désordre
                    :
                    the first piano study from Book I. Specifically, we will focus on modeling
                    the first section of the piece.
                <literal_block xml:space="preserve">
                    >>> print('Désordre')
                    Désordre
            """)
        assert actual == target, \
            systemtools.TestManager.diff(actual, target, 'Diff:')
 def test_collect_abjad_input_blocks_01(self):
     handler = abjadbooktools.SphinxDocumentHandler()
     document = handler.parse_rst(self.source_one)
     blocks = handler.collect_abjad_input_blocks(document)
     assert len(blocks) == 3
     nodes = tuple(blocks.keys())
     assert nodes[0] is document[0]
     assert nodes[1] is document[2]
     assert nodes[2] is document[4]
    def test_on_doctree_read_05(self):
        source = r'''
        ..  abjad::
            :text-width: 40

            [x for x in dir() if not x.startswith('_')]
        '''
        source = stringtools.normalize(source)
        handler = abjadbooktools.SphinxDocumentHandler()
        document = handler.parse_rst(source)
        handler.on_doctree_read(self.app, document)
        actual = stringtools.normalize(document.pformat())
        target = stringtools.normalize(r"""
            <document source="test">
                <literal_block xml:space="preserve">
                    >>> [x for x in dir() if not x.startswith('_')]
                    ['Accelerando', 'Articulation', 'Beam',
                    'Chord', 'Clef', 'Container', 'Context',
                    'Crescendo', 'Decrescendo', 'Duration',
                    'Dynamic', 'Fermata', 'Fraction',
                    'Glissando', 'Hairpin', 'KeySignature',
                    'LilyPondCommand', 'Markup', 'Measure',
                    'MultimeasureRest', 'Multiplier',
                    'NamedPitch', 'Note', 'Offset', 'Ratio',
                    'Rest', 'Ritardando', 'Score',
                    'Sequence', 'Skip', 'Slur', 'Staff',
                    'StaffGroup', 'Tempo', 'Tie',
                    'TimeSignature', 'Timespan', 'Tuplet',
                    'Voice', 'abctools',
                    'abjad_configuration', 'agenttools',
                    'attach', 'commandlinetools',
                    'datastructuretools', 'demos', 'detach',
                    'documentationtools', 'durationtools',
                    'exceptiontools', 'expressiontools',
                    'ext', 'f', 'graph', 'indicatortools',
                    'inspect_', 'instrumenttools',
                    'ipythontools', 'iterate', 'label',
                    'lilypondfiletools',
                    'lilypondnametools',
                    'lilypondparsertools', 'ly',
                    'markuptools', 'mathtools',
                    'metertools', 'mutate', 'new',
                    'override', 'parse', 'patterntools',
                    'persist', 'pitchtools', 'play',
                    'print_function', 'quantizationtools',
                    'rhythmmakertools', 'rhythmtreetools',
                    'schemetools', 'scoretools', 'select',
                    'selectiontools', 'selectortools',
                    'sequence', 'sequencetools', 'set_',
                    'show', 'spannertools', 'stringtools',
                    'systemtools', 'templatetools',
                    'timespantools', 'tonalanalysistools',
                    'topleveltools']
            """)
        assert actual == target, \
            systemtools.TestManager.diff(actual, target, 'Diff:')
 def test_collect_python_literal_blocks_01(self):
     handler = abjadbooktools.SphinxDocumentHandler()
     document = handler.parse_rst(self.source_one)
     blocks = handler.collect_python_literal_blocks(
         document,
         renderable_only=False,
     )
     assert len(blocks) == 2
     nodes = tuple(blocks.keys())
     assert nodes[0] is document[1]
     assert nodes[1] is document[3]
    def test_09(self):
        source = r'''
        ..  abjad::
            :hide:
            :no-stylesheet:
            :no-trim:
            :pages: 2-4
            :with-columns: 2

            staff = Staff("c'1 d'1 e'1 f'1 g'1")
            for note in staff[:-1]:
                attach(indicatortools.PageBreak(), note)

            show(staff)
        '''
        source = systemtools.TestManager.clean_string(source)
        handler = abjadbooktools.SphinxDocumentHandler()
        document = handler.parse_rst(source)
        handler.on_doctree_read(self.app, document)
        node = document[0]
        try:
            abjadbooktools.SphinxDocumentHandler.visit_abjad_output_block_html(
                self.app, node)
        except docutils.nodes.SkipNode:
            pass
        handler.on_build_finished(self.app, None)
        actual = '\n'.join(self.app.body)
        expected = systemtools.TestManager.clean_string(r'''
            <div class="table-row">
                <a class="table-cell thumbnail" href="../_images/abjadbook/lilypond-1113b742beda3b13163bb7fe4bbdd6787edc3c1a.ly">
                    <img src="../_images/abjadbook/lilypond-1113b742beda3b13163bb7fe4bbdd6787edc3c1a-page2.png" alt="View source." title="View source." />
                </a>
                <a class="table-cell thumbnail" href="../_images/abjadbook/lilypond-1113b742beda3b13163bb7fe4bbdd6787edc3c1a.ly">
                    <img src="../_images/abjadbook/lilypond-1113b742beda3b13163bb7fe4bbdd6787edc3c1a-page3.png" alt="View source." title="View source." />
                </a>
            </div>
            <div class="table-row">
                <a class="table-cell thumbnail" href="../_images/abjadbook/lilypond-1113b742beda3b13163bb7fe4bbdd6787edc3c1a.ly">
                    <img src="../_images/abjadbook/lilypond-1113b742beda3b13163bb7fe4bbdd6787edc3c1a-page4.png" alt="View source." title="View source." />
                </a>
            </div>
            ''')
        self.assertEqual(actual, expected)
        assert len(os.listdir(self.abjadbook_images_directory)) == 6
        for name in (
            'lilypond-1113b742beda3b13163bb7fe4bbdd6787edc3c1a.ly',
            'lilypond-1113b742beda3b13163bb7fe4bbdd6787edc3c1a-page1.png',
            'lilypond-1113b742beda3b13163bb7fe4bbdd6787edc3c1a-page2.png',
            'lilypond-1113b742beda3b13163bb7fe4bbdd6787edc3c1a-page3.png',
            'lilypond-1113b742beda3b13163bb7fe4bbdd6787edc3c1a-page4.png',
            'lilypond-1113b742beda3b13163bb7fe4bbdd6787edc3c1a-page5.png',
            ):
            path = os.path.join(self.images_directory, 'abjadbook', name)
            assert os.path.exists(path)
    def test_07(self):
        source = r'''
        ..  abjad::
            :hide:
            :no-stylesheet:
            :pages: 2-4

            staff = Staff("c'1 d'1 e'1 f'1 g'1")
            for note in staff[:-1]:
                attach(indicatortools.PageBreak(), note)

            show(staff)
        '''
        source = systemtools.TestManager.clean_string(source)
        handler = abjadbooktools.SphinxDocumentHandler()
        document = handler.parse_rst(source)
        handler.on_doctree_read(self.app, document)
        node = document[0]
        try:
            abjadbooktools.SphinxDocumentHandler.visit_abjad_output_block_html(
                self.app, node)
        except docutils.nodes.SkipNode:
            pass
        handler.on_build_finished(self.app, None)
        actual = '\n'.join(self.app.body)
        expected = systemtools.TestManager.clean_string(r'''
            <div class="abjad-book-image">
                <a href="../_images/abjadbook/lilypond-f75159c51f466ac3f0427cda3f86fba7bb709ae7.ly">
                    <img src="../_images/abjadbook/lilypond-f75159c51f466ac3f0427cda3f86fba7bb709ae7-page2.png" alt="View source." title="View source." />
                </a>
            </div>
            <div class="abjad-book-image">
                <a href="../_images/abjadbook/lilypond-f75159c51f466ac3f0427cda3f86fba7bb709ae7.ly">
                    <img src="../_images/abjadbook/lilypond-f75159c51f466ac3f0427cda3f86fba7bb709ae7-page3.png" alt="View source." title="View source." />
                </a>
            </div>
            <div class="abjad-book-image">
                <a href="../_images/abjadbook/lilypond-f75159c51f466ac3f0427cda3f86fba7bb709ae7.ly">
                    <img src="../_images/abjadbook/lilypond-f75159c51f466ac3f0427cda3f86fba7bb709ae7-page4.png" alt="View source." title="View source." />
                </a>
            </div>
            ''')
        self.assertEqual(actual, expected)
        assert len(os.listdir(self.abjadbook_images_directory)) == 6
        for name in (
            'lilypond-f75159c51f466ac3f0427cda3f86fba7bb709ae7.ly',
            'lilypond-f75159c51f466ac3f0427cda3f86fba7bb709ae7-page1.png',
            'lilypond-f75159c51f466ac3f0427cda3f86fba7bb709ae7-page2.png',
            'lilypond-f75159c51f466ac3f0427cda3f86fba7bb709ae7-page3.png',
            'lilypond-f75159c51f466ac3f0427cda3f86fba7bb709ae7-page4.png',
            'lilypond-f75159c51f466ac3f0427cda3f86fba7bb709ae7-page5.png',
            ):
            path = os.path.join(self.images_directory, 'abjadbook', name)
            assert os.path.exists(path)
    def test_09(self):
        source = r'''
        ..  abjad::
            :hide:
            :no-stylesheet:
            :no-trim:
            :pages: 2-4
            :with-columns: 2

            staff = Staff("c'1 d'1 e'1 f'1 g'1")
            for note in staff[:-1]:
                attach(indicatortools.PageBreak(), note)

            show(staff)
        '''
        source = stringtools.normalize(source)
        handler = abjadbooktools.SphinxDocumentHandler()
        document = handler.parse_rst(source)
        handler.on_doctree_read(self.app, document)
        node = document[0]
        try:
            abjadbooktools.SphinxDocumentHandler.visit_abjad_output_block_html(
                self.app, node)
        except docutils.nodes.SkipNode:
            pass
        handler.on_build_finished(self.app, None)
        actual = '\n'.join(self.app.body)
        expected = stringtools.normalize(r'''
            <div class="table-row">
                <a href="../_images/abjadbook/lilypond-c58647743390ca8f866acf83a0d7efbf9b84d67f.ly" title="" class="table-cell">
                    <img src="../_images/abjadbook/lilypond-c58647743390ca8f866acf83a0d7efbf9b84d67f-page2.png" alt=""/>
                </a>
                <a href="../_images/abjadbook/lilypond-c58647743390ca8f866acf83a0d7efbf9b84d67f.ly" title="" class="table-cell">
                    <img src="../_images/abjadbook/lilypond-c58647743390ca8f866acf83a0d7efbf9b84d67f-page3.png" alt=""/>
                </a>
            </div>
            <div class="table-row">
                <a href="../_images/abjadbook/lilypond-c58647743390ca8f866acf83a0d7efbf9b84d67f.ly" title="" class="table-cell">
                    <img src="../_images/abjadbook/lilypond-c58647743390ca8f866acf83a0d7efbf9b84d67f-page4.png" alt=""/>
                </a>
            </div>
            ''')
        self.assertEqual(actual, expected)
        assert len(os.listdir(self.abjadbook_images_directory)) == 6
        for name in (
            'lilypond-c58647743390ca8f866acf83a0d7efbf9b84d67f.ly',
            'lilypond-c58647743390ca8f866acf83a0d7efbf9b84d67f-page1.png',
            'lilypond-c58647743390ca8f866acf83a0d7efbf9b84d67f-page2.png',
            'lilypond-c58647743390ca8f866acf83a0d7efbf9b84d67f-page3.png',
            'lilypond-c58647743390ca8f866acf83a0d7efbf9b84d67f-page4.png',
            'lilypond-c58647743390ca8f866acf83a0d7efbf9b84d67f-page5.png',
            ):
            path = os.path.join(self.images_directory, 'abjadbook', name)
            assert os.path.exists(path)
    def test_06(self):
        source = r'''
        ..  abjad::
            :hide:
            :no-stylesheet:

            staff = Staff("c'1 d'1 e'1 f'1 g'1")
            for note in staff[:-1]:
                attach(indicatortools.PageBreak(), note)

            show(staff)
        '''
        source = stringtools.normalize(source)
        handler = abjadbooktools.SphinxDocumentHandler()
        document = handler.parse_rst(source)
        handler.on_doctree_read(self.app, document)
        node = document[0]
        try:
            abjadbooktools.SphinxDocumentHandler.visit_abjad_output_block_html(
                self.app, node)
        except docutils.nodes.SkipNode:
            pass
        handler.on_build_finished(self.app, None)
        actual = '\n'.join(self.app.body)
        expected = stringtools.normalize(r'''
            <a href="../_images/abjadbook/lilypond-4b0885a24cb0c0f7d7f825826532e89575af5365.ly" title="" class="abjadbook">
                <img src="../_images/abjadbook/lilypond-4b0885a24cb0c0f7d7f825826532e89575af5365-page1.png" alt=""/>
            </a>
            <a href="../_images/abjadbook/lilypond-4b0885a24cb0c0f7d7f825826532e89575af5365.ly" title="" class="abjadbook">
                <img src="../_images/abjadbook/lilypond-4b0885a24cb0c0f7d7f825826532e89575af5365-page2.png" alt=""/>
            </a>
            <a href="../_images/abjadbook/lilypond-4b0885a24cb0c0f7d7f825826532e89575af5365.ly" title="" class="abjadbook">
                <img src="../_images/abjadbook/lilypond-4b0885a24cb0c0f7d7f825826532e89575af5365-page3.png" alt=""/>
            </a>
            <a href="../_images/abjadbook/lilypond-4b0885a24cb0c0f7d7f825826532e89575af5365.ly" title="" class="abjadbook">
                <img src="../_images/abjadbook/lilypond-4b0885a24cb0c0f7d7f825826532e89575af5365-page4.png" alt=""/>
            </a>
            <a href="../_images/abjadbook/lilypond-4b0885a24cb0c0f7d7f825826532e89575af5365.ly" title="" class="abjadbook">
                <img src="../_images/abjadbook/lilypond-4b0885a24cb0c0f7d7f825826532e89575af5365-page5.png" alt=""/>
            </a>
            ''')
        self.assertEqual(actual, expected)
        assert len(os.listdir(self.abjadbook_images_directory)) == 6
        for name in (
            'lilypond-4b0885a24cb0c0f7d7f825826532e89575af5365.ly',
            'lilypond-4b0885a24cb0c0f7d7f825826532e89575af5365-page1.png',
            'lilypond-4b0885a24cb0c0f7d7f825826532e89575af5365-page2.png',
            'lilypond-4b0885a24cb0c0f7d7f825826532e89575af5365-page3.png',
            'lilypond-4b0885a24cb0c0f7d7f825826532e89575af5365-page4.png',
            'lilypond-4b0885a24cb0c0f7d7f825826532e89575af5365-page5.png',
            ):
            path = os.path.join(self.images_directory, 'abjadbook', name)
            assert os.path.exists(path)
    def test_on_doctree_read_09(self):
        source = '''
        ..  abjad::
            :strip-prompt:

            class Foo(object):

                def bar(self):
                    print('OK')

                def baz(self):
                    print('NO')

                def quux(self):
                    return 23

        ..  abjad::

            foo = Foo()
            foo.quux()
        '''
        handler = abjadbooktools.SphinxDocumentHandler()
        document = handler.parse_rst(source)
        handler.on_doctree_read(self.app, document)
        actual = stringtools.normalize(document.pformat())
        target = stringtools.normalize(r"""
            <document source="test">
                <block_quote>
                    <literal_block xml:space="preserve">
                        class Foo(object):

                            def bar(self):
                                print('OK')

                            def baz(self):
                                print('NO')

                            def quux(self):
                                return 23
                    <literal_block xml:space="preserve">
                        >>> foo = Foo()
                        >>> foo.quux()
                        23
            """)
        assert actual == target, \
            systemtools.TestManager.diff(actual, target, 'Diff:')
    def test_on_doctree_read_07(self):
        source = '''
        ..  abjad::
            :hide:
            :no-trim:
            :pages: 1-4
            :with-columns: 2

            show(Staff("c'4 d'4 e'4 f'4"))
        '''
        handler = abjadbooktools.SphinxDocumentHandler()
        document = handler.parse_rst(source)
        handler.on_doctree_read(self.app, document)
        actual = stringtools.normalize(document.pformat())
        target = stringtools.normalize(r"""
            <document source="test">
                <block_quote>
                    <abjad_output_block image_layout_specifier="ImageLayoutSpecifier(pages=(1, 2, 3, 4), with_columns=2)" image_render_specifier="ImageRenderSpecifier(no_trim=True, stylesheet='default.ly')" renderer="lilypond" xml:space="preserve">
                        \version "2.19.0"
                        \language "english"

                        #(ly:set-option 'relative-includes #t)

                        \include "default.ly"

                        \header {
                            tagline = ##f
                        }

                        \layout {}

                        \paper {}

                        \score {
                            \new Staff {
                                c'4
                                d'4
                                e'4
                                f'4
                            }
                        }
            """)
        assert actual == target, \
            systemtools.TestManager.diff(actual, target, 'Diff:')
    def test_05(self):
        source = r'''
        ..  abjad::
            :hide:
            :stylesheet: non-proportional.ly
            :no-trim:

            show(Staff("c'4 d'4 e'4 f'4"))
        '''
        source = systemtools.TestManager.clean_string(source)
        handler = abjadbooktools.SphinxDocumentHandler()
        document = handler.parse_rst(source)
        handler.on_doctree_read(self.app, document)
        abjadbooktools.SphinxDocumentHandler.on_builder_inited(self.app)
        node = document[0]
        try:
            abjadbooktools.SphinxDocumentHandler.visit_abjad_output_block_html(
                self.app, node)
        except docutils.nodes.SkipNode:
            pass
        handler.on_build_finished(self.app, None)
        actual = '\n'.join(self.app.body)
        expected = systemtools.TestManager.clean_string(r'''
            <div class="abjad-book-image">
                <a href="../_images/abjadbook/lilypond-eabd6888954618b38ced28351cc4a53e950f5a08.ly">
                    <img src="../_images/abjadbook/lilypond-eabd6888954618b38ced28351cc4a53e950f5a08.png" alt="View source." title="View source." />
                </a>
            </div>
            ''')
        self.assertEqual(actual, expected)
        assert len(os.listdir(self.abjadbook_images_directory)) == 6
        for name in (
            'default.ly',
            'external-settings-file-1.ly',
            'external-settings-file-2.ly',
            'lilypond-eabd6888954618b38ced28351cc4a53e950f5a08.ly',
            'lilypond-eabd6888954618b38ced28351cc4a53e950f5a08.png',
            'non-proportional.ly',
            ):
            path = os.path.join(self.images_directory, 'abjadbook', name)
            assert os.path.exists(path)
    def test_04(self):
        source = r'''
        ..  abjad::
            :hide:
            :no-resize:
            :no-stylesheet:
            :no-trim:
            :with-thumbnail:

            show(Staff("c'4 d'4 e'4 f'4"))
        '''
        source = systemtools.TestManager.clean_string(source)
        handler = abjadbooktools.SphinxDocumentHandler()
        document = handler.parse_rst(source)
        handler.on_doctree_read(self.app, document)
        node = document[0]
        try:
            abjadbooktools.SphinxDocumentHandler.visit_abjad_output_block_html(
                self.app, node)
        except docutils.nodes.SkipNode:
            pass
        handler.on_build_finished(self.app, None)
        assert len(self.app.builder.thumbnails) == 1
        assert '../_images/abjadbook/lilypond-93ffa240c3eeeb710e929d9d3ccb00128218440e.png' in self.app.builder.thumbnails
        actual = '\n'.join(self.app.body)
        expected = systemtools.TestManager.clean_string(r'''
            <a data-lightbox="group-lilypond-93ffa240c3eeeb710e929d9d3ccb00128218440e.ly" href="../_images/abjadbook/lilypond-93ffa240c3eeeb710e929d9d3ccb00128218440e.png" class="">
                <img src="../_images/abjadbook/lilypond-93ffa240c3eeeb710e929d9d3ccb00128218440e-thumbnail.png"/>
            </a>
            ''')
        self.assertEqual(actual, expected)
        assert len(os.listdir(self.abjadbook_images_directory)) == 3
        for name in (
            'lilypond-93ffa240c3eeeb710e929d9d3ccb00128218440e.ly',
            'lilypond-93ffa240c3eeeb710e929d9d3ccb00128218440e.png',
            'lilypond-93ffa240c3eeeb710e929d9d3ccb00128218440e-thumbnail.png',
            ):
            path = os.path.join(self.images_directory, 'abjadbook', name)
            assert os.path.exists(path)
    def test_04(self):
        source = r'''
        ..  abjad::
            :hide:
            :no-resize:
            :no-stylesheet:
            :no-trim:
            :with-thumbnail:

            show(Staff("c'4 d'4 e'4 f'4"))
        '''
        source = stringtools.normalize(source)
        handler = abjadbooktools.SphinxDocumentHandler()
        document = handler.parse_rst(source)
        handler.on_doctree_read(self.app, document)
        node = document[0]
        try:
            abjadbooktools.SphinxDocumentHandler.visit_abjad_output_block_html(
                self.app, node)
        except docutils.nodes.SkipNode:
            pass
        handler.on_build_finished(self.app, None)
        assert len(self.app.builder.thumbnails) == 1
        assert '../_images/abjadbook/lilypond-8a8f45fe58b00dd49561a578f60b7ec69ee75113.png' in self.app.builder.thumbnails
        actual = '\n'.join(self.app.body)
        expected = stringtools.normalize(r'''
            <a data-lightbox="group-lilypond-8a8f45fe58b00dd49561a578f60b7ec69ee75113.ly" href="../_images/abjadbook/lilypond-8a8f45fe58b00dd49561a578f60b7ec69ee75113.png" title="" data-title="" class="abjadbook thumbnail">
                <img src="../_images/abjadbook/lilypond-8a8f45fe58b00dd49561a578f60b7ec69ee75113-thumbnail.png" alt=""/>
            </a>
            ''')
        self.assertEqual(actual, expected)
        assert len(os.listdir(self.abjadbook_images_directory)) == 3
        for name in (
            'lilypond-8a8f45fe58b00dd49561a578f60b7ec69ee75113.ly',
            'lilypond-8a8f45fe58b00dd49561a578f60b7ec69ee75113.png',
            'lilypond-8a8f45fe58b00dd49561a578f60b7ec69ee75113-thumbnail.png',
            ):
            path = os.path.join(self.images_directory, 'abjadbook', name)
            assert os.path.exists(path)
    def test_on_doctree_read_10(self):
        source = '''
        ..  abjad::
            :hide:
            :reveal-label: foo
            :strip-prompt:

            def foo(x):
                return x + 1

        ..  abjad::

            3 * 5

        ..  reveal:: foo

        ..  abjad::

            foo(23)
        '''
        handler = abjadbooktools.SphinxDocumentHandler()
        document = handler.parse_rst(source)
        handler.on_doctree_read(self.app, document)
        actual = stringtools.normalize(document.pformat())
        target = stringtools.normalize(r"""
            <document source="test">
                <block_quote>
                    <literal_block xml:space="preserve">
                        >>> 3 * 5
                        15
                    <literal_block xml:space="preserve">
                        def foo(x):
                            return x + 1
                    <literal_block xml:space="preserve">
                        >>> foo(23)
                        24
            """)
        assert actual == target, \
            systemtools.TestManager.diff(actual, target, 'Diff:')
    def test_05(self):
        source = r'''
        ..  abjad::
            :hide:
            :stylesheet: non-proportional.ly
            :no-trim:

            show(Staff("c'4 d'4 e'4 f'4"))
        '''
        source = stringtools.normalize(source)
        handler = abjadbooktools.SphinxDocumentHandler()
        document = handler.parse_rst(source)
        handler.on_doctree_read(self.app, document)
        abjadbooktools.SphinxDocumentHandler.on_builder_inited(self.app)
        node = document[0]
        try:
            abjadbooktools.SphinxDocumentHandler.visit_abjad_output_block_html(
                self.app, node)
        except docutils.nodes.SkipNode:
            pass
        handler.on_build_finished(self.app, None)
        actual = '\n'.join(self.app.body)
        expected = stringtools.normalize(r'''
            <a href="../_images/abjadbook/lilypond-7d4a48470c171cd8b46a0bd339cd92e2f9fdfa13.ly" title="" class="abjadbook">
                <img src="../_images/abjadbook/lilypond-7d4a48470c171cd8b46a0bd339cd92e2f9fdfa13.png" alt=""/>
            </a>
            ''')
        self.assertEqual(actual, expected)
        assert len(os.listdir(self.abjadbook_images_directory)) == 6
        for name in (
            'default.ly',
            'external-settings-file-1.ly',
            'external-settings-file-2.ly',
            'lilypond-7d4a48470c171cd8b46a0bd339cd92e2f9fdfa13.ly',
            'lilypond-7d4a48470c171cd8b46a0bd339cd92e2f9fdfa13.png',
            'non-proportional.ly',
            ):
            path = os.path.join(self.images_directory, 'abjadbook', name)
            assert os.path.exists(path)
    def test_on_doctree_read_08(self):
        source = '''
        ..  abjad::

            staff = Staff("c'4 d'4 e'4 f'4")
            spanner = Slur()
            attach(spanner, staff[:])

        ..  abjad::

            for leaf in staff:
                is_first = spanner._is_my_first_leaf(leaf)
                is_last = spanner._is_my_last_leaf(leaf)
                print(repr(leaf), is_first, is_last)
        '''
        handler = abjadbooktools.SphinxDocumentHandler()
        document = handler.parse_rst(source)
        handler.on_doctree_read(self.app, document)
        actual = stringtools.normalize(document.pformat())
        target = stringtools.normalize(r"""
            <document source="test">
                <block_quote>
                    <literal_block xml:space="preserve">
                        >>> staff = Staff("c'4 d'4 e'4 f'4")
                        >>> spanner = Slur()
                        >>> attach(spanner, staff[:])
                    <literal_block xml:space="preserve">
                        >>> for leaf in staff:
                        ...     is_first = spanner._is_my_first_leaf(leaf)
                        ...     is_last = spanner._is_my_last_leaf(leaf)
                        ...     print(repr(leaf), is_first, is_last)
                        ...
                        Note("c'4") True False
                        Note("d'4") False False
                        Note("e'4") False False
                        Note("f'4") False True
            """)
        assert actual == target, \
            systemtools.TestManager.diff(actual, target, 'Diff:')
    def test_on_doctree_read_02(self):
        source = r'''
        ..  abjad::

            staff = Staff("c'1 g'1")
            for note in staff:
                show(note)

            len(staff)
        '''
        source = systemtools.TestManager.clean_string(source)
        handler = abjadbooktools.SphinxDocumentHandler()
        document = handler.parse_rst(source)
        handler.on_doctree_read(self.app, document)
        actual = systemtools.TestManager.clean_string(document.pformat())
        target = systemtools.TestManager.clean_string(r"""
            <document source="test">
                <literal_block xml:space="preserve">
                    >>> staff = Staff("c'1 g'1")
                    >>> for note in staff:
                    ...     show(note)
                    ...
                <abjad_output_block image_layout_specifier image_render_specifier="ImageRenderSpecifier(stylesheet='default.ly')" renderer="lilypond" xml:space="preserve">
                    \version "2.19.0"
                    \language "english"

                    #(ly:set-option 'relative-includes #t)

                    \include "default.ly"

                    \header {
                        tagline = \markup {}
                    }

                    \layout {}

                    \paper {}

                    \score {
                        {
                            c'1
                        }
                    }
                <abjad_output_block image_layout_specifier image_render_specifier="ImageRenderSpecifier(stylesheet='default.ly')" renderer="lilypond" xml:space="preserve">
                    \version "2.19.0"
                    \language "english"

                    #(ly:set-option 'relative-includes #t)

                    \include "default.ly"

                    \header {
                        tagline = \markup {}
                    }

                    \layout {}

                    \paper {}

                    \score {
                        {
                            g'1
                        }
                    }
                <literal_block xml:space="preserve">
                    >>> len(staff)
                    2
            """)
        assert actual == target
 def test_collect_python_literal_blocks_02(self):
     handler = abjadbooktools.SphinxDocumentHandler()
     document = handler.parse_rst(self.source_one)
     blocks = handler.collect_python_literal_blocks(document)
     assert len(blocks) == 0
    def test_on_doctree_read_04(self):
        source = r'''
        ..  container:: example

            **Example 1.** Duple meter:

            ::

                >>> 1 + 1

            ::

                >>> meter = metertools.Meter((2, 4))
                >>> meter
                Meter('(2/4 (1/4 1/4))')
                >>> print(meter.pretty_rtm_format)
                (2/4 (
                    1/4
                    1/4))

            ::

                >>> graph(meter) # doctest: +SKIP

            `2/4` comprises two beats.

        ..  container:: example

            **Example 2.** Triple meter:

            ::

                >>> meter = metertools.Meter((3, 4))
                >>> print(meter.pretty_rtm_format)
                (3/4 (
                    1/4
                    1/4
                    1/4))

            ::

                >>> graph(meter) # doctest: +SKIP

            `3/4` comprises three beats.
        '''
        source = stringtools.normalize(source)
        handler = abjadbooktools.SphinxDocumentHandler()
        document = handler.parse_rst(source)
        handler.on_doctree_read(self.app, document)
        actual = stringtools.normalize(document.pformat())
        target = stringtools.normalize(r"""
            <document source="test">
                <container classes="example">
                    <paragraph>
                        <strong>
                            Example 1.
                         Duple meter:
                    <literal_block xml:space="preserve">
                        >>> 1 + 1
                        2
                    <literal_block xml:space="preserve">
                        >>> meter = metertools.Meter((2, 4))
                        >>> meter
                        Meter('(2/4 (1/4 1/4))')
                    <literal_block xml:space="preserve">
                        >>> print(meter.pretty_rtm_format)
                        (2/4 (
                            1/4
                            1/4))
                    <literal_block xml:space="preserve">
                        >>> graph(meter) # doctest: +SKIP
                    <abjad_output_block image_layout_specifier image_render_specifier layout="dot" renderer="graphviz" xml:space="preserve">
                        digraph G {
                            graph [bgcolor=transparent,
                                fontname=Arial,
                                penwidth=2,
                                truecolor=true];
                            node [fontname=Arial,
                                fontsize=12,
                                penwidth=2];
                            edge [penwidth=2];
                            node_0 [label="2/4",
                                shape=triangle];
                            node_1 [label="1/4",
                                shape=box];
                            node_2 [label="1/4",
                                shape=box];
                            subgraph cluster_cluster_offsets {
                                graph [style=rounded];
                                node_3_0 [color=white,
                                    fillcolor=black,
                                    fontcolor=white,
                                    fontname="Arial bold",
                                    label="{ <f_0_0> 0 | <f_0_1> ++ }",
                                    shape=Mrecord,
                                    style=filled];
                                node_3_1 [color=white,
                                    fillcolor=black,
                                    fontcolor=white,
                                    fontname="Arial bold",
                                    label="{ <f_0_0> 1/4 | <f_0_1> + }",
                                    shape=Mrecord,
                                    style=filled];
                                node_3_2 [label="{ <f_0_0> 1/2 | <f_0_1> ++ }",
                                    shape=Mrecord];
                            }
                            node_0 -> node_1;
                            node_0 -> node_2;
                            node_1 -> node_3_0 [style=dotted];
                            node_1 -> node_3_1 [style=dotted];
                            node_2 -> node_3_1 [style=dotted];
                            node_2 -> node_3_2 [style=dotted];
                        }
                    <paragraph>
                        <title_reference>
                            2/4
                         comprises two beats.
                <container classes="example">
                    <paragraph>
                        <strong>
                            Example 2.
                         Triple meter:
                    <literal_block xml:space="preserve">
                        >>> meter = metertools.Meter((3, 4))
                        >>> print(meter.pretty_rtm_format)
                        (3/4 (
                            1/4
                            1/4
                            1/4))
                    <literal_block xml:space="preserve">
                        >>> graph(meter) # doctest: +SKIP
                    <abjad_output_block image_layout_specifier image_render_specifier layout="dot" renderer="graphviz" xml:space="preserve">
                        digraph G {
                            graph [bgcolor=transparent,
                                fontname=Arial,
                                penwidth=2,
                                truecolor=true];
                            node [fontname=Arial,
                                fontsize=12,
                                penwidth=2];
                            edge [penwidth=2];
                            node_0 [label="3/4",
                                shape=triangle];
                            node_1 [label="1/4",
                                shape=box];
                            node_2 [label="1/4",
                                shape=box];
                            node_3 [label="1/4",
                                shape=box];
                            subgraph cluster_cluster_offsets {
                                graph [style=rounded];
                                node_4_0 [color=white,
                                    fillcolor=black,
                                    fontcolor=white,
                                    fontname="Arial bold",
                                    label="{ <f_0_0> 0 | <f_0_1> ++ }",
                                    shape=Mrecord,
                                    style=filled];
                                node_4_1 [color=white,
                                    fillcolor=black,
                                    fontcolor=white,
                                    fontname="Arial bold",
                                    label="{ <f_0_0> 1/4 | <f_0_1> + }",
                                    shape=Mrecord,
                                    style=filled];
                                node_4_2 [color=white,
                                    fillcolor=black,
                                    fontcolor=white,
                                    fontname="Arial bold",
                                    label="{ <f_0_0> 1/2 | <f_0_1> + }",
                                    shape=Mrecord,
                                    style=filled];
                                node_4_3 [label="{ <f_0_0> 3/4 | <f_0_1> ++ }",
                                    shape=Mrecord];
                            }
                            node_0 -> node_1;
                            node_0 -> node_2;
                            node_0 -> node_3;
                            node_1 -> node_4_0 [style=dotted];
                            node_1 -> node_4_1 [style=dotted];
                            node_2 -> node_4_1 [style=dotted];
                            node_2 -> node_4_2 [style=dotted];
                            node_3 -> node_4_2 [style=dotted];
                            node_3 -> node_4_3 [style=dotted];
                        }
                    <paragraph>
                        <title_reference>
                            3/4
                         comprises three beats.
            """)
        assert actual == target, \
            systemtools.TestManager.diff(actual, target, 'Diff:')
    def test_11(self):
        source = r'''
        ..  abjad::
            :hide:
            :no-resize:
            :no-stylesheet:
            :with-columns: 2
            :with-thumbnail:

            staff = Staff("c'1 d'1 e'1 f'1 g'1")
            for note in staff[:-1]:
                attach(indicatortools.PageBreak(), note)

            abjad.show(staff)
        '''
        source = abjad.String.normalize(source)
        handler = abjadbooktools.SphinxDocumentHandler()
        document = handler.parse_rst(source)
        handler.on_doctree_read(self.app, document)
        node = document[0]
        try:
            abjadbooktools.SphinxDocumentHandler.visit_abjad_output_block_html(
                self.app, node)
        except docutils.nodes.SkipNode:
            pass
        handler.on_build_finished(self.app, None)
        actual = '\n'.join(self.app.body)
        expected = abjad.String.normalize(r'''
            <div class="table-row">
                <a data-lightbox="group-lilypond-0aa2622a00db4f1eb5e873ef7e6a7f14fa465623.ly" href="../_images/abjadbook/lilypond-0aa2622a00db4f1eb5e873ef7e6a7f14fa465623-page1.png" title="" data-title="" class="table-cell thumbnail">
                    <img src="../_images/abjadbook/lilypond-0aa2622a00db4f1eb5e873ef7e6a7f14fa465623-page1-thumbnail.png" alt=""/>
                </a>
                <a data-lightbox="group-lilypond-0aa2622a00db4f1eb5e873ef7e6a7f14fa465623.ly" href="../_images/abjadbook/lilypond-0aa2622a00db4f1eb5e873ef7e6a7f14fa465623-page2.png" title="" data-title="" class="table-cell thumbnail">
                    <img src="../_images/abjadbook/lilypond-0aa2622a00db4f1eb5e873ef7e6a7f14fa465623-page2-thumbnail.png" alt=""/>
                </a>
            </div>
            <div class="table-row">
                <a data-lightbox="group-lilypond-0aa2622a00db4f1eb5e873ef7e6a7f14fa465623.ly" href="../_images/abjadbook/lilypond-0aa2622a00db4f1eb5e873ef7e6a7f14fa465623-page3.png" title="" data-title="" class="table-cell thumbnail">
                    <img src="../_images/abjadbook/lilypond-0aa2622a00db4f1eb5e873ef7e6a7f14fa465623-page3-thumbnail.png" alt=""/>
                </a>
                <a data-lightbox="group-lilypond-0aa2622a00db4f1eb5e873ef7e6a7f14fa465623.ly" href="../_images/abjadbook/lilypond-0aa2622a00db4f1eb5e873ef7e6a7f14fa465623-page4.png" title="" data-title="" class="table-cell thumbnail">
                    <img src="../_images/abjadbook/lilypond-0aa2622a00db4f1eb5e873ef7e6a7f14fa465623-page4-thumbnail.png" alt=""/>
                </a>
            </div>
            <div class="table-row">
                <a data-lightbox="group-lilypond-0aa2622a00db4f1eb5e873ef7e6a7f14fa465623.ly" href="../_images/abjadbook/lilypond-0aa2622a00db4f1eb5e873ef7e6a7f14fa465623-page5.png" title="" data-title="" class="table-cell thumbnail">
                    <img src="../_images/abjadbook/lilypond-0aa2622a00db4f1eb5e873ef7e6a7f14fa465623-page5-thumbnail.png" alt=""/>
                </a>
            </div>
            ''')
        self.assertEqual(actual, expected)
        assert len(os.listdir(self.abjadbook_images_directory)) == 11
        for name in (
                'lilypond-0aa2622a00db4f1eb5e873ef7e6a7f14fa465623.ly',
                'lilypond-0aa2622a00db4f1eb5e873ef7e6a7f14fa465623-page1.png',
                'lilypond-0aa2622a00db4f1eb5e873ef7e6a7f14fa465623-page1-thumbnail.png',
                'lilypond-0aa2622a00db4f1eb5e873ef7e6a7f14fa465623-page2.png',
                'lilypond-0aa2622a00db4f1eb5e873ef7e6a7f14fa465623-page2-thumbnail.png',
                'lilypond-0aa2622a00db4f1eb5e873ef7e6a7f14fa465623-page3.png',
                'lilypond-0aa2622a00db4f1eb5e873ef7e6a7f14fa465623-page3-thumbnail.png',
                'lilypond-0aa2622a00db4f1eb5e873ef7e6a7f14fa465623-page4.png',
                'lilypond-0aa2622a00db4f1eb5e873ef7e6a7f14fa465623-page4-thumbnail.png',
                'lilypond-0aa2622a00db4f1eb5e873ef7e6a7f14fa465623-page5.png',
                'lilypond-0aa2622a00db4f1eb5e873ef7e6a7f14fa465623-page5-thumbnail.png',
        ):
            path = os.path.join(self.images_directory, 'abjadbook', name)
            assert os.path.exists(path)
    def test_on_doctree_read_03(self):
        source = r'''
        ..  abjad::
            :no-stylesheet:

            staff = Staff("c'1 g'1")
            for note in staff:
                show(note)

            len(staff)
        '''
        source = stringtools.normalize(source)
        handler = abjadbooktools.SphinxDocumentHandler()
        document = handler.parse_rst(source)
        handler.on_doctree_read(self.app, document)
        actual = stringtools.normalize(document.pformat())
        target = stringtools.normalize(r"""
            <document source="test">
                <literal_block xml:space="preserve">
                    >>> staff = Staff("c'1 g'1")
                    >>> for note in staff:
                    ...     show(note)
                    ...
                <abjad_output_block image_layout_specifier image_render_specifier="ImageRenderSpecifier(no_stylesheet=True)" renderer="lilypond" xml:space="preserve">
                    \version "2.19.0"
                    \language "english"

                    \header {
                        tagline = ##f
                    }

                    \layout {}

                    \paper {}

                    \score {
                        {
                            c'1
                        }
                    }
                <abjad_output_block image_layout_specifier image_render_specifier="ImageRenderSpecifier(no_stylesheet=True)" renderer="lilypond" xml:space="preserve">
                    \version "2.19.0"
                    \language "english"

                    \header {
                        tagline = ##f
                    }

                    \layout {}

                    \paper {}

                    \score {
                        {
                            g'1
                        }
                    }
                <literal_block xml:space="preserve">
                    >>> len(staff)
                    2
            """)
        assert actual == target