Esempio n. 1
0
 def test_only_uxid(self):
     annot = pf.Div(
         identifier="{}-foo".format(SITE_UXID_PREFIX),
         classes=(SITE_UXID_PREFIX, ),
     )
     identifier = extract_identifier([annot])
     self.assertEqual(identifier, "foo")
Esempio n. 2
0
def create_content_box(elem_content, elem_classes, lang):
    """
    Create a content box.

    Convenience function for creating content boxes that only differ
    by having diffent content and classes.
    """
    if not elem_classes or elem_classes == []:
        msg = "create_content_box without element classes: {}".format(elem_classes)
        raise ValueError(msg)

    if not elem_content or elem_content == "":
        msg = "create_content_box without element content: {}".format(elem_content)
        raise ValueError(msg)

    div = pf.Div(classes=elem_classes)
    content = parse_fragment(elem_content, lang)

    # Check if environment had an \MLabel/SiteUXID identifier
    identifier = extract_identifier(content)
    if identifier:
        div.identifier = identifier

    div.content.extend(content)
    return div
Esempio n. 3
0
 def test_uxid_para(self):
     annot = pf.Div(
         identifier="{}-foo".format(SITE_UXID_PREFIX),
         classes=(SITE_UXID_PREFIX, ),
     )
     para = pf.Para(pf.Str("bar"))
     identifier = extract_identifier([annot, para])
     self.assertEqual(identifier, "foo")
Esempio n. 4
0
 def handle_mexercises(self, elem_content, env_args, elem):
     r"""Handle ``\MExercises`` environment."""
     content = parse_fragment(elem_content, elem.doc.metadata["lang"].text)
     lang = elem.doc.metadata["lang"].text
     header = create_header(TRANSLATIONS["exercises"][lang],
                            elem.doc,
                            level=3)
     identifier = extract_identifier(content)
     if identifier:
         header.identifier = identifier
     # pylint: disable=no-member
     header.classes.extend(ELEMENT_CLASSES["MEXERCISES"])
     content.insert(0, header)
     return content
Esempio n. 5
0
 def handle_mcontent(self, elem_content, env_args, elem):
     r"""Handle ``\MContent`` environment."""
     content = parse_fragment(elem_content, elem.doc.metadata["lang"].text)
     lang = elem.doc.metadata["lang"].text
     header = create_header(
         TRANSLATIONS["content"][lang],
         elem.doc,
         level=3,
         identifier="content",
     )
     identifier = extract_identifier(content)
     if identifier:
         header.identifier = identifier
     content.insert(0, header)
     return content
Esempio n. 6
0
 def handle_mintro(self, elem_content, env_args, elem):
     r"""Handle ``\MIntro`` environment."""
     content = parse_fragment(elem_content, elem.doc.metadata["lang"].text)
     lang = elem.doc.metadata["lang"].text
     header = create_header(
         TRANSLATIONS["introduction"][lang],
         elem.doc,
         level=3,
         identifier="introduction",
     )
     identifier = extract_identifier(content)
     if identifier:
         header.identifier = identifier
     # pylint: disable=no-member
     header.classes.extend(ELEMENT_CLASSES["MINTRO"])
     content.insert(0, header)
     return content
Esempio n. 7
0
    def handle_mxcontent(self, elem_content, env_args, elem):
        r"""Handle ``\MXContent`` environment."""
        content = parse_fragment(elem_content, elem.doc.metadata["lang"].text)

        # special case: Skip header creation for some weird (meta?) caption in
        # entrance test.
        if env_args[0] != "Restart" and env_args[0] != "Neustart":
            header = create_header(env_args[0],
                                   elem.doc,
                                   level=3,
                                   short_title=env_args[1])
            identifier = extract_identifier(content)
            if identifier:
                header.identifier = identifier
            content.insert(0, header)

        return content
Esempio n. 8
0
    def test_uxid_label_para(self):
        mlabel = pf.Div(
            identifier="{}-foo".format(INDEX_LABEL_PREFIX),
            classes=(INDEX_LABEL_PREFIX, ),
        )
        uxid = pf.Div(
            identifier="{}-bar".format(SITE_UXID_PREFIX),
            classes=(SITE_UXID_PREFIX, ),
        )
        para = pf.Para(pf.Str("bar"))

        tests = (
            ("(mlabel,uxid,para)", "foo", [mlabel, uxid, para]),
            ("(uxid,mlabel,para)", "foo", [uxid, mlabel, para]),
            ("(uxid,para)", "bar", [uxid, para]),
            ("(para)", None, [para]),
        )

        for name, exp_id, test in tests:
            with self.subTest("{} expected: {}".format(name, exp_id)):
                identifier = extract_identifier(test)
                self.assertEqual(identifier, exp_id)
Esempio n. 9
0
    def handle_mtest(self, elem_content, env_args, elem):
        r"""Handle ``\MTest`` environment."""
        content = parse_fragment(elem_content, elem.doc.metadata["lang"].text)
        title = env_args[0]

        # Normalize various forms of inconsistent titles
        if "Abschlusstest" in title:  # Final test
            title = "Abschlusstest"
        elif "Final Test" in title:
            title = "Final Test"
        elif "Eingangstest" in title:  # Entrance test
            title = "Test 1: Abzugebender Teil"
        elif "Graded Test" in title:
            title = "Test 1: Graded Part To Be Submitted"

        header = create_header(title, elem.doc, level=2)
        identifier = extract_identifier(content)
        if identifier:
            header.identifier = identifier

        # pylint: disable=no-member
        header.classes.extend(ELEMENT_CLASSES["MTEST"])
        content.insert(0, header)
        return content