============================= test session starts ==============================
platform linux -- Python 3.10.1, pytest-6.2.5, py-1.11.0, pluggy-0.13.1
rootdir: /build/python-setproctitle/src/setproctitle-1.2.2
collected 21 items / 1 skipped / 20 selected

../../tests/setproctitle_test.py ...F....FFFFFFFF..                      [ 85%]
../../tests/setthreadtitle_test.py FFF                                   [100%]

=================================== FAILURES ===================================
______________________________ test_setproctitle _______________________________

    def test_setproctitle():
        """setproctitle() can set the process title, duh."""
        rv = run_script(
            r"""
    import setproctitle
    setproctitle.setproctitle('Hello, world!')
    
    import os
    print(os.getpid())
    # ps can fail on kfreebsd arch
    # (http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=460331)
    print(os.popen("ps -x -o pid,command 2> /dev/null").read())
    """
        )
        lines = [line for line in rv.splitlines() if line]
        pid = lines.pop(0)
        pids = dict([r.strip().split(None, 1) for r in lines])
        title = _clean_up_title(pids[pid])
>       assert title == "Hello, world!"
E       AssertionError: assert '/usr/bin/qem...sr/bin/python' == 'Hello, world!'
E         - Hello, world!
E         + /usr/bin/qemu-riscv64-static /usr/bin/python /usr/bin/python

../../tests/setproctitle_test.py:92: AssertionError
_________________________________ test_issue_8 _________________________________

tmp_pypath = PosixPath('/tmp/pytest-of-builduser/pytest-0/test_issue_80')

    def test_issue_8(tmp_pypath):
        """Test that the module works with 'python -m'."""
        module = "spt_issue_8"
        with open(tmp_pypath / f"{module}.py", "w") as f:
            f.write(
                r"""
    import setproctitle
    setproctitle.setproctitle("Hello, module!")
    
    import os
    print(os.getpid())
    print(os.popen("ps -x -o pid,command 2> /dev/null").read())
                """
            )
    
        rv = run_script(args="-m " + module)
        lines = [line for line in rv.splitlines() if line]
        pid = lines.pop(0)
        pids = dict([r.strip().split(None, 1) for r in lines])
    
        title = _clean_up_title(pids[pid])
>       assert title == "Hello, module!"
E       AssertionError: assert '/usr/bin/qem...m spt_issue_8' == 'Hello, module!'
E         - Hello, module!
E         + /usr/bin/qemu-riscv64-static /usr/bin/python /usr/bin/python -m spt_issue_8

../../tests/setproctitle_test.py:200: AssertionError
______________________________ test_large_cmdline ______________________________

tmp_pypath = PosixPath('/tmp/pytest-of-builduser/pytest-0/test_large_cmdline0')

    def test_large_cmdline(tmp_pypath):
        """Test with a 64KB command line."""
        module = "longargs"
        with open(tmp_pypath / f"{module}.py", "w") as f:
            f.write(
                r"""
    import setproctitle
    setproctitle.setproctitle("Hello, long!")
    
    import os
    print(os.getpid())
    print(os.popen("ps -x -o pid,command 2> /dev/null").read())
                """
            )
    
        rv = run_script(args=f"-m {module} {' '.join(['X' * 1024] * 64)}")
        lines = [line for line in rv.splitlines() if line]
        pid = lines.pop(0)
        pids = dict([r.strip().split(None, 1) for r in lines])
    
        title = _clean_up_title(pids[pid])
>       assert title == "Hello, long!"
E       AssertionError: assert '/usr/bin/qem...XXXXXXXXXXXXX' == 'Hello, long!'
E         - Hello, long!
E         + /usr/bin/qemu-riscv64-static /usr/bin/python /usr/bin/python -m longargs XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX...
E         
E         ...Full output truncated (1 line hidden), use '-vv' to show

