Beispiel #1
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),
     )
Beispiel #2
0
 def test_parse_raw_config(self):
     "test parsing a raw config of all the different value types"
     # override the library values
     conf.BOOLEAN_VALUES = [u"test_boolean"]
     conf.INT_VALUES = [u"test_int"]
     conf.LIST_VALUES = [u"test_list"]
     # build a config object
     config = configparser.ConfigParser(interpolation=None)
     config["DEFAULT"][u"test_boolean"] = self.boolean_value
     config["DEFAULT"][u"test_int"] = self.int_value
     config["DEFAULT"][u"test_list"] = self.list_value
     # parse the raw config for coverage
     config_dict = conf.parse_raw_config(config["DEFAULT"])
     # assert some things
     self.assertIsNotNone(config_dict)
     self.assertEqual(config_dict.get("test_boolean"),
                      self.boolean_expected)
     self.assertEqual(config_dict.get("test_int"), self.int_expected)
     self.assertEqual(config_dict.get("test_list"), self.list_expected)
 def test_build_digest(self, test_data):
     "check building a digest object from a DOCX file"
     # note: below after 'the' is a unicode non-breaking space character
     expected_author = u"Anonymous"
     expected_title = u"Fishing for errors in the\xa0tests"
     expected_summary = (
         u"Testing a document which mimics the format of a file we’ve used  "
         + "before plus CO<sub>2</sub> and Ca<sup>2+</sup>.")
     expected_keywords = ["Face Recognition", "Neuroscience", "Vision"]
     expected_doi = u"https://doi.org/10.7554/eLife.99999"
     expected_text_len = 3
     expected_text_0 = read_fixture(
         "digest_content_99999_text_1.txt").decode("utf-8")
     expected_text_1 = read_fixture(
         "digest_content_99999_text_2.txt").decode("utf-8")
     expected_text_2 = read_fixture(
         "digest_content_99999_text_3.txt").decode("utf-8")
     expected_image_caption = (
         u"<b>It’s not just mammals who can recognise sample data.</b>" +
         u"\xa0Image credit:\xa0Anonymous and Anonymous\xa0(CC BY\xa04.0)")
     # build now
     digest_config = parse_raw_config(
         raw_config(test_data.get("config_section")))
     digest = build.build_digest(data_path(test_data.get("file_name")),
                                 "tmp", digest_config)
     # assert assertions
     self.assertIsNotNone(digest)
     self.assertEqual(digest.author, expected_author)
     self.assertEqual(digest.title, expected_title)
     self.assertEqual(digest.summary, expected_summary)
     self.assertEqual(digest.keywords, expected_keywords)
     self.assertEqual(digest.doi, expected_doi)
     self.assertEqual(len(digest.text), expected_text_len)
     self.assertEqual(digest.text[0], expected_text_0)
     self.assertEqual(digest.text[1], expected_text_1)
     self.assertEqual(digest.text[2], expected_text_2)
     if digest.image:
         self.assertEqual(digest.image.caption, expected_image_caption)
         if test_data.get("image_file"):
             expected_image_file = os.path.join("tmp",
                                                test_data.get("image_file"))
             self.assertEqual(digest.image.file, expected_image_file)
Beispiel #4
0
 def test_build_json(self, test_data, fake_iiif_server_info):
     "check building a JSON from a DOCX file"
     fake_iiif_server_info.return_value = test_data.get("iiif_info")
     file_name = data_path(test_data.get("file_name"))
     jats_file = fixture_file(test_data.get("jats_file"))
     expected_json = read_fixture(test_data.get("expected_json_file"))
     # config
     digest_config = parse_raw_config(
         raw_config(test_data.get("config_section")))
     image_file_name = test_data.get("image_file_name")
     related = test_data.get("related")
     # build now
     json_content = json_output.build_json(file_name, "tmp", digest_config,
                                           jats_file, image_file_name,
                                           related)
     # assert assertions
     self.assertEqual(
         json_content,
         expected_json,
         "failed in {comment}".format(comment=test_data.get("comment")),
     )
 def setUp(self):
     self.digest_config = parse_raw_config(raw_config("elife"))