Exemplo n.º 1
0
    def test_multiple_codeblocks(self):
        '''Tests that multiple codeblocks are processed independently.'''
        test_string = self.read_test_file(self.processor_name,
                                          'multiple_codeblocks.md')

        converted_test_string = markdown.markdown(
            test_string,
            extensions=[
                'markdown.extensions.fenced_code', self.verto_extension
            ])
        expected_string = self.read_test_file(
            self.processor_name,
            'multiple_codeblocks_expected.html',
            strip=True)
        self.assertEqual(expected_string, converted_test_string)

        actual_scratch_images = self.verto_extension.required_files[
            'scratch_images']
        expected_scratch_images = {
            ScratchImageMetaData(
                hash=
                '3dfa73663a21d295e1e5c1e5583d8d01edd68ec53ad3050597de126076c44ea5',
                text='say [Hello] for (2) secs'),
            ScratchImageMetaData(
                hash=
                '2f3ea223b778227287b8935bc5d209e25d3e8a25ef46ff85f6c44818159601d7',
                text='when flag clicked'),
            ScratchImageMetaData(
                hash=
                '1c95862744e873cc87e4cadf6174257ce6e8a237b29b5c41f241e98e0d78eb14',
                text='turn ccw (9) degrees'),
        }
        self.assertSetEqual(actual_scratch_images, expected_scratch_images)
Exemplo n.º 2
0
    def test_doc_example_basic(self):
        '''An example of common useage.'''
        test_string = self.read_test_file(self.processor_name,
                                          'doc_example_basic_usage.md')

        converted_test_string = markdown.markdown(
            test_string,
            extensions=[
                'markdown.extensions.fenced_code', self.verto_extension
            ])
        expected_string = self.read_test_file(
            self.processor_name,
            'doc_example_basic_usage_expected.html',
            strip=True)
        self.assertEqual(expected_string, converted_test_string)

        actual_scratch_images = self.verto_extension.required_files[
            'scratch_images']
        expected_scratch_images = {
            ScratchImageMetaData(
                hash=
                '3dfa73663a21d295e1e5c1e5583d8d01edd68ec53ad3050597de126076c44ea5',
                text='say [Hello] for (2) secs'),
        }
        self.assertSetEqual(actual_scratch_images, expected_scratch_images)
Exemplo n.º 3
0
    def test_doc_example_override_html(self):
        '''An example showing how to override the html-template.'''
        test_string = self.read_test_file(self.processor_name,
                                          'doc_example_override_html.md')

        html_template = self.read_test_file(
            self.processor_name,
            'doc_example_override_html_template.html',
            strip=True)
        verto_extension = VertoExtension(
            [self.processor_name],
            html_templates={self.processor_name: html_template},
            extensions=['markdown.extensions.fenced_code'])

        converted_test_string = markdown.markdown(
            test_string,
            extensions=['markdown.extensions.fenced_code', verto_extension])
        expected_string = self.read_test_file(
            self.processor_name,
            'doc_example_override_html_expected.html',
            strip=True)
        self.assertEqual(expected_string, converted_test_string)

        actual_scratch_images = verto_extension.required_files[
            'scratch_images']
        expected_scratch_images = {
            ScratchImageMetaData(
                hash=
                '2f3ea223b778227287b8935bc5d209e25d3e8a25ef46ff85f6c44818159601d7',
                text='when flag clicked'),
        }
        self.assertSetEqual(actual_scratch_images, expected_scratch_images)
Exemplo n.º 4
0
    def test_example_standard_markdown_block(self):
        '''Tests that even without extensions it behaves as expected.
        '''
        verto_extension = VertoExtension([self.processor_name], {}, [])
        test_string = self.read_test_file(
            self.processor_name, 'example_standard_markdown_block.md')

        converted_test_string = markdown.markdown(test_string,
                                                  extensions=[verto_extension])
        expected_string = self.read_test_file(
            self.processor_name,
            'example_standard_markdown_block_expected.html',
            strip=True)
        self.assertEqual(expected_string, converted_test_string)

        actual_scratch_images = verto_extension.required_files[
            'scratch_images']
        expected_scratch_images = {
            ScratchImageMetaData(
                hash=
                'a0f8fcad796864abfacac8bda6e0719813833fd1fca348700abbd040557c1576',
                text=
                'when flag clicked\nclear\nforever\npen down\nif <<mouse down?> and <touching [mouse-pointer v]?>> then\nswitch costume to [button v]\nelse\nadd (x position) to [list v]\nend\nmove (foo) steps\nturn ccw (9) degrees'
            ),
        }
        self.assertSetEqual(actual_scratch_images, expected_scratch_images)