../../tests/setproctitle_test.py:224: AssertionError
_________________________________ test_unicode _________________________________

    def test_unicode():
        """Title can contain unicode characters."""
        snowman = "\u2603"
        try:
            snowman.encode(sys.getdefaultencoding())
        except UnicodeEncodeError:
            pytest.skip(
                "default encoding '%s' can't deal with snowmen"
                % sys.getdefaultencoding()
            )
    
        try:
            snowman.encode(sys.getfilesystemencoding())
        except UnicodeEncodeError:
            pytest.skip(
                "file system encoding '%s' can't deal with snowmen"
                % sys.getfilesystemencoding()
            )
    
        rv = run_script(
            r"""
    snowman = u'\u2603'
    
    import setproctitle
    setproctitle.setproctitle("Hello, " + snowman + "!")
    
    import os
    import locale
    from subprocess import Popen, PIPE
    print(os.getpid())
    proc = Popen("ps -x -o pid,command 2> /dev/null", shell=True,
        close_fds=True, stdout=PIPE, stderr=PIPE)
    buf = proc.stdout.read()
    print(buf.decode(locale.getpreferredencoding(), 'replace'))
    """
        )
        lines = [line for line in rv.splitlines() if line]
        pid = lines.pop(0)
        pids = dict([r.strip().split(None, 1) for r in lines])
    
        snowmen = [
            "\u2603",  # ps supports unicode
            r"\M-b\M^X\M^C",  # ps output on BSD
            r"M-bM^XM^C",  # ps output on some Darwin < 11.2
            "\ufffdM^XM^C",  # ps output on Darwin 11.2
        ]
        title = _clean_up_title(pids[pid])
        for snowman in snowmen:
            if title == "Hello, " + snowman + "!":
                break
        else:
>           pytest.fail("unexpected ps output: %r" % title)
E           Failed: unexpected ps output: '/usr/bin/qemu-riscv64-static /usr/bin/python /usr/bin/python'

../../tests/setproctitle_test.py:278: Failed
_______________________________ test_weird_args ________________________________

    def test_weird_args():
        """No problem with encoded arguments."""
        euro = "\u20ac"
        snowman = "\u2603"
        try:
            rv = run_script(
                r"""
    import setproctitle
    setproctitle.setproctitle("Hello, weird args!")
    
    import os
    print(os.getpid())
    print(os.popen("ps -x -o pid,command 2> /dev/null").read())
    """,
                args=" ".join(["-", "hello", euro, snowman]),
            )
        except TypeError:
            pytest.skip("apparently we can't pass unicode args to a program")
    
        lines = [line for line in rv.splitlines() if line]
        pid = lines.pop(0)
        pids = dict([r.strip().split(None, 1) for r in lines])
    
        title = _clean_up_title(pids[pid])
>       assert title == "Hello, weird args!"
E       AssertionError: assert '/usr/bin/qem...n - hello € ☃' == 'Hello, weird args!'
E         - Hello, weird args!
E         + /usr/bin/qemu-riscv64-static /usr/bin/python /usr/bin/python - hello € ☃

../../tests/setproctitle_test.py:305: AssertionError
_______________________________ test_weird_path ________________________________

tmp_path = PosixPath('/tmp/pytest-of-builduser/pytest-0/test_weird_path0')
spt_directory = '/build/python-setproctitle/src/setproctitle-1.2.2/build/lib.linux-riscv64-3.10'

    def test_weird_path(tmp_path, spt_directory):
        """No problem with encoded argv[0] path."""
        _check_4388()
        euro = "\u20ac"
        snowman = "\u2603"
        dir = tmp_path / euro / snowman
        try:
            os.makedirs(dir)
        except UnicodeEncodeError:
            pytest.skip("file system doesn't support unicode")
    
        exc = dir / "python"
        os.symlink(sys.executable, exc)
    
        rv = run_script(
            f"""
    import sys
    sys.path.insert(0, {repr(spt_directory)})
    
    import setproctitle
    setproctitle.setproctitle("Hello, weird path!")
    
    import os
    print(os.getpid())
    print(os.popen("ps -x -o pid,command 2> /dev/null").read())
    """,
            args=" ".join(["-", "foo", "bar", "baz"]),
            executable=exc,
        )
        lines = [line for line in rv.splitlines() if line]
        pid = lines.pop(0)
        pids = dict([r.strip().split(None, 1) for r in lines])
    
        title = _clean_up_title(pids[pid])
