• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

twisted / twisted / 8233984069

11 Mar 2024 01:52PM UTC coverage: 90.875% (-0.1%) from 91.015%
8233984069

push

github

ziviseal
Enable workflows

28795 of 34231 branches covered (84.12%)

135227 of 148806 relevant lines covered (90.87%)

2.61 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

97.3
/src/twisted/conch/test/test_unix.py
1
# -*- test-case-name: twisted.conch.test.test_unix -*-
2
# Copyright (c) Twisted Matrix Laboratories.
3
# See LICENSE for details.
4

5

6
from zope.interface import implementer
3✔
7

8
from twisted.internet.interfaces import IReactorProcess
3✔
9
from twisted.python.reflect import requireModule
3✔
10
from twisted.trial import unittest
3✔
11

12
cryptography = requireModule("cryptography")
3✔
13
unix = requireModule("twisted.conch.unix")
3✔
14

15

16
@implementer(IReactorProcess)
3✔
17
class MockProcessSpawner:
18
    """
19
    An L{IReactorProcess} that logs calls to C{spawnProcess}.
20
    """
21

22
    def __init__(self):
3✔
23
        self._spawnProcessCalls = []
2✔
24

25
    def spawnProcess(
3✔
26
        self,
27
        processProtocol,
28
        executable,
29
        args=(),
30
        env={},
31
        path=None,
32
        uid=None,
33
        gid=None,
34
        usePTY=0,
35
        childFDs=None,
36
    ):
37
        """
38
        Log a call to C{spawnProcess}. Do not actually spawn a process.
39
        """
40
        self._spawnProcessCalls.append(
2✔
41
            {
42
                "processProtocol": processProtocol,
43
                "executable": executable,
44
                "args": args,
45
                "env": env,
46
                "path": path,
47
                "uid": uid,
48
                "gid": gid,
49
                "usePTY": usePTY,
50
                "childFDs": childFDs,
51
            }
52
        )
53

54

55
class StubUnixConchUser:
3✔
56
    """
57
    Enough of UnixConchUser to exercise SSHSessionForUnixConchUser in the
58
    tests below.
59
    """
60

61
    def __init__(self, homeDirectory):
3✔
62
        from .test_session import StubClient, StubConnection
2✔
63

64
        self._homeDirectory = homeDirectory
2✔
65
        self.conn = StubConnection(transport=StubClient())
2✔
66

67
    def getUserGroupId(self):
3✔
68
        return (None, None)
2✔
69

70
    def getHomeDir(self):
3✔
71
        return self._homeDirectory
2✔
72

73
    def getShell(self):
3✔
74
        pass
2✔
75

76

77
class TestSSHSessionForUnixConchUser(unittest.TestCase):
3✔
78

79
    if cryptography is None:
3✔
80
        skip = "Cannot run without cryptography"
1✔
81
    elif unix is None:
2!
82
        skip = "Unix system required"
×
83

84
    def testExecCommandEnvironment(self):
3✔
85
        """
86
        C{execCommand} sets the C{HOME} environment variable to the avatar's home
87
        directory.
88
        """
89
        mockReactor = MockProcessSpawner()
2✔
90
        homeDirectory = "/made/up/path/"
2✔
91
        avatar = StubUnixConchUser(homeDirectory)
2✔
92
        session = unix.SSHSessionForUnixConchUser(avatar, reactor=mockReactor)
2✔
93
        protocol = None
2✔
94
        command = ["not-actually-executed"]
2✔
95
        session.execCommand(protocol, command)
2✔
96
        [call] = mockReactor._spawnProcessCalls
2✔
97
        self.assertEqual(homeDirectory, call["env"]["HOME"])
2✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc