test_process.py 文件源码

python
阅读 26 收藏 0 点赞 0 评论 0

项目:respeaker_virtualenv 作者: respeaker 项目源码 文件源码
def test_exe(self):
        sproc = get_test_subprocess()
        exe = psutil.Process(sproc.pid).exe()
        try:
            self.assertEqual(exe, PYTHON)
        except AssertionError:
            if WINDOWS and len(exe) == len(PYTHON):
                # on Windows we don't care about case sensitivity
                normcase = os.path.normcase
                self.assertEqual(normcase(exe), normcase(PYTHON))
            else:
                # certain platforms such as BSD are more accurate returning:
                # "/usr/local/bin/python2.7"
                # ...instead of:
                # "/usr/local/bin/python"
                # We do not want to consider this difference in accuracy
                # an error.
                ver = "%s.%s" % (sys.version_info[0], sys.version_info[1])
                try:
                    self.assertEqual(exe.replace(ver, ''),
                                     PYTHON.replace(ver, ''))
                except AssertionError:
                    # Tipically OSX. Really not sure what to do here.
                    pass

        subp = subprocess.Popen([exe, '-c', 'import os; print("hey")'],
                                stdout=subprocess.PIPE)
        out, _ = subp.communicate()
        self.assertEqual(out.strip(), b'hey')
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号