>       assert title == "Hello, weird path!"
E       AssertionError: assert '/usr/bin/qem...- foo bar baz' == 'Hello, weird path!'
E         - Hello, weird path!
E         + /usr/bin/qemu-riscv64-static /tmp/pytest-of-builduser/pytest-0/test_weird_path0/€/☃/python /tmp/pytest-of-builduser/pytest-0/test_weird_path0/€/☃/python - foo bar baz

../../tests/setproctitle_test.py:342: AssertionError
________________________________ test_embedded _________________________________

pyrun = '/build/python-setproctitle/src/setproctitle-1.2.2/tests/pyrun3.10'
spt_directory = '/build/python-setproctitle/src/setproctitle-1.2.2/build/lib.linux-riscv64-3.10'

    @pytest.mark.embedded
    @pytest.mark.skipif(IS_PYPY, reason="skip test, pypy")
    def test_embedded(pyrun, spt_directory):
        """Check the module works with embedded Python.
        """
        if not os.path.exists("/proc/%s/cmdline" % os.getpid()):
            pytest.skip("known failure: '/proc/PID/cmdline' not available")
    
        rv = run_script(
            f"""
    import sys
    sys.path.insert(0, {spt_directory!r})
    import setproctitle
    setproctitle.setproctitle("Hello, embedded!")
    
    import os
    print(os.getpid())
    print(os.popen("ps -x -o pid,command 2> /dev/null").read())
    """,
            executable=pyrun,
        )
        lines = [line for line in rv.splitlines() if line]
        pid = lines.pop(0)
        pids = dict([r.strip().split(None, 1) for r in lines])
    
        title = _clean_up_title(pids[pid])
>       assert title == "Hello, embedded!"
E       AssertionError: assert '/usr/bin/qem...sts/pyrun3.10' == 'Hello, embedded!'
E         - Hello, embedded!
E         + /usr/bin/qemu-riscv64-static /build/python-setproctitle/src/setproctitle-1.2.2/tests/pyrun3.10 /build/python-setproctitle/src/setproctitle-1.2.2/tests/pyrun3.10

../../tests/setproctitle_test.py:371: AssertionError
___________________________ test_embedded_many_args ____________________________

pyrun = '/build/python-setproctitle/src/setproctitle-1.2.2/tests/pyrun3.10'
spt_directory = '/build/python-setproctitle/src/setproctitle-1.2.2/build/lib.linux-riscv64-3.10'

    @pytest.mark.embedded
    @pytest.mark.skipif(IS_PYPY, reason="skip test, pypy")
    def test_embedded_many_args(pyrun, spt_directory):
        """Check more complex cmdlines are handled in embedded env too."""
        if not os.path.exists("/proc/%s/cmdline" % os.getpid()):
            pytest.skip("known failure: '/proc/PID/cmdline' not available")
    
        rv = run_script(
            f"""
    import sys
    sys.path.insert(0, {spt_directory!r})
    import setproctitle
    setproctitle.setproctitle("Hello, embedded!")
    
    import os
    print(os.getpid())
    print(os.popen("ps -x -o pid,command 2> /dev/null").read())
    """,
            executable=pyrun,
            args=" ".join(["foo", "bar", "baz"]),
        )
        lines = [line for line in rv.splitlines() if line]
        pid = lines.pop(0)
        pids = dict([r.strip().split(None, 1) for r in lines])
    
        title = _clean_up_title(pids[pid])
>       assert title == "Hello, embedded!"
E       AssertionError: assert '/usr/bin/qem...0 foo bar baz' == 'Hello, embedded!'
E         - Hello, embedded!
E         + /usr/bin/qemu-riscv64-static /build/python-setproctitle/src/setproctitle-1.2.2/tests/pyrun3.10 /build/python-setproctitle/src/setproctitle-1.2.2/tests/pyrun3.10 foo bar baz

