def test_script_defaults(): ip = get_ipython() for cmd in ['sh', 'bash', 'perl', 'ruby']: try: find_cmd(cmd) except Exception: pass else: nt.assert_in(cmd, ip.magics_manager.magics['cell'])
def kpsewhich(filename): """Invoke kpsewhich command with an argument `filename`.""" try: find_cmd("kpsewhich") proc = subprocess.Popen(["kpsewhich", filename], stdout=subprocess.PIPE, stderr=subprocess.PIPE) (stdout, stderr) = proc.communicate() return stdout.strip().decode('utf8', 'replace') except FindCmdError: pass
def test_exit_code_signal_csh(self): SHELL = os.environ.get('SHELL', None) os.environ['SHELL'] = find_cmd("csh") try: self.test_exit_code_signal() finally: if SHELL is not None: os.environ['SHELL'] = SHELL else: del os.environ['SHELL']
def latex_to_png_dvipng(s, wrap): try: find_cmd('latex') find_cmd('dvipng') except FindCmdError: return None try: workdir = tempfile.mkdtemp() tmpfile = os.path.join(workdir, "tmp.tex") dvifile = os.path.join(workdir, "tmp.dvi") outfile = os.path.join(workdir, "tmp.png") with open(tmpfile, "w", encoding='utf8') as f: f.writelines(genelatex(s, wrap)) with open(os.devnull, 'wb') as devnull: subprocess.check_call([ "latex", "-halt-on-error", "-interaction", "batchmode", tmpfile ], cwd=workdir, stdout=devnull, stderr=devnull) subprocess.check_call([ "dvipng", "-T", "tight", "-x", "1500", "-z", "9", "-bg", "transparent", "-o", outfile, dvifile ], cwd=workdir, stdout=devnull, stderr=devnull) with open(outfile, "rb") as f: return f.read() except subprocess.CalledProcessError: return None finally: shutil.rmtree(workdir)
def test_find_cmd_pythonw(): """Try to find pythonw on Windows.""" path = find_cmd('pythonw') assert path.lower().endswith('pythonw.exe'), path
def test_find_cmd_ls(): """Make sure we can find the full path to ls.""" path = find_cmd('ls') nt.assert_true(path.endswith('ls'))