• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python sh.python函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中sh.python函数的典型用法代码示例。如果您正苦于以下问题:Python python函数的具体用法?Python python怎么用?Python python使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了python函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: test_binary_pipe

    def test_binary_pipe(self):
        binary = b"\xec;\xedr\xdbF\x92\xf9\x8d\xa7\x98\x02/\x15\xd2K\xc3\x94d\xc9"

        py1 = create_tmp_test(
            """
import sys
import os

sys.stdout = os.fdopen(sys.stdout.fileno(), "wb", 0)
sys.stdout.write(%r)
"""
            % binary
        )

        py2 = create_tmp_test(
            """
import sys
import os

sys.stdin = os.fdopen(sys.stdin.fileno(), "rb", 0)
sys.stdout = os.fdopen(sys.stdout.fileno(), "wb", 0)
sys.stdout.write(sys.stdin.read())
"""
        )
        out = python(python(py1.name), py2.name)
        self.assertEqual(out.stdout, binary)
开发者ID:swayf,项目名称:sh,代码行数:26,代码来源:test.py


示例2: execute_locally

 def execute_locally(self):
     """Runs the equivalent command locally in a blocking way."""
     # Make script file #
     self.make_script()
     # Do it #
     with open(self.kwargs['out_file'], 'w') as handle:
         sh.python(self.script_path, _out=handle, _err=handle)
开发者ID:xapple,项目名称:plumbing,代码行数:7,代码来源:job.py


示例3: test_out_redirection

    def test_out_redirection(self):
        import tempfile

        py = create_tmp_test(
            """
import sys
import os

sys.stdout.write("stdout")
sys.stderr.write("stderr")
"""
        )

        file_obj = tempfile.TemporaryFile()
        out = python(py.name, _out=file_obj)

        self.assertTrue(len(out) == 0)

        file_obj.seek(0)
        actual_out = file_obj.read()
        file_obj.close()

        self.assertTrue(len(actual_out) != 0)

        # test with tee
        file_obj = tempfile.TemporaryFile()
        out = python(py.name, _out=file_obj, _tee=True)

        self.assertTrue(len(out) != 0)

        file_obj.seek(0)
        actual_out = file_obj.read()
        file_obj.close()

        self.assertTrue(len(actual_out) != 0)
开发者ID:swayf,项目名称:sh,代码行数:35,代码来源:test.py


示例4: test_err_redirection

    def test_err_redirection(self):
        import tempfile

        py = create_tmp_test(
            """
import sys
import os

sys.stdout.write("stdout")
sys.stderr.write("stderr")
"""
        )
        file_obj = tempfile.TemporaryFile()
        p = python(py.name, _err=file_obj)

        file_obj.seek(0)
        stderr = file_obj.read().decode()
        file_obj.close()

        self.assertTrue(p.stdout == b"stdout")
        self.assertTrue(stderr == "stderr")
        self.assertTrue(len(p.stderr) == 0)

        # now with tee
        file_obj = tempfile.TemporaryFile()
        p = python(py.name, _err=file_obj, _tee="err")

        file_obj.seek(0)
        stderr = file_obj.read().decode()
        file_obj.close()

        self.assertTrue(p.stdout == b"stdout")
        self.assertTrue(stderr == "stderr")
        self.assertTrue(len(p.stderr) != 0)
开发者ID:swayf,项目名称:sh,代码行数:34,代码来源:test.py


示例5: test_with_context_args

    def test_with_context_args(self):
        from sh import whoami
        import getpass

        py = create_tmp_test("""
import sys
import os
import subprocess
from optparse import OptionParser

parser = OptionParser()
parser.add_option("-o", "--opt", action="store_true", default=False, dest="opt")
options, args = parser.parse_args()

if options.opt:
    subprocess.Popen(args[0], shell=False).wait()
""")
        with python(py.name, opt=True, _with=True):
            out = whoami()
        self.assertTrue(getpass.getuser() == out.strip())
        
        
        with python(py.name, _with=True):
            out = whoami()    
        self.assertTrue(out == "")
开发者ID:ahhentz,项目名称:sh,代码行数:25,代码来源:test.py


示例6: test_environment

    def test_environment(self):
        import os

        env = {"HERP": "DERP"}

        py = create_tmp_test(
            """
import os

osx_cruft = ["__CF_USER_TEXT_ENCODING", "__PYVENV_LAUNCHER__"]
for key in osx_cruft:
    try: del os.environ[key]
    except: pass
print(os.environ["HERP"] + " " + str(len(os.environ)))
"""
        )
        out = python(py.name, _env=env).strip()
        self.assertEqual(out, "DERP 1")

        py = create_tmp_test(
            """
import os, sys
sys.path.insert(0, os.getcwd())
import sh
osx_cruft = ["__CF_USER_TEXT_ENCODING", "__PYVENV_LAUNCHER__"]
for key in osx_cruft:
    try: del os.environ[key]
    except: pass
print(sh.HERP + " " + str(len(os.environ)))
"""
        )
        out = python(py.name, _env=env, _cwd=THIS_DIR).strip()
        self.assertEqual(out, "DERP 1")