../../tests/setproctitle_test.py:400: AssertionError
__________________________________ test_noenv __________________________________

    def test_noenv():
        """Check that SPT_NOENV avoids clobbering environ."""
        if not os.path.exists("/proc/self/environ"):
            pytest.skip("'/proc/self/environ' not available")
    
        env = os.environ.copy()
        env["SPT_TESTENV"] = "testenv"
        rv = run_script(
            """
    import os
    os.environ['SPT_NOENV'] = "1"
    
    cmdline_len = len(open('/proc/self/cmdline').read())
    print(cmdline_len)
    print('SPT_TESTENV=testenv' in open('/proc/self/environ').read())
    
    import setproctitle
    setproctitle.setproctitle('X' * cmdline_len * 10)
    
    title = open('/proc/self/cmdline').read().rstrip()
    print(title)
    print(len(title))
    
    print('SPT_TESTENV=testenv' in open('/proc/self/environ').read())
        """,
            env=env,
        )
        lines = rv.splitlines()
        cmdline_len = int(lines[0])
        assert lines[1] == "True", "can't verify testenv"
        title = lines[2]
>       assert "XXX" in _clean_up_title(title), "title not set as expected"
E       AssertionError: title not set as expected
E       assert 'XXX' in '/usr/bin/python\x00'
E        +  where '/usr/bin/python\x00' = _clean_up_title('/usr/bin/python\x00')

../../tests/setproctitle_test.py:434: AssertionError
_________________________ test_thread_title_unchanged __________________________

    def test_thread_title_unchanged():
        if not os.path.isdir("/proc/self/task/"):
            pytest.skip("no task dir")
    
        rv = run_script(
            """
    from glob import glob
    
    def print_stuff():
        for fn in sorted(glob("/proc/self/task/*/comm")):
            with open(fn) as f:
                print(f.readline().rstrip())
    
    print_stuff()
    print("---")
    import setproctitle
    print_stuff()
    print("---")
    print(setproctitle.getthreadtitle())
    """
        )
        before, after, gtt = rv.split("---\n")
        assert before == after
>       assert before == gtt
E       AssertionError: assert 'python\npython\n' == 'python\n'
E           python
E         + python

../../tests/setthreadtitle_test.py:35: AssertionError
____________________________ test_set_thread_title _____________________________

    def test_set_thread_title():
        if not os.path.isdir("/proc/self/task/"):
            pytest.skip("no task dir")
    
>       rv = run_script(
            """
    from glob import glob
    import setproctitle
    setproctitle.setthreadtitle("hello" * 10)
    
    (fn,) = glob("/proc/self/task/*/comm")
    with open(fn) as f:
        assert f.read().rstrip() == "hello" * 3
    """
        )

../../tests/setthreadtitle_test.py:42: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

script = '\nfrom glob import glob\nimport setproctitle\nsetproctitle.setthreadtitle("hello" * 10)\n\n(fn,) = glob("/proc/self/task/*/comm")\nwith open(fn) as f:\n    assert f.read().rstrip() == "hello" * 3\n'
args = None, executable = '/usr/bin/python', env = None

    def run_script(script=None, args=None, executable=None, env=None):
        """run a script in a separate process.
    
        if the script completes successfully, return its ``stdout``,
        else fail the test.
        """
        if executable is None:
            executable = sys.executable
    
        cmdline = str(executable)
        if args:
            cmdline = cmdline + " " + args
    
        proc = sp.Popen(
            cmdline,
            stdin=sp.PIPE,
            stdout=sp.PIPE,
            stderr=sp.PIPE,
            env=env,
            shell=True,
            close_fds=True,
        )
    
        out, err = proc.communicate(script and script.encode())
        if 0 != proc.returncode:
            print(out)
            print(err)
