Exemple #1
0
 def test_store_different_versions(self, cache_settings):
     """Show that a new vesion of a document gets added to the cache while keeping the old version too.
     """
     path = os.path.join(config.module_dir, "test", "assets",
                         "da-49-l1q1.xml")
     res = LocalResource(path)
     Tex(res).process(output_format="tex")
     modified_path = os.path.join(config.module_dir, "test", "assets",
                                  "da-49-l1q1-modified.xml")
     modified_res = LocalResource(modified_path)
     Tex(modified_res).process(output_format="tex")
     assert len(os.listdir(config.cache_dir)) == 2
Exemple #2
0
def main():

    args = setup_arguments(docopt(__doc__, version=__version__))

    # Setup logging according to configuration
    logger.setLevel(args["--verbosity"].upper())
    logger.debug("Logging initialized at debug level.")

    # Initialize the object
    transcriptions = []
    if args["--scta"]:
        for num, exp in enumerate(args["<id>"], 1):
            logger.info(f'Initializing {exp}. [{num}/{len(args["<id>"])}]')
            transcriptions.append(
                RemoteResource(exp, custom_xslt=args["--xslt"]))
    elif args["--local"]:
        for num, exp in enumerate(args["<file>"], 1):
            logger.info(f'Initializing {exp}. [{num}/{len(args["<file>"])}]')
            transcriptions.append(
                LocalResource(exp, custom_xslt=args["--xslt"]))

    if args["pdf"]:
        output_format = "pdf"
    elif args["tex"]:
        output_format = "tex"
    else:
        output_format = None

    for num, item in enumerate(transcriptions, 1):
        # Determine xslt script file (either provided or selected based on the xml transcription)
        logger.info("-------")
        logger.info(f"Processing {item.input}. [{num}/{len(transcriptions)}]")

        if args["--xslt"]:
            item.xslt = item.select_xlst_script(args["--xslt"])

        if args["--no-cache"]:
            caching = False
        else:
            caching = True

        if args["--no-samewords"]:
            samewords = False
        else:
            samewords = True

        result_file = Tex(
            item,
            xslt_parameters=args["--xslt-parameters"],
            enable_caching=caching,
            annotate_samewords=samewords,
        ).process(output_format=output_format)

        # Handle output dir
        # output_dir=args["--output"]

        logger.info("Results returned sucessfully.\n "
                    "The output file is located at %s" %
                    os.path.abspath(result_file))
Exemple #3
0
 def test_store_in_cache_after_processing(self, cache_settings):
     """Show that a document is stored in the cache after processing."""
     path = os.path.join(config.module_dir, "test", "assets",
                         "da-49-l1q1.xml")
     res = LocalResource(path)
     Tex(res).process(output_format="tex")
     assert os.path.isfile(
         os.path.join(config.cache_dir, res.digest + ".tex"))
Exemple #4
0
    def test_log_analysis_with_failing_errors(self):
        """Test that the error from Saxon is raised and the process stopped."""

        path = os.path.join(config.module_dir, "test", "assets",
                            "da-49-l1q1.xml")
        xslt_file = os.path.join(config.module_dir, "test", "assets",
                                 "invalid.xslt")
        res = LocalResource(path, custom_xslt=xslt_file)
        with pytest.raises(lbp_exceptions.SaxonError):
            Tex(res, enable_caching=False).process(output_format="tex")
Exemple #5
0
    def test_log_analysis_without_failing_errors(self, caplog):
        """Test that the log contains recoverable error records, and that it completes 
        successfully.
        """
        log_error = "Recoverable error on line 1503 of critical.xslt:"

        path = os.path.join(config.module_dir, "test", "assets",
                            "da-49-l1q1.xml")
        res = LocalResource(path)
        Tex(res, enable_caching=False).process(output_format="tex")
        assert log_error in caplog.text
Exemple #6
0
 def test_create_tex_file_from_url(self):
     output_file = Tex(self.url_resource).process(output_format="tex")
     assert os.path.isfile(output_file)
     assert os.path.splitext(output_file)[1] == ".tex"
Exemple #7
0
 def test_create_tex_file_from_remote(self):
     """Make sure that the return value of the tex compilation is a tex file."""
     output_file = Tex(self.local).process(output_format="tex")
     assert os.path.isfile(output_file)
     assert os.path.splitext(output_file)[1] == ".tex"
Exemple #8
0
 def clean(self, content: str) -> str:
     with tempfile.NamedTemporaryFile(mode="w+") as fh:
         fh.writelines(content)
         fh.seek(0)
         Tex(self.local).whitespace_cleanup(fh.name)
         return fh.read()