开发者ID:swayf,项目名称:sh,代码行数:33,代码来源:test.py


示例7: test_no_err

    def test_no_err(self):
        py = create_tmp_test(
            """
import sys
sys.stdout.write("stdout")
sys.stderr.write("stderr")
"""
        )
        p = python(py.name, _no_err=True)
        self.assertEqual(p.stderr, b"")
        self.assertEqual(p.stdout, b"stdout")
        self.assertFalse(p.process._pipe_queue.empty())

        def callback(line):
            pass

        p = python(py.name, _err=callback)
        self.assertEqual(p.stderr, b"")
        self.assertEqual(p.stdout, b"stdout")
        self.assertFalse(p.process._pipe_queue.empty())

        p = python(py.name)
        self.assertEqual(p.stderr, b"stderr")
        self.assertEqual(p.stdout, b"stdout")
        self.assertFalse(p.process._pipe_queue.empty())
开发者ID:swayf,项目名称:sh,代码行数:25,代码来源:test.py


示例8: run

 def run(self, clean):
     sh.cd(self.working_dir)
     try:
         sh.python(self.mainfile, _out=self.print_output, _err=self.print_output).wait()
     except Exception:
         pass
     if clean:
         self.clean()
开发者ID:Tefx,项目名称:cloudpy,代码行数:8,代码来源:cloudpy_agent.py


示例9: test_make_migrations

def test_make_migrations(cookies):
    """generated project should be able to generate migrations"""
    with bake_in_temp_dir(cookies, extra_context={}) as result:
        res = result.project.join('manage.py')
        try:
            sh.python(res, 'makemigrations')
        except sh.ErrorReturnCode as e:
            pytest.fail(str(e))
开发者ID:christopherdcunha,项目名称:cookiecutter-djangopackage,代码行数:8,代码来源:test_bake_project.py


示例10: test_run_tests

def test_run_tests(cookies):
    """generated project should run tests"""
    with bake_in_temp_dir(cookies, extra_context={}) as result:
        res = result.project.join('runtests.py')
        try:
            sh.python(res)
        except sh.ErrorReturnCode as e:
            pytest.fail(str(e))
开发者ID:christopherdcunha,项目名称:cookiecutter-djangopackage,代码行数:8,代码来源:test_bake_project.py


示例11: test_list

def test_list(ts):
	n, s = ts
	with open("log/%s.log" % n, "w") as f:
		for t in s:
			dax = "dax/%s" % t
			start = time.time()
			sh.python("emo4.py", dax)
			cost= time.time() - start
			print >>f, "%s\t%.2fs" % (dax, cost)
开发者ID:Tefx,项目名称:Wookie,代码行数:9,代码来源:test.py


示例12: test_long_bool_option

    def test_long_bool_option(self):
        py = create_tmp_test("""
from optparse import OptionParser
parser = OptionParser()
parser.add_option("-l", "--long-option", action="store_true", default=False, dest="long_option")
options, args = parser.parse_args()
print(options.long_option)
""")
        self.assertTrue(python(py.name, long_option=True).strip() == "True")
        self.assertTrue(python(py.name).strip() == "False")
开发者ID:ahhentz,项目名称:sh,代码行数:10,代码来源:test.py


示例13: test_long_option

    def test_long_option(self):
        py = create_tmp_test("""
from optparse import OptionParser
parser = OptionParser()
parser.add_option("-l", "--long-option", action="store", default="", dest="long_option")
options, args = parser.parse_args()
print(options.long_option.upper())
""")
        self.assertTrue(python(py.name, long_option="testing").strip() == "TESTING")
        self.assertTrue(python(py.name).strip() == "")
开发者ID:ahhentz,项目名称:sh,代码行数:10,代码来源:test.py


示例14: test_screenly_should_exit_if_no_settings_file_found

    def test_screenly_should_exit_if_no_settings_file_found(self):
        new_env = os.environ.copy()
        new_env["HOME"] = "/tmp"
        project_dir = os.path.dirname(__file__)

        with self.assertRaises(sh.ErrorReturnCode_1):
            sh.python(project_dir + '/../viewer.py', _env=new_env)

        with self.assertRaises(sh.ErrorReturnCode_1):
            sh.python(project_dir + '/../server.py', _env=new_env)
开发者ID:viaict,项目名称:screenly-ose,代码行数:10,代码来源:settings_test.py


示例15: upload

