Beispiel #1
0
 def test_getoutput_quoted(self):
     out = getoutput('python -c "print (1)"')
     self.assertEquals(out.strip(), '1')
     out = getoutput("python -c 'print (1)'")
     self.assertEquals(out.strip(), '1')
     out = getoutput("python -c 'print (\"1\")'")
     self.assertEquals(out.strip(), '1')
Beispiel #2
0
def test_profile_create_ipython_dir():
    """ipython profile create respects --ipython-dir"""
    with TemporaryDirectory() as td:
        getoutput([sys.executable, '-m', 'IPython', 'profile', 'create',
             'foo', '--ipython-dir=%s' % td])
        profile_dir = os.path.join(td, 'profile_foo')
        assert os.path.exists(profile_dir)
        ipython_config = os.path.join(profile_dir, 'ipython_config.py')
        assert os.path.exists(ipython_config)
Beispiel #3
0
def test_profile_create_ipython_dir():
    """ipython profile create respects --ipython-dir"""
    with TemporaryDirectory() as td:
        getoutput([sys.executable, '-m', 'IPython', 'profile', 'create',
             'foo', '--ipython-dir=%s' % td])
        profile_dir = os.path.join(td, 'profile_foo')
        assert os.path.exists(profile_dir)
        ipython_config = os.path.join(profile_dir, 'ipython_config.py')
        assert os.path.exists(ipython_config)
Beispiel #4
0
 def test_getoutput(self):
     out = getoutput('%s "%s"' % (python, self.fname))
     # we can't rely on the order the line buffered streams are flushed
     try:
         self.assertEqual(out, 'on stderron stdout')
     except AssertionError:
         self.assertEqual(out, 'on stdouton stderr')
Beispiel #5
0
 def test_getoutput(self):
     out = getoutput('%s "%s"' % (python, self.fname))
     # we can't rely on the order the line buffered streams are flushed
     try:
         self.assertEqual(out, 'on stderron stdout')
     except AssertionError:
         self.assertEqual(out, 'on stdouton stderr')
Beispiel #6
0
def test_profile_create_ipython_dir():
    """ipython profile create respects --ipython-dir"""
    with TemporaryDirectory() as td:
        getoutput([
            sys.executable,
            "-m",
            "IPython",
            "profile",
            "create",
            "foo",
            "--ipython-dir=%s" % td,
        ])
        profile_dir = Path(td) / "profile_foo"
        assert Path(profile_dir).exists()
        ipython_config = profile_dir / "ipython_config.py"
        assert Path(ipython_config).exists()
Beispiel #7
0
def test_profile_create_ipython_dir():
    """ipython profile create respects --ipython-dir"""
    with TemporaryDirectory() as td:
        getoutput(
            [
                sys.executable,
                "-m",
                "IPython",
                "profile",
                "create",
                "foo",
                "--ipython-dir=%s" % td,
            ]
        )
        profile_dir = os.path.join(td, "profile_foo")
        assert os.path.exists(profile_dir)
        ipython_config = os.path.join(profile_dir, "ipython_config.py")
        assert os.path.exists(ipython_config)
Beispiel #8
0
def pandocify(src, lang):
    """use pandoc to convert various things to rst"""
    with tempfile.NamedTemporaryFile(delete=False) as f:
        f.write(src)
        fname = f.name
    
    pandoc = find_cmd('pandoc')
    cmd = "%s -r %s -w rst '%s'" % (pandoc, lang, fname)
    try:
        rst = getoutput(cmd)
        return rst
    finally:
        os.unlink(fname)
Beispiel #9
0
def exec_cpp(code):
    """Compile, execute C++ code, and return the standard
    output."""
    # We create a temporary directory. This directory will
    # be deleted at the end of the 'with' context.
    # All created files will be in this directory.
    with tempfile.TemporaryDirectory() as tmpdir:

        # We define the source and executable filenames.
        source_path = op.join(tmpdir, 'temp.cpp')
        program_path = op.join(tmpdir, 'temp')

        # We write the code to the C++ file.
        with open(source_path, 'w') as f:
            f.write(code)

        # We compile the C++ code into an executable.
        os.system("g++ {0:s} -o {1:s}".format(source_path, program_path))

        # We execute the program and return the output.
        return getoutput(program_path)
Beispiel #10
0
 def test_getoutput_quoted2(self):
     out = getoutput("%s -c 'print (1)'" % python)
     self.assertEqual(out.strip(), '1')
     out = getoutput("%s -c 'print (\"1\")'" % python)
     self.assertEqual(out.strip(), '1')
Beispiel #11
0
 def test_getoutput_quoted(self):
     out = getoutput('%s -c "print (1)"' % python)
     self.assertEqual(out.strip(), '1')
 def test_getoutput_quoted(self):
     out = getoutput('python -c "print (1)"')
     self.assertEquals(out.strip(), '1')
Beispiel #13
0
# module to use temporary files instead of 'inline data' for data
# communication. Note that this is the default, so unless you've manually
# fiddled with it you should be ok. If you need to make changes, in the
# Gnuplot module directory, loook for the gp_unix.py file and make sure the
# prefer_inline_data variable is set to 0. If you set it to 1 Gnuplot.py will
# try to pass the data to gnuplot via standard input, which completely
# confuses the mouse control system (even though it may be a bit faster than
# using temp files).

# As of Gnuplot.py v1.7, a new option was added to use FIFOs (pipes).  This
# mechanism, while fast, also breaks the mouse system.  You must therefore set
# the variable prefer_fifo_data to 0 in gp_unix.py.