Exemplo n.º 5
0
    def test_example_other_code(self):
        '''Tests that other codeblocks that are not scratch codeblocks
        are not erroneously matched.
        '''
        test_string = self.read_test_file(self.processor_name,
                                          'example_other_code.md')

        converted_test_string = markdown.markdown(
            test_string,
            extensions=[
                'markdown.extensions.fenced_code', self.verto_extension
            ])
        expected_string = self.read_test_file(
            self.processor_name,
            'example_other_code_expected.html',
            strip=True)
        self.assertEqual(expected_string, converted_test_string)

        actual_scratch_images = self.verto_extension.required_files[
            'scratch_images']
        expected_scratch_images = {
            ScratchImageMetaData(
                hash=
                'a0f8fcad796864abfacac8bda6e0719813833fd1fca348700abbd040557c1576',
                text=
                'when flag clicked\nclear\nforever\npen down\nif <<mouse down?> and <touching [mouse-pointer v]?>> then\nswitch costume to [button v]\nelse\nadd (x position) to [list v]\nend\nmove (foo) steps\nturn ccw (9) degrees'
            ),
        }
        self.assertSetEqual(actual_scratch_images, expected_scratch_images)
Exemplo n.º 6
0
    def test_doc_example_override_html(self):
        '''An example showing how to override the html-template.
        '''
        test_string = self.read_test_file(self.processor_name,
                                          'doc_example_override_html.md')

        html_template = self.read_test_file(
            self.processor_name,
            'doc_example_override_html_template.html',
            strip=True)
        verto_extension = VertoExtension(
            [self.processor_name],
            html_templates={self.processor_name: html_template},
            extensions=['markdown.extensions.fenced_code'])

        converted_test_string = markdown.markdown(
            test_string,
            extensions=['markdown.extensions.fenced_code', verto_extension])
        expected_string = self.read_test_file(
            self.processor_name,
            'doc_example_override_html_expected.html',
            strip=True)
        self.assertEqual(expected_string, converted_test_string)

        actual_scratch_images = verto_extension.required_files[
            'scratch_images']
        expected_scratch_images = {
            ScratchImageMetaData(
                hash=
                'a3b77ed3c3fa57e43c830e338dc39d292c7def676e0e8f7545972b7da20275da',
                text='when flag clicked\nsay [Hi]'),
        }
        self.assertSetEqual(actual_scratch_images, expected_scratch_images)
Exemplo n.º 7
0
    def test_example_separate_blocks(self):
        '''Tests that code separated by whitespace is still processed.
        '''
        test_string = self.read_test_file(self.processor_name,
                                          'example_separate_blocks.md')

        converted_test_string = markdown.markdown(
            test_string,
            extensions=[
                'markdown.extensions.fenced_code', self.verto_extension
            ])
        expected_string = self.read_test_file(
            self.processor_name,
            'example_separate_blocks_expected.html',
            strip=True)
        self.assertEqual(expected_string, converted_test_string)

        actual_scratch_images = self.verto_extension.required_files[
            'scratch_images']
        expected_scratch_images = {
            ScratchImageMetaData(
                hash=
                '8e8a2129c3cecf32101248439961735fc1d45793fadc56e2575673f63d42b9fb',
                text=
                'when flag clicked\nclear\nforever\npen down\n\nif <<mouse down?> and <touching [mouse-pointer v]?>> then\nswitch costume to [button v]\nelse\nadd (x position) to [list v]\nend\n\nmove (foo) steps\nturn ccw (9) degrees'
            ),
        }
        self.assertSetEqual(actual_scratch_images, expected_scratch_images)