def upload():
    if request.method == 'GET':
        return render_template("upload.html")
    else:
        f = request.files['file']
        filename = secure_filename(f.filename)
        if not os.path.exists('/tmp/polly'):
            os.makedirs('/tmp/polly')
        f.save(os.path.join('/tmp/polly', filename))
        sh.python("/srv/polly/python-client/send_file.py")
        return redirect('/upload')
开发者ID:charliejl28,项目名称:polly,代码行数:11,代码来源:webserver.py


示例16: test_exit_code_from_exception

    def test_exit_code_from_exception(self):
        from sh import ErrorReturnCode
        py = create_tmp_test("""
exit(3)
""")

        self.assertRaises(ErrorReturnCode, python, py.name)

        try:
            python(py.name)
        except Exception as e:
            self.assertEqual(e.exit_code, 3)
开发者ID:0xr0ot,项目名称:sh,代码行数:12,代码来源:test.py


示例17: import_data

def import_data(json_name, package_dir):

    json_path = os.path.join(get_json_dir(), json_name)
    if os.path.exists(json_path):
        print('loading %s' % json_name)
        sh.cd(package_dir)
        if IS_PY2:
            sh.python('manage.py', 'loaddata', json_path)
        else:
            sh.python3('manage.py', 'loaddata', json_path)
    else:
        log('%s does not exist' % json_path)
开发者ID:goodcrypto,项目名称:goodcrypto-libs,代码行数:12,代码来源:import_json_to_db.py


示例18: test_multiple_args_long_option

    def test_multiple_args_long_option(self):
        py = create_tmp_test("""
from optparse import OptionParser
parser = OptionParser()
parser.add_option("-l", "--long-option", dest="long_option")
options, args = parser.parse_args()
print(len(options.long_option.split()))
""")
        num_args = int(python(py.name, long_option="one two three"))
        self.assertEqual(num_args, 3)

        num_args = int(python(py.name, "--long-option", "one's two's three's"))
        self.assertEqual(num_args, 3)
开发者ID:ahhentz,项目名称:sh,代码行数:13,代码来源:test.py


示例19: gen_model_code

def gen_model_code(model_codegen_dir,
                   platform,
                   model_file_path,
                   weight_file_path,
                   model_sha256_checksum,
                   weight_sha256_checksum,
                   input_nodes,
                   output_nodes,
                   runtime,
                   model_tag,
                   input_shapes,
                   dsp_mode,
                   embed_model_data,
                   winograd,
                   quantize,
                   quantize_range_file,
                   obfuscate,
                   model_graph_format,
                   data_type,
                   graph_optimize_options):
    bazel_build_common("//mace/python/tools:converter")

    if os.path.exists(model_codegen_dir):
        sh.rm("-rf", model_codegen_dir)
    sh.mkdir("-p", model_codegen_dir)

    sh.python("bazel-bin/mace/python/tools/converter",
              "-u",
              "--platform=%s" % platform,
              "--model_file=%s" % model_file_path,
              "--weight_file=%s" % weight_file_path,
              "--model_checksum=%s" % model_sha256_checksum,
              "--weight_checksum=%s" % weight_sha256_checksum,
              "--input_node=%s" % input_nodes,
              "--output_node=%s" % output_nodes,
              "--runtime=%s" % runtime,
              "--template=%s" % "mace/python/tools",
              "--model_tag=%s" % model_tag,
              "--input_shape=%s" % input_shapes,
              "--dsp_mode=%s" % dsp_mode,
              "--embed_model_data=%s" % embed_model_data,
              "--winograd=%s" % winograd,
              "--quantize=%s" % quantize,
              "--quantize_range_file=%s" % quantize_range_file,
              "--obfuscate=%s" % obfuscate,
              "--output_dir=%s" % model_codegen_dir,
              "--model_graph_format=%s" % model_graph_format,
              "--data_type=%s" % data_type,
              "--graph_optimize_options=%s" % graph_optimize_options,
              _fg=True)
开发者ID:lemonish,项目名称:mace,代码行数:50,代码来源:sh_commands.py


示例20: test_files

    def test_files(self):
        tpl_filename = self.tempfile('test.txt.tpl')
        txt_filename = self.tempfile('test.txt')
        with open(tpl_filename, 'wt') as f:
            f.write('hello {{FOO}}')

        sh.python(
            self.envtpl(), tpl_filename,
            _env={'FOO': 'world'},
        )

        self.assertFalse(os.path.exists(tpl_filename))
        self.assertTrue(os.path.exists(txt_filename))
        with open(txt_filename, 'r') as f:
            self.assertEquals('hello world', f.read())
开发者ID:andreasjansson,项目名称:envtpl,代码行数:15,代码来源:test_envtpl.py



注:本文中的sh.python函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python sh.rm函数代码示例发布时间:2022-05-27
下一篇:
Python sh.mv函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap