def test_component_subtitle_with_face_markup(self):
     """build an article object and component, generate Crossref XML"""
     doi = "10.7554/eLife.00666"
     title = "Test article"
     article = Article(doi, title)
     component = Component()
     component.title = "A component"
     component.subtitle = (
         "A <sc>STRANGE</sc> <italic>subtitle</italic>, " +
         "and this tag is <not_allowed>!</not_allowed>")
     expected_subtitle = (
         "A <sc>STRANGE</sc> <i>subtitle</i>, and this tag " +
         "is &lt;not_allowed&gt;!&lt;/not_allowed&gt;")
     article.component_list = [component]
     # load a config and override the value
     raw_config_object = raw_config("elife")
     face_markup = raw_config_object.get("face_markup")
     raw_config_object["face_markup"] = "true"
     crossref_config = parse_raw_config(raw_config_object)
     # generate the crossrefXML
     c_xml = generate.CrossrefXML([article], crossref_config, None, True)
     crossref_xml_string = c_xml.output_xml()
     self.assertIsNotNone(crossref_xml_string)
     # A quick test just look for the expected string to test for tags and escape characters
     self.assertTrue(expected_subtitle in crossref_xml_string)
     # now set the config back to normal
     raw_config_object["face_markup"] = face_markup
 def test_set_abstract_jats_abstract_format(self):
     """test the abstract using jats abstract format set to true"""
     doi = "10.7554/eLife.00666"
     title = "Test article"
     article = Article(doi, title)
     article.abstract = self.abstract
     article.abstract_xml = self.abstract_xml
     expected_contains = (
         '<jats:abstract xmlns:xlink="http://www.w3.org/1999/xlink">'
         '<jats:p xmlns:xlink="http://www.w3.org/1999/xlink">'
         "<jats:bold><jats:italic><jats:underline><jats:sub><jats:sup>"
         "An abstract. "
         '<jats:ext-link ext-link-type="uri" xlink:href="http://dx.doi.org/10.1601/nm.3602">'
         "Desulfocapsa sulfexigens</jats:ext-link>."
         "</jats:sup></jats:sub></jats:underline></jats:italic></jats:bold> "
         '<jats:xref ref-type="bibr">Stock and Wise (1990)</jats:xref>.'
         "</jats:p></jats:abstract>"
     )
     # generate
     raw_config_object = raw_config("elife")
     jats_abstract = raw_config_object.get("jats_abstract")
     raw_config_object["jats_abstract"] = "true"
     crossref_config = parse_raw_config(raw_config_object)
     crossref_object = generate.CrossrefXML([article], crossref_config, None, True)
     crossref_xml_string = crossref_object.output_xml()
     # test assertion
     self.assertTrue(expected_contains in crossref_xml_string)
     # now set the config back to normal
     raw_config_object["jats_abstract"] = jats_abstract
Beispiel #3
0
def crossref_xml(
    poa_articles,
    crossref_config=None,
    pub_date=None,
    add_comment=True,
    submission_type="journal",
    pretty=False,
    indent="",
):
    """build crossref xml and return output as a string"""
    if not crossref_config:
        crossref_config = parse_raw_config(raw_config(None))
    c_xml = build_crossref_xml(poa_articles, crossref_config, pub_date,
                               add_comment, submission_type)
    return c_xml.output_xml(pretty=pretty, indent=indent)
Beispiel #4
0
def build_crossref_xml(
    poa_articles,
    crossref_config=None,
    pub_date=None,
    add_comment=True,
    submission_type="journal",
):
    """
    Given a list of article article objects
    generate crossref XML from them
    """
    if not crossref_config:
        crossref_config = parse_raw_config(raw_config(None))
    return CrossrefXML(poa_articles, crossref_config, pub_date, add_comment,
                       submission_type)
 def test_set_titles_face_markup_format(self):
     """test the title using face markup set to true"""
     doi = "10.7554/eLife.00666"
     article = Article(doi, self.title)
     expected_contains = ("<titles><title><b>Test article</b> for"
                          " Desulfocapsa sulfexigens</title></titles>")
     # generate
     raw_config_object = raw_config("elife")
     face_markup = raw_config_object.get("face_markup")
     raw_config_object["face_markup"] = "true"
     crossref_config = parse_raw_config(raw_config_object)
     crossref_object = generate.CrossrefXML([article], crossref_config,
                                            None, True)
     crossref_xml_string = crossref_object.output_xml()
     # test assertion
     self.assertTrue(expected_contains in crossref_xml_string)
     # now set the config back to normal
     raw_config_object["face_markup"] = face_markup