Exemplo n.º 8
0
    def test_example_multiple_codeblocks_2(self):
        '''Tests that enabling the codehilite extension does not effect
        the functionality. (Loads the compatiability processor).
        '''
        extensions = [
            'markdown.extensions.codehilite', 'markdown.extensions.fenced_code'
        ]
        verto_extension = VertoExtension([self.processor_name], {}, extensions)
        test_string = self.read_test_file(self.processor_name,
                                          'example_multiple_codeblocks_2.md')

        converted_test_string = markdown.markdown(test_string,
                                                  extensions=extensions +
                                                  [verto_extension])
        expected_string = self.read_test_file(
            self.processor_name,
            'example_multiple_codeblocks_expected_2.html',
            strip=True)
        self.assertEqual(expected_string, converted_test_string)

        actual_scratch_images = verto_extension.required_files[
            'scratch_images']
        expected_scratch_images = {
            ScratchImageMetaData(
                hash=
                'a3b77ed3c3fa57e43c830e338dc39d292c7def676e0e8f7545972b7da20275da',
                text='when flag clicked\nsay [Hi]'),
            ScratchImageMetaData(
                hash=
                'cd6d9a0d464bb8f5eec1e6fc9a4e33378a64ebfce7c6198794ead614962f38e5',
                text=
                'when flag clicked\nsay [Hi]\nmove (foo) steps\nturn ccw (9) degrees'
            ),
            ScratchImageMetaData(
                hash=
                '8e8a2129c3cecf32101248439961735fc1d45793fadc56e2575673f63d42b9fb',
                text=
                'when flag clicked\nclear\nforever\npen down\n\nif <<mouse down?> and <touching [mouse-pointer v]?>> then\nswitch costume to [button v]\nelse\nadd (x position) to [list v]\nend\n\nmove (foo) steps\nturn ccw (9) degrees'
            ),
        }
        self.assertSetEqual(actual_scratch_images, expected_scratch_images)
Exemplo n.º 9
0
    def test_example_split_codeblocks_compatibility(self):
        '''Tests that options are compatible with codehilite.
        '''
        extensions = [
            'markdown.extensions.codehilite', 'markdown.extensions.fenced_code'
        ]
        verto_extension = VertoExtension([self.processor_name], {}, extensions)
        test_string = self.read_test_file(self.processor_name,
                                          'example_split_codeblocks.md')

        converted_test_string = markdown.markdown(test_string,
                                                  extensions=extensions +
                                                  [verto_extension])
        expected_string = self.read_test_file(
            self.processor_name,
            'example_split_codeblocks_expected.html',
            strip=True)
        self.assertEqual(expected_string, converted_test_string)

        actual_scratch_images = verto_extension.required_files[
            'scratch_images']
        expected_scratch_images = {
            ScratchImageMetaData(
                hash=
                'a3b77ed3c3fa57e43c830e338dc39d292c7def676e0e8f7545972b7da20275da',
                text='when flag clicked\nsay [Hi]'),
            ScratchImageMetaData(
                hash=
                'cd6d9a0d464bb8f5eec1e6fc9a4e33378a64ebfce7c6198794ead614962f38e5',
                text=
                'when flag clicked\nsay [Hi]\nmove (foo) steps\nturn ccw (9) degrees'
            ),
            ScratchImageMetaData(
                hash=
                'a0f8fcad796864abfacac8bda6e0719813833fd1fca348700abbd040557c1576',
                text=
                'when flag clicked\nclear\nforever\npen down\nif <<mouse down?> and <touching [mouse-pointer v]?>> then\nswitch costume to [button v]\nelse\nadd (x position) to [list v]\nend\nmove (foo) steps\nturn ccw (9) degrees'
            ),
        }
        self.assertSetEqual(actual_scratch_images, expected_scratch_images)