tmpname = tempfile.mktemp()
open(tmpname,'w').write('set mouse')
gnu_out = getoutput('gnuplot '+ tmpname)
os.unlink(tmpname)
if gnu_out:  # Gnuplot won't print anything if it has mouse support
    print("*** Your version of Gnuplot appears not to have mouse support.")
    gnuplot_mouse = 0
else:
    gnuplot_mouse = 1
del tmpname,gnu_out

# Default state for persistence of new gnuplot instances
if os.name in ['nt','dos'] or sys.platform == 'cygwin':
    gnuplot_persist = 0
else:
    gnuplot_persist = 1

import IPython.Gnuplot2 as Gnuplot
Beispiel #14
0
 def test_getoutput_quoted2(self):
     out = getoutput("%s -c 'print (1)'" % python)
     self.assertEqual(out.strip(), '1')
     out = getoutput("%s -c 'print (\"1\")'" % python)
     self.assertEqual(out.strip(), '1')
Beispiel #15
0
def getUuid(part):
    return getoutput("blkid {} -o value -s UUID".format(device + part)).strip()
Beispiel #16
0
def assertReady():
    if device is None:
        raise RuntimeError('Destination drive not set.')
    o = getoutput("df")
    if o.find(device) != -1:
        raise RuntimeError('Destination drive already mounted!')
 def test_getoutput(self):
     out = getoutput('python "%s"' % self.fname)
     self.assertEquals(out, 'on stdout')
Beispiel #18
0
        return self._prefilter(line, continuation)


# Rebind this to be the new IPython prefilter:
from IPython.core.iplib import InteractiveShell
InteractiveShell.prefilter = prefilter_shell
# Clean up the namespace.
del InteractiveShell, prefilter_shell

# Provide pysh and further shell-oriented services
import os, sys, shutil
from IPython.utils.process import system, shell, getoutput, getoutputerror

# Short aliases for getting shell output as a string and a list
sout = getoutput
lout = lambda cmd: getoutput(cmd, split=1)


# Empty function, meant as a docstring holder so help(pysh) works.
def pysh():
    """Pysh is a set of modules and extensions to IPython which make shell-like
    usage with Python syntax more convenient.  Keep in mind that pysh is NOT a
    full-blown shell, so don't try to make it your /etc/passwd entry!
    
    In particular, it has no job control, so if you type Ctrl-Z (under Unix),
    you'll suspend pysh itself, not the process you just started.

    Since pysh is really nothing but a customized IPython, you should
    familiarize yourself with IPython's features.  This brief help mainly
    documents areas in which pysh differs from the normal IPython.
Beispiel #19
0
 def test_getoutput_quoted(self):
     out = getoutput('%s -c "print (1)"' % python)
     self.assertEqual(out.strip(), '1')
 def test_getoutput(self):
     out = getoutput('python "%s"' % self.fname)
     self.assertEquals(out, 'on stdout')
Beispiel #21
0
    else:
        return self._prefilter(line,continuation)

# Rebind this to be the new IPython prefilter:
from IPython.core.iplib import InteractiveShell
InteractiveShell.prefilter = prefilter_shell
# Clean up the namespace.
del InteractiveShell,prefilter_shell

# Provide pysh and further shell-oriented services
import os,sys,shutil
from IPython.utils.process import system,shell,getoutput,getoutputerror

# Short aliases for getting shell output as a string and a list
sout = getoutput
lout = lambda cmd: getoutput(cmd,split=1)

# Empty function, meant as a docstring holder so help(pysh) works.
def pysh():
    """Pysh is a set of modules and extensions to IPython which make shell-like
    usage with Python syntax more convenient.  Keep in mind that pysh is NOT a
    full-blown shell, so don't try to make it your /etc/passwd entry!

    In particular, it has no job control, so if you type Ctrl-Z (under Unix),
    you'll suspend pysh itself, not the process you just started.

    Since pysh is really nothing but a customized IPython, you should
    familiarize yourself with IPython's features.  This brief help mainly
    documents areas in which pysh differs from the normal IPython.

    ALIASES
Beispiel #22
0
# module to use temporary files instead of 'inline data' for data
# communication. Note that this is the default, so unless you've manually
# fiddled with it you should be ok. If you need to make changes, in the
# Gnuplot module directory, loook for the gp_unix.py file and make sure the
# prefer_inline_data variable is set to 0. If you set it to 1 Gnuplot.py will
# try to pass the data to gnuplot via standard input, which completely
# confuses the mouse control system (even though it may be a bit faster than
# using temp files).

# As of Gnuplot.py v1.7, a new option was added to use FIFOs (pipes).  This
# mechanism, while fast, also breaks the mouse system.  You must therefore set
# the variable prefer_fifo_data to 0 in gp_unix.py.

tmpname = tempfile.mktemp()
open(tmpname,'w').write('set mouse')
gnu_out = getoutput('gnuplot '+ tmpname)
os.unlink(tmpname)
if gnu_out:  # Gnuplot won't print anything if it has mouse support
    print "*** Your version of Gnuplot appears not to have mouse support."
    gnuplot_mouse = 0
else:
    gnuplot_mouse = 1
del tmpname,gnu_out

# Default state for persistence of new gnuplot instances
if os.name in ['nt','dos'] or sys.platform == 'cygwin':
    gnuplot_persist = 0
else:
    gnuplot_persist = 1

import IPython.Gnuplot2 as Gnuplot