def test_crossref_xml_to_disk(self):
     """test writing to disk for test coverage and also not pass crossref_config"""
     article_xml_file = "up-sta-example.xml"
     crossref_xml_file = "crossref-606-20170717071707.xml"
     crossref_config = None
     pub_date = DEFAULT_PUB_DATE
     file_path = TEST_DATA_PATH + article_xml_file
     # build the article object
     articles = generate.build_articles_for_crossref([file_path])
     # generate and write to disk
     generate.crossref_xml_to_disk(
         articles,
         crossref_config,
         pub_date,
         False,
         "journal",
         pretty=True,
         indent="\t",
     )
     # check the output matches
     expected_output = read_file_content(TEST_DATA_PATH + crossref_xml_file)
     if sys.version_info < (3, 8):
         # pre Python 3.8 tag attributes are in a different order
         expected_output = replace_namespaces(expected_output)
     generated_output = read_file_content(generate.TMP_DIR +
                                          crossref_xml_file)
     self.assertEqual(generated_output, expected_output)
 def test_generate(self):
     for (
             article_xml_file,
             crossref_xml_file,
             config_section,
             pub_date,
     ) in self.passes:
         file_path = TEST_DATA_PATH + article_xml_file
         articles = generate.build_articles_for_crossref([file_path])
         crossref_config = None
         if config_section:
             crossref_config = create_crossref_config(config_section)
         # generate pretty XML
         crossref_xml = generate.crossref_xml(articles,
                                              crossref_config,
                                              pub_date,
                                              False,
                                              pretty=True,
                                              indent="\t")
         model_crossref_xml = read_file_content(TEST_DATA_PATH +
                                                crossref_xml_file)
         if sys.version_info < (3, 8):
             # pre Python 3.8 tag attributes are in a different order
             model_crossref_xml = replace_namespaces(model_crossref_xml)
         self.assertEqual(
             crossref_xml,
             model_crossref_xml.decode("utf-8"),
             "Failed parse test on file %s" % article_xml_file,
         )
 def test_parse_do_no_pass_pub_date(self):
     """
     For test coverage build a crossrefXML object without passing in a pub_date
     """
     article_xml_file = "elife_poa_e02725.xml"
     file_path = TEST_DATA_PATH + article_xml_file
     articles = generate.build_articles_for_crossref([file_path])
     crossref_config = create_crossref_config("elife")
     crossref_object = generate.CrossrefXML(articles, crossref_config, None,
                                            True)
     self.assertIsNotNone(crossref_object.pub_date)
     self.assertIsNotNone(crossref_object.generated)
     self.assertIsNotNone(
         [tag for tag in crossref_object.root.iter() if tag is Comment])
     self.assertIsNotNone(crossref_object.output_xml())
Ejemplo n.º 4
0
def crossref_convert(file_path):
    if not file_path:
        return None
    config_section = 'elife'
    try:
        articles = generate.build_articles_for_crossref([file_path])
    except:
        # parsing failed somehow
        return None
    crossref_config = None
    #if config_section:
    #    crossref_config = parse_raw_config(raw_config(config_section))
    crossref_xml_object = generate.build_crossref_xml(articles, crossref_config)
    crossref_xml = crossref_xml_object.output_xml(pretty=True, indent="\t")
    return crossref_xml
 def test_generate_jats_abstract_face_markup(self):
     """
     For coverage test JATS and inline output by overriding the config
     """
     article_xml_file = "elife-16988-v1.xml"
     file_path = TEST_DATA_PATH + article_xml_file
     articles = generate.build_articles_for_crossref([file_path])
     crossref_config = create_crossref_config("elife")
     # override config values
     crossref_config["jats_abstract"] = True
     crossref_config["face_markup"] = True
     # create the Crossref XML
     crossref_object = generate.CrossrefXML(articles, crossref_config, None,
                                            True)
     # Check for some tags we expect to find in the output
     self.assertTrue("<jats:italic>" in crossref_object.output_xml())
     self.assertTrue("</b>" in crossref_object.output_xml())
    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",
        )