>           pytest.fail("test script failed")
E           Failed: test script failed

../../tests/conftest.py:124: Failed
----------------------------- Captured stdout call -----------------------------
b''
b'Traceback (most recent call last):\n  File "<stdin>", line 6, in <module>\nValueError: too many values to unpack (expected 1)\n'
____________________________ test_set_threads_title ____________________________

    def test_set_threads_title():
        if not os.path.isdir("/proc/self/task/"):
            pytest.skip("no task dir")
    
>       rv = run_script(
            """
    import time
    import threading
    from glob import glob
    
    (fn,) = glob("/proc/self/task/*/comm")
    with open(fn) as f:
        orig = f.read().rstrip()
    
    import setproctitle
    
    def worker(title):
        setproctitle.setthreadtitle(title)
        while 1:
            time.sleep(1)
    
    t1 = threading.Thread(target=worker, args=('reader',), daemon=True)
    t2 = threading.Thread(target=worker, args=('writer',), daemon=True)
    t1.start()
    t2.start()
    
    comms = []
    for fn in glob("/proc/self/task/*/comm"):
        with open(fn) as f:
            comms.append(f.read().rstrip())
    
    comms.sort()
    assert comms == sorted([orig, "reader", "writer"])
    """
        )

../../tests/setthreadtitle_test.py:59: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

script = '\nimport time\nimport threading\nfrom glob import glob\n\n(fn,) = glob("/proc/self/task/*/comm")\nwith open(fn) as f:...) as f:\n        comms.append(f.read().rstrip())\n\ncomms.sort()\nassert comms == sorted([orig, "reader", "writer"])\n'
args = None, executable = '/usr/bin/python', env = None

    def run_script(script=None, args=None, executable=None, env=None):
        """run a script in a separate process.
    
        if the script completes successfully, return its ``stdout``,
        else fail the test.
        """
        if executable is None:
            executable = sys.executable
    
        cmdline = str(executable)
        if args:
            cmdline = cmdline + " " + args
    
        proc = sp.Popen(
            cmdline,
            stdin=sp.PIPE,
            stdout=sp.PIPE,
            stderr=sp.PIPE,
            env=env,
            shell=True,
            close_fds=True,
        )
    
        out, err = proc.communicate(script and script.encode())
        if 0 != proc.returncode:
            print(out)
            print(err)
>           pytest.fail("test script failed")
E           Failed: test script failed

../../tests/conftest.py:124: Failed
----------------------------- Captured stdout call -----------------------------
b''
b'Traceback (most recent call last):\n  File "<stdin>", line 6, in <module>\nValueError: too many values to unpack (expected 1)\n'
=========================== short test summary info ============================
FAILED ../../tests/setproctitle_test.py::test_setproctitle - AssertionError: ...
FAILED ../../tests/setproctitle_test.py::test_issue_8 - AssertionError: asser...
FAILED ../../tests/setproctitle_test.py::test_large_cmdline - AssertionError:...
FAILED ../../tests/setproctitle_test.py::test_unicode - Failed: unexpected ps...
FAILED ../../tests/setproctitle_test.py::test_weird_args - AssertionError: as...
FAILED ../../tests/setproctitle_test.py::test_weird_path - AssertionError: as...
FAILED ../../tests/setproctitle_test.py::test_embedded - AssertionError: asse...
FAILED ../../tests/setproctitle_test.py::test_embedded_many_args - AssertionE...
FAILED ../../tests/setproctitle_test.py::test_noenv - AssertionError: title n...
FAILED ../../tests/setthreadtitle_test.py::test_thread_title_unchanged - Asse...
FAILED ../../tests/setthreadtitle_test.py::test_set_thread_title - Failed: te...
FAILED ../../tests/setthreadtitle_test.py::test_set_threads_title - Failed: t...
=================== 12 failed, 9 passed, 1 skipped in 11.94s ===================
[1m[31m==> ERROR:[m[1m A failure occurred in check().[m
[1m    Aborting...[m