Exemplo n.º 10
0
    def test_mixed_codeblocks(self):
        '''Tests that normal codeblocks are not inadvertently effected.'''
        extensions = ['markdown.extensions.fenced_code']
        verto_extension = VertoExtension([self.processor_name], {}, extensions)
        test_string = self.read_test_file(self.processor_name,
                                          'mixed_codeblocks.md')

        converted_test_string = markdown.markdown(test_string,
                                                  extensions=extensions +
                                                  [verto_extension])
        expected_string = self.read_test_file(self.processor_name,
                                              'mixed_codeblocks_expected.html',
                                              strip=True)
        self.assertEqual(expected_string, converted_test_string)

        actual_scratch_images = verto_extension.required_files[
            'scratch_images']
        expected_scratch_images = {
            ScratchImageMetaData(
                hash=
                '9dabe0bac28bc3a143cfb19c2e5d7f46aae62b3d793166a56665a789d0df5bf7',
                text='say [Hello]')
        }
        self.assertSetEqual(actual_scratch_images, expected_scratch_images)
Exemplo n.º 11
0
    def test_multiple_calls(self):
        '''Checks all fields of VertoResult are correct for multiple Verto calls.
        '''
        test_cases = [
            ('all_processors.md',
             VertoResult(
                 html_string=self.read_test_file(
                     self.test_name,
                     'all_processors_expected.html',
                     strip=True),
                 title='Example Title',
                 required_files={
                     'interactives': {'binary-cards'},
                     'images': set(),
                     'page_scripts': set(),
                     'scratch_images': {
                         ScratchImageMetaData(
                             hash=
                             'a0f8fcad796864abfacac8bda6e0719813833fd1fca348700abbd040557c1576',
                             text
                             ='when flag clicked\nclear\nforever\npen down\nif <<mouse down?> and <touching [mouse-pointer v]?>> then\nswitch costume to [button v]\nelse\nadd (x position) to [list v]\nend\nmove (foo) steps\nturn ccw (9) degrees'
                         ),
                     }
                 },
                 heading_tree=(
                     HeadingNode(
                         title='Example Title',
                         title_slug='example-title',
                         level=1,
                         children=(),
                     ),
                     HeadingNode(title='Example Title 2',
                                 title_slug='example-title-2',
                                 level=1,
                                 children=()),
                 ),
                 required_glossary_terms={'algorithm': []})),
            ('some_processors.md',
             VertoResult(
                 html_string=self.read_test_file(
                     self.test_name,
                     'some_processors_expected.html',
                     strip=
                     True),
                 title='Another Example Title',
                 required_files={
                     'interactives': set(),
                     'images':
                     {'totally-legit-image.png'},
                     'page_scripts': set(),
                     'scratch_images':
                     set()
                 },
                 heading_tree=
                 (HeadingNode(
                     title='Another Example Title',
                     title_slug
                     ='another-example-title',
                     level=1,
                     children=(HeadingNode(
                         title='This is an H2',
                         title_slug
                         ='this-is-an-h2',
                         level=2,
                         children=(
                         )), ),
                 ), ),
                 required_glossary_terms={
                     'chomsky-hierarchy':
                     [('Formal languages', 'glossary-chomsky-hierarchy')]
                 })),
            ('some_processors_2.md',
             VertoResult(
                 html_string=self.read_test_file(
                     self.test_name,
                     'some_processors_2_expected.html',
                     strip=
                     True),
                 title='Another Example Title',
                 required_files={
                     'interactives': set(),
                     'images':
                     {
                         'totally-legit-image.png',
                         'finite-state-automata-no-trap-example.png',
                         'finite-state-automata-trap-added-example.png',
                         'finite-state-automata-trap-added-extreme-example.png',
                     },
                     'page_scripts': set(),
                     'scratch_images': set()
                 },
                 heading_tree=(HeadingNode(
                     title='Another Example Title',
                     title_slug='another-example-title',
                     level=1,
                     children=(),
                 ), ),
                 required_glossary_terms={
                     'hello': [],
                     'algorithm':
                     [('computer program', 'glossary-algorithm'),
                      ('algorithm cost', 'glossary-algorithm-2'),
                      ('searching algorithms', 'glossary-algorithm-3'),
                      ('sorting algorithms', 'glossary-algorithm-4')]
                 }))
        ]

        verto = Verto()
        for filename, expected_result in test_cases:
            test_string = self.read_test_file(self.test_name, filename)
            verto_result = verto.convert(test_string)

            self.assertEqual(verto_result.title, expected_result.title)
            self.assertEqual(verto_result.required_files,
                             expected_result.required_files)
            self.assertTupleEqual(verto_result.heading_tree,
                                  expected_result.heading_tree)
            self.assertDictEqual(verto_result.required_glossary_terms,
                                 expected_result.required_glossary_terms)
            verto.clear_saved_data()
