How to use the testpath.tempdir.TemporaryWorkingDirectory function in testpath

To help you get started, we’ve selected a few testpath examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github jupyter / testpath / testpath / tempdir.py View on Github external
def __enter__(self):
        self.old_wd = _os.getcwd()
        _os.chdir(self.name)
        return super(TemporaryWorkingDirectory, self).__enter__()
github cuthbertLab / music21 / music21 / ext / nbconvert / exporters / pdf.py View on Github external
def from_notebook_node(self, nb, resources=None, **kw):
        latex, resources = super(PDFExporter, self).from_notebook_node(
            nb, resources=resources, **kw
        )
        # set texinputs directory, so that local files will be found
        if resources and resources.get('metadata', {}).get('path'):
            self.texinputs = resources['metadata']['path']
        else:
            self.texinputs = getcwd()
        
        self._captured_outputs = []
        with TemporaryWorkingDirectory():
            notebook_name = 'notebook'
            tex_file = self.writer.write(latex, resources, notebook_name=notebook_name)
            self.log.info("Building PDF")
            rc = self.run_latex(tex_file)
            if rc:
                rc = self.run_bib(tex_file)
            if rc:
                rc = self.run_latex(tex_file)
            
            pdf_file = notebook_name + '.pdf'
            if not os.path.isfile(pdf_file):
                raise LatexFailed('\n'.join(self._captured_output))
            self.log.info('PDF successfully created')
            with open(pdf_file, 'rb') as f:
                pdf_data = f.read()

testpath

Test utilities for code working with files and commands

BSD-3-Clause
Latest version published 2 years ago

Package Health Score

55 / 100
Full package analysis

Similar packages