Beispiel #1
0
Datei: test.py Projekt: 0xr0ot/sh
    def test_custom_separator(self):
        py = create_tmp_test("""
import sys
print(sys.argv[1])
""")
        self.assertEqual(python(py.name,
            {"long-option": "underscore"}, _long_sep="=custom=").strip(), "--long-option=custom=underscore")
        # test baking too
        python_baked = python.bake(py.name, {"long-option": "underscore"}, _long_sep="=baked=")
        self.assertEqual(python_baked().strip(), "--long-option=baked=underscore")
Beispiel #2
0
    def test_custom_separator(self):
        py = create_tmp_test("""
import sys
print(sys.argv[1])
""")
        self.assertEqual(python(py.name, 
            {"long-option": "underscore"}, _long_sep="=custom=").strip(), "--long-option=custom=underscore")
        # test baking too
        python_baked = python.bake(py.name, {"long-option": "underscore"}, _long_sep="=baked=")
        self.assertEqual(python_baked().strip(), "--long-option=baked=underscore")
Beispiel #3
0
    def test_multiple_bakes(self):
        from sh import whoami
        import getpass
        
        py = create_tmp_test("""
import sys
import subprocess
subprocess.Popen(sys.argv[1:], shell=False).wait()
""")

        out = python.bake(py.name).bake("whoami")()
        self.assertTrue(getpass.getuser() == out.strip())
Beispiel #4
0
    def test_multiple_bakes(self):
        from sh import whoami
        import getpass

        py = create_tmp_test("""
import sys
import subprocess
subprocess.Popen(sys.argv[1:], shell=False).wait()
""")

        out = python.bake(py.name).bake("whoami")()
        self.assertTrue(getpass.getuser() == out.strip())
Beispiel #5
0
    def test_subcommand_and_bake(self):
        from sh import ls
        import getpass
        
        py = create_tmp_test("""
import sys
import os
import subprocess

print("subcommand")
subprocess.Popen(sys.argv[1:], shell=False).wait()
""")

        cmd1 = python.bake(py.name)
        out = cmd1.whoami()
        self.assertTrue("subcommand" in out)
        self.assertTrue(getpass.getuser() in out)
Beispiel #6
0
    def test_subcommand_and_bake(self):
        from sh import ls
        import getpass

        py = create_tmp_test("""
import sys
import os
import subprocess

print("subcommand")
subprocess.Popen(sys.argv[1:], shell=False).wait()
""")

        cmd1 = python.bake(py.name)
        out = cmd1.whoami()
        self.assertTrue("subcommand" in out)
        self.assertTrue(getpass.getuser() in out)
Beispiel #7
0
    def test_with_context(self):
        from sh import whoami
        import getpass
        
        py = create_tmp_test("""
import sys
import os
import subprocess

print("with_context")
subprocess.Popen(sys.argv[1:], shell=False).wait()
""")

        cmd1 = python.bake(py.name, _with=True)
        with cmd1:
            out = whoami()
        self.assertTrue("with_context" in out)
        self.assertTrue(getpass.getuser() in out)
Beispiel #8
0
    def test_with_context(self):
        from sh import whoami
        import getpass

        py = create_tmp_test("""
import sys
import os
import subprocess

print("with_context")
subprocess.Popen(sys.argv[1:], shell=False).wait()
""")

        cmd1 = python.bake(py.name, _with=True)
        with cmd1:
            out = whoami()
        self.assertTrue("with_context" in out)
        self.assertTrue(getpass.getuser() in out)
Beispiel #9
0
#!/usr/bin/python
"""Script to clean, build, and release the natu code.
"""

# pylint: disable=I0011, C0103, C0325, E0611

import sys
import os

from time import strftime
from collections import namedtuple
from docutils.core import publish_string
from sh import bash, git, python, python3, rm
from natu import util

setup = python.bake('setup.py')


def set_version(version, fname='natu/__init__.py'):
    """Update the version in a file.
    """
    util.replace(fname, [('(__version__) *= *.+', r"\1 = %s" % version)])


def build():
    """Build/make the code.
    """

    # Check that long-description.txt is a valid ReST file (otherwise, the PyPI
    # page won't show correctly).
    readme = 'doc/long-description.txt'
Beispiel #10
0
#!/usr/bin/python
"""Script to clean, build, and release the natu code.
"""

# pylint: disable=I0011, C0103, C0325, E0611

import sys
import os

from time import strftime
from collections import namedtuple
from docutils.core import publish_string
from sh import bash, git, python, python3, rm
from natu import util

setup = python.bake('setup.py')


def build():
    """Build the code to prepare for release.
    """

    # Check that long-description.txt is a valid ReST file (otherwise, the PyPI
    # page won't display correctly).
    readme = 'doc/long-description.txt'
    error_start = 'Docutils System Messages\n'
    with open(readme, 'r') as rstfile:
        parsed = publish_string(rstfile.read())
    if error_start in parsed:
        print("Errors in " + readme)
        util.delayed_exit()