示例#1
0
def build_digest(file_name,
                 temp_dir="tmp",
                 digest_config=None,
                 image_file_name=None):
    "build a digest object from a DOCX input file"
    digest = None
    docx_file_name, zip_image_file_name = handle_zip(file_name, temp_dir)
    LOGGER.info("build_digest file '%s' has docx_file_name: '%s'", file_name,
                docx_file_name)
    LOGGER.info(
        "build_digest file '%s' has zip_image_file_name: '%s'",
        file_name,
        zip_image_file_name,
    )
    if not image_file_name:
        image_file_name = zip_image_file_name
    content = parse_content(docx_file_name)
    if content:
        digest = Digest()
        digest.author = build_author(content)
        digest.title = build_title(content)
        digest.summary = build_summary(content)
        digest.keywords = build_keywords(content)
        digest.manuscript_number = build_manuscript_number(content)
        digest.doi = build_doi(content, digest_config)
        digest.text = build_text(content)
        digest.image = build_image(content, image_file_name)
    return digest
示例#2
0
 def test_docx_file_name(self, test_data):
     "docx output file name tests for various input"
     # build the Digest object
     digest = Digest()
     digest.author = test_data.get("author")
     digest.doi = test_data.get("doi")
     # set the config, if using in the test
     digest_config = None
     if test_data.get("use_config"):
         digest_config = parse_raw_config(
             raw_config(test_data.get("config_section")))
     # generate the file_name
     file_name = output.docx_file_name(digest, digest_config)
     # test assertion
     self.assertEqual(
         file_name,
         test_data.get("expected_file_name"),
         u"failed in scenario '{scenario}', got file_name {file_name}".
         format(scenario=test_data.get("scenario"), file_name=file_name),
     )
     # test for creating the file on disk
     full_file_name = os.path.join("tmp", file_name)
     output_file_name = output.digest_docx(digest, full_file_name)
     self.assertEqual(
         os.path.join("tmp", test_data.get("expected_file_name")),
         output_file_name,
         u"failed creating file in scenario '{scenario}', got file_name {file_name}"
         .format(scenario=test_data.get("scenario"),
                 file_name=output_file_name),
     )