Exemplo n.º 12
0
    def test_multiple_calls_without_clearing(self):
        '''Tests that if the verto extension is not cleared that information such as required_files and slugs are persistent.
        '''
        filename = 'all_processors.md'
        other_filename = 'otherfile.md'
        expected_result = VertoResult(
            html_string=self.read_test_file(self.test_name,
                                            'all_processors_expected.html',
                                            strip=True),
            title='Example Title',
            required_files={
                'interactives': {'binary-cards'},
                'images': set(),
                'page_scripts': set(),
                'scratch_images': {
                    ScratchImageMetaData(
                        hash=
                        'a0f8fcad796864abfacac8bda6e0719813833fd1fca348700abbd040557c1576',
                        text=
                        'when flag clicked\nclear\nforever\npen down\nif <<mouse down?> and <touching [mouse-pointer v]?>> then\nswitch costume to [button v]\nelse\nadd (x position) to [list v]\nend\nmove (foo) steps\nturn ccw (9) degrees'
                    ),
                }
            },
            heading_tree=(
                HeadingNode(
                    title='Example Title',
                    title_slug='example-title',
                    level=1,
                    children=(),
                ),
                HeadingNode(title='Example Title 2',
                            title_slug='example-title-2',
                            level=1,
                            children=()),
            ),
            required_glossary_terms={'algorithm': []})
        expected_otherfile_result = VertoResult(
            html_string=self.read_test_file(self.test_name,
                                            'otherfile_expected.html',
                                            strip=True),
            title='Example Title',
            required_files={
                'interactives': {'binary-cards'},
                'images': {'pixel-diamond.png'},
                'page_scripts': set(),
                'scratch_images': {
                    ScratchImageMetaData(
                        hash=
                        'a0f8fcad796864abfacac8bda6e0719813833fd1fca348700abbd040557c1576',
                        text=
                        'when flag clicked\nclear\nforever\npen down\nif <<mouse down?> and <touching [mouse-pointer v]?>> then\nswitch costume to [button v]\nelse\nadd (x position) to [list v]\nend\nmove (foo) steps\nturn ccw (9) degrees'
                    ),
                    ScratchImageMetaData(
                        hash=
                        'b78bff524e54a18116e1e898a93e360827f874a8b0b508e1edc47d21516495ad',
                        text='never\ngoing\nto\ngive\nyou\nup'),
                }
            },
            heading_tree=(HeadingNode(
                title='Example Title',
                title_slug='example-title-3',
                level=1,
                children=(),
            ), ),
            required_glossary_terms={'algorithm': []})

        verto = Verto()
        # First file
        test_string = self.read_test_file(self.test_name, filename)
        verto_result = verto.convert(test_string)

        self.assertEqual(verto_result.title, expected_result.title)
        self.assertEqual(verto_result.required_files,
                         expected_result.required_files)
        self.assertTupleEqual(verto_result.heading_tree,
                              expected_result.heading_tree)
        self.assertDictEqual(verto_result.required_glossary_terms,
                             expected_result.required_glossary_terms)

        # Another file
        test_string = self.read_test_file(self.test_name, other_filename)
        verto_result = verto.convert(test_string)

        self.assertEqual(verto_result.title, expected_otherfile_result.title)
        self.assertEqual(verto_result.required_files,
                         expected_otherfile_result.required_files)
        self.assertTupleEqual(verto_result.heading_tree,
                              expected_otherfile_result.heading_tree)
        self.assertDictEqual(verto_result.required_glossary_terms,
                             expected_otherfile_result.required_glossary_terms)