File: cwd_test.py

package info (click to toggle)
dumb-init 1.2.5-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 268 kB
  • sloc: python: 677; ansic: 260; makefile: 86; sh: 49
file content (22 lines) | stat: -rw-r--r-- 796 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import os
import shutil
from subprocess import run, PIPE

import pytest

@pytest.mark.usefixtures('both_debug_modes', 'both_setsid_modes')
def test_working_directories():
    """The child process must start in the working directory in which
    dumb-init was invoked, but dumb-init itself should not keep a
    reference to that."""

    # We need absolute path to dumb-init since we pass cwd=/tmp to get
    # predictable output - so we can't rely on dumb-init being found
    # in the "." directory.
    dumb_init = os.path.realpath(shutil.which('dumb-init'))
    proc = run((dumb_init,
                'sh', '-c', 'readlink /proc/$PPID/cwd && readlink /proc/$$/cwd'),
               cwd="/tmp", stdout=PIPE, stderr=PIPE)

    assert proc.returncode == 0
    assert proc.stdout == b'/\n/tmp\n'