| 25 | |
| 26 | |
| 27 | class TestProgram(object): |
| 28 | def __init__(self, kind, name, protocol, transport, socket, workdir, stop_signal, command, env=None, |
| 29 | extra_args=[], extra_args2=[], join_args=False, **kwargs): |
| 30 | |
| 31 | self.kind = kind |
| 32 | self.name = name |
| 33 | self.protocol = protocol |
| 34 | self.transport = transport |
| 35 | self.socket = socket |
| 36 | self.workdir = workdir |
| 37 | self.stop_signal = stop_signal |
| 38 | self.command = None |
| 39 | self._base_command = self._fix_cmd_path(command) |
| 40 | if env: |
| 41 | self.env = copy.copy(os.environ) |
| 42 | self.env.update(env) |
| 43 | else: |
| 44 | self.env = os.environ |
| 45 | self._extra_args = extra_args |
| 46 | self._extra_args2 = extra_args2 |
| 47 | self._join_args = join_args |
| 48 | |
| 49 | def _fix_cmd_path(self, cmd): |
| 50 | # if the arg is a file in the current directory, make it path |
| 51 | def abs_if_exists(arg): |
| 52 | p = os.path.join(self.workdir, arg) |
| 53 | return p if os.path.exists(p) else arg |
| 54 | |
| 55 | if cmd[0] == 'python': |
| 56 | cmd[0] = sys.executable |
| 57 | else: |
| 58 | cmd[0] = abs_if_exists(cmd[0]) |
| 59 | return cmd |
| 60 | |
| 61 | def _socket_args(self, socket, port): |
| 62 | support_socket_activation = self.kind == 'server' and sys.platform != "win32" |
| 63 | return { |
| 64 | 'ip-ssl': ['--ssl'], |
| 65 | 'domain': ['--domain-socket=%s' % domain_socket_path(port)], |
| 66 | 'domain-socketactivated': (['--emulate-socketactivation'] if support_socket_activation else []) + ['--domain-socket=%s' % domain_socket_path(port)], |
| 67 | 'abstract': ['--abstract-namespace', '--domain-socket=%s' % domain_socket_path(port)], |
| 68 | }.get(socket, None) |
| 69 | |
| 70 | def _transport_args(self, transport): |
| 71 | return { |
| 72 | 'zlib': ['--zlib'], |
| 73 | }.get(transport, None) |
| 74 | |
| 75 | def build_command(self, port): |
| 76 | cmd = copy.copy(self._base_command) |
| 77 | args = copy.copy(self._extra_args2) |
| 78 | args.append('--protocol=' + self.protocol) |
| 79 | args.append('--transport=' + self.transport) |
| 80 | transport_args = self._transport_args(self.transport) |
| 81 | if transport_args: |
| 82 | args += transport_args |
| 83 | socket_args = self._socket_args(self.socket, port) |
| 84 | if socket_args: |