Beispiel #6
0
def crossref_xml_to_disk(
    poa_articles,
    crossref_config=None,
    pub_date=None,
    add_comment=True,
    submission_type="journal",
    pretty=False,
    indent="",
):
    """build crossref xml and write the output to disk"""
    if not crossref_config:
        crossref_config = parse_raw_config(raw_config(None))
    c_xml = build_crossref_xml(poa_articles, crossref_config, pub_date,
                               add_comment, submission_type)
    xml_string = c_xml.output_xml(pretty=pretty, indent=indent)
    # Write to file
    filename = TMP_DIR + os.sep + c_xml.batch_id + ".xml"
    with open(filename, "wb") as open_file:
        open_file.write(xml_string.encode("utf-8"))
 def test_ref_list_citation_elocation_id(self):
     """for test coverage for schema where elocation_id goes into first_page element"""
     # load a config and override the value
     raw_config_object = raw_config("elife")
     original_schema_version = raw_config_object.get(
         "crossref_schema_version")
     raw_config_object["crossref_schema_version"] = "4.4.0"
     crossref_config = parse_raw_config(raw_config_object)
     doi = "10.7554/eLife.00666"
     title = "Test article"
     article = Article(doi, title)
     citation = Citation()
     citation.elocation_id = "e00003"
     article.ref_list = [citation]
     c_xml = generate.CrossrefXML([article], crossref_config, None, True)
     crossref_xml_string = c_xml.output_xml()
     self.assertTrue(
         "<first_page>e00003</first_page>" in crossref_xml_string)
     # now set the config back to normal
     raw_config_object["crossref_schema_version"] = original_schema_version
 def generate_crossref_schema_version(self, crossref_schema_version,
                                      expected_snippet):
     """Test non-default crossref schema version"""
     # build an article object and component, generate Crossref XML
     doi = "10.7554/eLife.00666"
     title = "Test article"
     article = Article(doi, title)
     # load a config and override the value
     raw_config_object = raw_config("elife")
     original_schema_version = raw_config_object.get(
         "crossref_schema_version")
     raw_config_object["crossref_schema_version"] = crossref_schema_version
     crossref_config = parse_raw_config(raw_config_object)
     # generate the crossrefXML
     c_xml = generate.CrossrefXML([article], crossref_config, None, True)
     crossref_xml_string = c_xml.output_xml()
     self.assertIsNotNone(crossref_xml_string)
     # A quick test just look for a string value to test
     self.assertTrue(expected_snippet in crossref_xml_string)
     # now set the config back to normal
     raw_config_object["crossref_schema_version"] = original_schema_version
Beispiel #9
0
def create_crossref_config(config_section="elife"):
    """utility to create the crossref object"""
    raw_config_object = raw_config(config_section)
    return parse_raw_config(raw_config_object)
    XML_FILES.append([
        "tests/test_data/elife-16988-v1.xml", "elife", DEFAULT_PUB_DATE, False
    ])
    XML_FILES.append([
        "tests/test_data/elife-11134-v2.xml", "elife", DEFAULT_PUB_DATE, False
    ])
    XML_FILES.append([
        "tests/test_data/elife-00508-v1.xml", "elife", DEFAULT_PUB_DATE, False
    ])
    XML_FILES.append(
        ["tests/test_data/cstp77-jats.xml", "cstp", DEFAULT_PUB_DATE, False])
    XML_FILES.append([
        "tests/test_data/bmjopen-4-e003269.xml", "bmjopen", DEFAULT_PUB_DATE,
        False
    ])
    XML_FILES.append(
        ["tests/test_data/up-sta-example.xml", None, DEFAULT_PUB_DATE, False])
    for xml_file, config_section, pub_date, add_comment in XML_FILES:
        generate.TMP_DIR = "tests/test_data"
        articles = generate.build_articles_for_crossref([xml_file])
        crossref_config = parse_raw_config(raw_config(config_section))
        generate.crossref_xml_to_disk(
            articles,
            crossref_config,
            pub_date,
            add_comment,
            "journal",
            pretty=True,
            indent="\t",
        )