| 1 |
From 9df1603360df57dd197b5be350ad3402047c8e41 Mon Sep 17 00:00:00 2001 |
| 2 |
From: Simon Chopin <[email protected]> |
| 3 |
Date: Thu, 8 Oct 2015 09:26:23 -0700 |
| 4 |
Subject: Remove the pycompat* submodules |
| 5 |
|
| 6 |
Those are not needed in Debian as we already ship the latest runtime version. |
| 7 |
Forwarded: not-needed |
| 8 |
Last-Update: 2013-04-30 |
| 9 |
Patch-Name: remove_compat_layers |
| 10 |
--- |
| 11 |
kitchen2/docs/api-overview.rst | 3 - |
| 12 |
kitchen2/docs/api-pycompat24.rst | 34 - |
| 13 |
kitchen2/docs/api-pycompat25.rst | 8 - |
| 14 |
kitchen2/docs/api-pycompat27.rst | 35 - |
| 15 |
kitchen2/kitchen/text/converters.py | 3 - |
| 16 |
kitchen2/kitchen/text/misc.py | 3 - |
| 17 |
kitchen2/tests/subprocessdata/sigchild_ignore.py | 11 - |
| 18 |
kitchen2/tests/test__all__.py | 2 - |
| 19 |
kitchen2/tests/test_base64.py | 190 --- |
| 20 |
kitchen2/tests/test_collections.py | 3 - |
| 21 |
kitchen2/tests/test_defaultdict.py | 180 --- |
| 22 |
kitchen2/tests/test_pycompat.py | 25 - |
| 23 |
kitchen2/tests/test_pycompat24.py | 109 -- |
| 24 |
kitchen2/tests/test_subprocess.py | 1467 ---------------------- |
| 25 |
kitchen3/docs/api-overview.rst | 3 - |
| 26 |
kitchen3/docs/api-pycompat24.rst | 34 - |
| 27 |
kitchen3/docs/api-pycompat25.rst | 8 - |
| 28 |
kitchen3/docs/api-pycompat27.rst | 35 - |
| 29 |
kitchen3/tests/subprocessdata/sigchild_ignore.py | 11 - |
| 30 |
kitchen3/tests/test__all__.py | 2 - |
| 31 |
kitchen3/tests/test_collections.py | 3 - |
| 32 |
kitchen3/tests/test_deprecation_py3.py | 65 - |
| 33 |
kitchen3/tests/test_pycompat.py | 25 - |
| 34 |
setup.py | 14 - |
| 35 |
24 files changed, 2273 deletions(-) |
| 36 |
delete mode 100644 kitchen2/docs/api-pycompat24.rst |
| 37 |
delete mode 100644 kitchen2/docs/api-pycompat25.rst |
| 38 |
delete mode 100644 kitchen2/docs/api-pycompat27.rst |
| 39 |
delete mode 100644 kitchen2/tests/subprocessdata/sigchild_ignore.py |
| 40 |
delete mode 100644 kitchen2/tests/test_base64.py |
| 41 |
delete mode 100644 kitchen2/tests/test_defaultdict.py |
| 42 |
delete mode 100644 kitchen2/tests/test_pycompat.py |
| 43 |
delete mode 100644 kitchen2/tests/test_pycompat24.py |
| 44 |
delete mode 100644 kitchen2/tests/test_subprocess.py |
| 45 |
delete mode 100644 kitchen3/docs/api-pycompat24.rst |
| 46 |
delete mode 100644 kitchen3/docs/api-pycompat25.rst |
| 47 |
delete mode 100644 kitchen3/docs/api-pycompat27.rst |
| 48 |
delete mode 100644 kitchen3/tests/subprocessdata/sigchild_ignore.py |
| 49 |
delete mode 100644 kitchen3/tests/test_deprecation_py3.py |
| 50 |
delete mode 100644 kitchen3/tests/test_pycompat.py |
| 51 |
|
| 52 |
Index: kitchen/kitchen2/docs/api-overview.rst |
| 53 |
=================================================================== |
| 54 |
--- kitchen.orig/kitchen2/docs/api-overview.rst 2017-08-28 00:47:21.493143026 -0400 |
| 55 |
+++ kitchen/kitchen2/docs/api-overview.rst 2017-08-28 00:47:21.485143105 -0400 |
| 56 |
@@ -16,9 +16,6 @@ |
| 57 |
api-collections |
| 58 |
api-iterutils |
| 59 |
api-versioning |
| 60 |
- api-pycompat24 |
| 61 |
- api-pycompat25 |
| 62 |
- api-pycompat27 |
| 63 |
api-exceptions |
| 64 |
|
| 65 |
.. _`project webpage`: https://fedorahosted.org/kitchen |
| 66 |
Index: kitchen/kitchen2/docs/api-pycompat24.rst |
| 67 |
=================================================================== |
| 68 |
--- kitchen.orig/kitchen2/docs/api-pycompat24.rst 2017-08-28 00:47:21.493143026 -0400 |
| 69 |
+++ /dev/null 1970-01-01 00:00:00.000000000 +0000 |
| 70 |
@@ -1,34 +0,0 @@ |
| 71 |
-======================= |
| 72 |
-Python 2.4 Compatibiity |
| 73 |
-======================= |
| 74 |
- |
| 75 |
- |
| 76 |
-------------------- |
| 77 |
-Sets for python-2.3 |
| 78 |
-------------------- |
| 79 |
- |
| 80 |
-.. automodule:: kitchen.pycompat24.sets |
| 81 |
-.. autofunction:: kitchen.pycompat24.sets.add_builtin_set |
| 82 |
- |
| 83 |
----------------------------------- |
| 84 |
-Partial new style base64 interface |
| 85 |
----------------------------------- |
| 86 |
- |
| 87 |
-.. automodule:: kitchen.pycompat24.base64 |
| 88 |
- :members: |
| 89 |
- |
| 90 |
----------- |
| 91 |
-Subprocess |
| 92 |
----------- |
| 93 |
- |
| 94 |
-.. seealso:: |
| 95 |
- |
| 96 |
- :mod:`kitchen.pycompat27.subprocess` |
| 97 |
- Kitchen includes the python-2.7 version of subprocess which has a new |
| 98 |
- function, :func:`~kitchen.pycompat27.subprocess.check_output`. When |
| 99 |
- you import :mod:`pycompat24.subprocess` you will be getting the |
| 100 |
- python-2.7 version of subprocess rather than the 2.4 version (where |
| 101 |
- subprocess first appeared). This choice was made so that we can |
| 102 |
- concentrate our efforts on keeping the single version of subprocess up |
| 103 |
- to date rather than working on a 2.4 version that very few people |
| 104 |
- would need specifically. |
| 105 |
Index: kitchen/kitchen2/docs/api-pycompat25.rst |
| 106 |
=================================================================== |
| 107 |
--- kitchen.orig/kitchen2/docs/api-pycompat25.rst 2017-08-28 00:47:21.493143026 -0400 |
| 108 |
+++ /dev/null 1970-01-01 00:00:00.000000000 +0000 |
| 109 |
@@ -1,8 +0,0 @@ |
| 110 |
-======================== |
| 111 |
-Python 2.5 Compatibility |
| 112 |
-======================== |
| 113 |
- |
| 114 |
-.. automodule:: kitchen.pycompat25 |
| 115 |
- |
| 116 |
-.. automodule:: kitchen.pycompat25.collections._defaultdict |
| 117 |
- |
| 118 |
Index: kitchen/kitchen2/docs/api-pycompat27.rst |
| 119 |
=================================================================== |
| 120 |
--- kitchen.orig/kitchen2/docs/api-pycompat27.rst 2017-08-28 00:47:21.493143026 -0400 |
| 121 |
+++ /dev/null 1970-01-01 00:00:00.000000000 +0000 |
| 122 |
@@ -1,35 +0,0 @@ |
| 123 |
-======================== |
| 124 |
-Python 2.7 Compatibility |
| 125 |
-======================== |
| 126 |
- |
| 127 |
-.. module:: kitchen.pycompat27.subprocess |
| 128 |
- |
| 129 |
--------------------------- |
| 130 |
-Subprocess from Python 2.7 |
| 131 |
--------------------------- |
| 132 |
- |
| 133 |
-The :mod:`subprocess` module included here is a direct import from |
| 134 |
-python-2.7's |stdlib|_. You can access it via:: |
| 135 |
- |
| 136 |
- >>> from kitchen.pycompat27 import subprocess |
| 137 |
- |
| 138 |
-The motivation for including this module is that various API changing |
| 139 |
-improvements have been made to subprocess over time. The following is a list |
| 140 |
-of the known changes to :mod:`subprocess` with the python version they were |
| 141 |
-introduced in: |
| 142 |
- |
| 143 |
-==================================== === |
| 144 |
-New API Feature Ver |
| 145 |
-==================================== === |
| 146 |
-:exc:`subprocess.CalledProcessError` 2.5 |
| 147 |
-:func:`subprocess.check_call` 2.5 |
| 148 |
-:func:`subprocess.check_output` 2.7 |
| 149 |
-:meth:`subprocess.Popen.send_signal` 2.6 |
| 150 |
-:meth:`subprocess.Popen.terminate` 2.6 |
| 151 |
-:meth:`subprocess.Popen.kill` 2.6 |
| 152 |
-==================================== === |
| 153 |
- |
| 154 |
-.. seealso:: |
| 155 |
- |
| 156 |
- The stdlib :mod:`subprocess` documentation |
| 157 |
- For complete documentation on how to use subprocess |
| 158 |
Index: kitchen/kitchen2/kitchen/text/converters.py |
| 159 |
=================================================================== |
| 160 |
--- kitchen.orig/kitchen2/kitchen/text/converters.py 2017-08-28 00:47:21.493143026 -0400 |
| 161 |
+++ kitchen/kitchen2/kitchen/text/converters.py 2017-08-28 00:47:21.485143105 -0400 |
| 162 |
@@ -50,9 +50,6 @@ |
| 163 |
import warnings |
| 164 |
import xml.sax.saxutils |
| 165 |
|
| 166 |
-from kitchen.pycompat24 import sets |
| 167 |
-sets.add_builtin_set() |
| 168 |
- |
| 169 |
from kitchen.text.exceptions import ControlCharError, XmlEncodeError |
| 170 |
from kitchen.text.misc import guess_encoding, html_entities_unescape, \ |
| 171 |
isbytestring, isunicodestring, process_control_chars |
| 172 |
Index: kitchen/kitchen2/kitchen/text/misc.py |
| 173 |
=================================================================== |
| 174 |
--- kitchen.orig/kitchen2/kitchen/text/misc.py 2017-08-28 00:47:21.493143026 -0400 |
| 175 |
+++ kitchen/kitchen2/kitchen/text/misc.py 2017-08-28 00:47:21.485143105 -0400 |
| 176 |
@@ -43,11 +43,8 @@ |
| 177 |
except ImportError: |
| 178 |
chardet = None |
| 179 |
|
| 180 |
-from kitchen.pycompat24 import sets |
| 181 |
from kitchen.text.exceptions import ControlCharError |
| 182 |
|
| 183 |
-sets.add_builtin_set() |
| 184 |
- |
| 185 |
# Define a threshold for chardet confidence. If we fall below this we decode |
| 186 |
# byte strings we're guessing about as latin1 |
| 187 |
_CHARDET_THRESHHOLD = 0.6 |
| 188 |
Index: kitchen/kitchen2/tests/subprocessdata/sigchild_ignore.py |
| 189 |
=================================================================== |
| 190 |
--- kitchen.orig/kitchen2/tests/subprocessdata/sigchild_ignore.py 2017-08-28 00:47:21.493143026 -0400 |
| 191 |
+++ /dev/null 1970-01-01 00:00:00.000000000 +0000 |
| 192 |
@@ -1,11 +0,0 @@ |
| 193 |
-import os |
| 194 |
-import signal, sys |
| 195 |
-sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..', '..')) |
| 196 |
- |
| 197 |
-from kitchen.pycompat27.subprocess import _subprocess as subprocess |
| 198 |
- |
| 199 |
-# On Linux this causes os.waitpid to fail with OSError as the OS has already |
| 200 |
-# reaped our child process. The wait() passing the OSError on to the caller |
| 201 |
-# and causing us to exit with an error is what we are testing against. |
| 202 |
-signal.signal(signal.SIGCHLD, signal.SIG_IGN) |
| 203 |
-subprocess.Popen([sys.executable, '-c', 'print("albatross")']).wait() |
| 204 |
Index: kitchen/kitchen2/tests/test__all__.py |
| 205 |
=================================================================== |
| 206 |
--- kitchen.orig/kitchen2/tests/test__all__.py 2017-08-28 00:47:21.493143026 -0400 |
| 207 |
+++ kitchen/kitchen2/tests/test__all__.py 2017-08-28 00:47:21.485143105 -0400 |
| 208 |
@@ -4,8 +4,6 @@ |
| 209 |
import os |
| 210 |
import types |
| 211 |
import warnings |
| 212 |
-from kitchen.pycompat24.sets import add_builtin_set |
| 213 |
-add_builtin_set() |
| 214 |
|
| 215 |
def logit(msg): |
| 216 |
log = open('/var/tmp/test.log', 'a') |
| 217 |
Index: kitchen/kitchen2/tests/test_base64.py |
| 218 |
=================================================================== |
| 219 |
--- kitchen.orig/kitchen2/tests/test_base64.py 2017-08-28 00:47:21.493143026 -0400 |
| 220 |
+++ /dev/null 1970-01-01 00:00:00.000000000 +0000 |
| 221 |
@@ -1,190 +0,0 @@ |
| 222 |
-import unittest |
| 223 |
-from kitchen.pycompat24.base64 import _base64 as base64 |
| 224 |
- |
| 225 |
- |
| 226 |
- |
| 227 |
-class LegacyBase64TestCase(unittest.TestCase): |
| 228 |
- def test_encodestring(self): |
| 229 |
- eq = self.assertEqual |
| 230 |
- eq(base64.encodestring("www.python.org"), "d3d3LnB5dGhvbi5vcmc=\n") |
| 231 |
- eq(base64.encodestring("a"), "YQ==\n") |
| 232 |
- eq(base64.encodestring("ab"), "YWI=\n") |
| 233 |
- eq(base64.encodestring("abc"), "YWJj\n") |
| 234 |
- eq(base64.encodestring(""), "") |
| 235 |
- eq(base64.encodestring("abcdefghijklmnopqrstuvwxyz" |
| 236 |
- "ABCDEFGHIJKLMNOPQRSTUVWXYZ" |
| 237 |
- "0123456789!@#0^&*();:<>,. []{}"), |
| 238 |
- "YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXpBQkNE" |
| 239 |
- "RUZHSElKS0xNTk9QUVJTVFVWV1hZWjAxMjM0\nNT" |
| 240 |
- "Y3ODkhQCMwXiYqKCk7Ojw+LC4gW117fQ==\n") |
| 241 |
- |
| 242 |
- def test_decodestring(self): |
| 243 |
- eq = self.assertEqual |
| 244 |
- eq(base64.decodestring("d3d3LnB5dGhvbi5vcmc=\n"), "www.python.org") |
| 245 |
- eq(base64.decodestring("YQ==\n"), "a") |
| 246 |
- eq(base64.decodestring("YWI=\n"), "ab") |
| 247 |
- eq(base64.decodestring("YWJj\n"), "abc") |
| 248 |
- eq(base64.decodestring("YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXpBQkNE" |
| 249 |
- "RUZHSElKS0xNTk9QUVJTVFVWV1hZWjAxMjM0\nNT" |
| 250 |
- "Y3ODkhQCMwXiYqKCk7Ojw+LC4gW117fQ==\n"), |
| 251 |
- "abcdefghijklmnopqrstuvwxyz" |
| 252 |
- "ABCDEFGHIJKLMNOPQRSTUVWXYZ" |
| 253 |
- "0123456789!@#0^&*();:<>,. []{}") |
| 254 |
- eq(base64.decodestring(''), '') |
| 255 |
- |
| 256 |
- def test_encode(self): |
| 257 |
- eq = self.assertEqual |
| 258 |
- from cStringIO import StringIO |
| 259 |
- infp = StringIO('abcdefghijklmnopqrstuvwxyz' |
| 260 |
- 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' |
| 261 |
- '0123456789!@#0^&*();:<>,. []{}') |
| 262 |
- outfp = StringIO() |
| 263 |
- base64.encode(infp, outfp) |
| 264 |
- eq(outfp.getvalue(), |
| 265 |
- 'YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXpBQkNE' |
| 266 |
- 'RUZHSElKS0xNTk9QUVJTVFVWV1hZWjAxMjM0\nNT' |
| 267 |
- 'Y3ODkhQCMwXiYqKCk7Ojw+LC4gW117fQ==\n') |
| 268 |
- |
| 269 |
- def test_decode(self): |
| 270 |
- from cStringIO import StringIO |
| 271 |
- infp = StringIO('d3d3LnB5dGhvbi5vcmc=') |
| 272 |
- outfp = StringIO() |
| 273 |
- base64.decode(infp, outfp) |
| 274 |
- self.assertEqual(outfp.getvalue(), 'www.python.org') |
| 275 |
- |
| 276 |
- |
| 277 |
- |
| 278 |
-class BaseXYTestCase(unittest.TestCase): |
| 279 |
- def test_b64encode(self): |
| 280 |
- eq = self.assertEqual |
| 281 |
- # Test default alphabet |
| 282 |
- eq(base64.b64encode("www.python.org"), "d3d3LnB5dGhvbi5vcmc=") |
| 283 |
- eq(base64.b64encode('\x00'), 'AA==') |
| 284 |
- eq(base64.b64encode("a"), "YQ==") |
| 285 |
- eq(base64.b64encode("ab"), "YWI=") |
| 286 |
- eq(base64.b64encode("abc"), "YWJj") |
| 287 |
- eq(base64.b64encode(""), "") |
| 288 |
- eq(base64.b64encode("abcdefghijklmnopqrstuvwxyz" |
| 289 |
- "ABCDEFGHIJKLMNOPQRSTUVWXYZ" |
| 290 |
- "0123456789!@#0^&*();:<>,. []{}"), |
| 291 |
- "YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXpBQkNE" |
| 292 |
- "RUZHSElKS0xNTk9QUVJTVFVWV1hZWjAxMjM0NT" |
| 293 |
- "Y3ODkhQCMwXiYqKCk7Ojw+LC4gW117fQ==") |
| 294 |
- # Test with arbitrary alternative characters |
| 295 |
- eq(base64.b64encode('\xd3V\xbeo\xf7\x1d', altchars='*$'), '01a*b$cd') |
| 296 |
- # Test standard alphabet |
| 297 |
- eq(base64.standard_b64encode("www.python.org"), "d3d3LnB5dGhvbi5vcmc=") |
| 298 |
- eq(base64.standard_b64encode("a"), "YQ==") |
| 299 |
- eq(base64.standard_b64encode("ab"), "YWI=") |
| 300 |
- eq(base64.standard_b64encode("abc"), "YWJj") |
| 301 |
- eq(base64.standard_b64encode(""), "") |
| 302 |
- eq(base64.standard_b64encode("abcdefghijklmnopqrstuvwxyz" |
| 303 |
- "ABCDEFGHIJKLMNOPQRSTUVWXYZ" |
| 304 |
- "0123456789!@#0^&*();:<>,. []{}"), |
| 305 |
- "YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXpBQkNE" |
| 306 |
- "RUZHSElKS0xNTk9QUVJTVFVWV1hZWjAxMjM0NT" |
| 307 |
- "Y3ODkhQCMwXiYqKCk7Ojw+LC4gW117fQ==") |
| 308 |
- # Test with 'URL safe' alternative characters |
| 309 |
- eq(base64.urlsafe_b64encode('\xd3V\xbeo\xf7\x1d'), '01a-b_cd') |
| 310 |
- |
| 311 |
- def test_b64decode(self): |
| 312 |
- eq = self.assertEqual |
| 313 |
- eq(base64.b64decode("d3d3LnB5dGhvbi5vcmc="), "www.python.org") |
| 314 |
- eq(base64.b64decode('AA=='), '\x00') |
| 315 |
- eq(base64.b64decode("YQ=="), "a") |
| 316 |
- eq(base64.b64decode("YWI="), "ab") |
| 317 |
- eq(base64.b64decode("YWJj"), "abc") |
| 318 |
- eq(base64.b64decode("YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXpBQkNE" |
| 319 |
- "RUZHSElKS0xNTk9QUVJTVFVWV1hZWjAxMjM0\nNT" |
| 320 |
- "Y3ODkhQCMwXiYqKCk7Ojw+LC4gW117fQ=="), |
| 321 |
- "abcdefghijklmnopqrstuvwxyz" |
| 322 |
- "ABCDEFGHIJKLMNOPQRSTUVWXYZ" |
| 323 |
- "0123456789!@#0^&*();:<>,. []{}") |
| 324 |
- eq(base64.b64decode(''), '') |
| 325 |
- # Test with arbitrary alternative characters |
| 326 |
- eq(base64.b64decode('01a*b$cd', altchars='*$'), '\xd3V\xbeo\xf7\x1d') |
| 327 |
- # Test standard alphabet |
| 328 |
- eq(base64.standard_b64decode("d3d3LnB5dGhvbi5vcmc="), "www.python.org") |
| 329 |
- eq(base64.standard_b64decode("YQ=="), "a") |
| 330 |
- eq(base64.standard_b64decode("YWI="), "ab") |
| 331 |
- eq(base64.standard_b64decode("YWJj"), "abc") |
| 332 |
- eq(base64.standard_b64decode(""), "") |
| 333 |
- eq(base64.standard_b64decode("YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXpBQkNE" |
| 334 |
- "RUZHSElKS0xNTk9QUVJTVFVWV1hZWjAxMjM0NT" |
| 335 |
- "Y3ODkhQCMwXiYqKCk7Ojw+LC4gW117fQ=="), |
| 336 |
- "abcdefghijklmnopqrstuvwxyz" |
| 337 |
- "ABCDEFGHIJKLMNOPQRSTUVWXYZ" |
| 338 |
- "0123456789!@#0^&*();:<>,. []{}") |
| 339 |
- # Test with 'URL safe' alternative characters |
| 340 |
- eq(base64.urlsafe_b64decode('01a-b_cd'), '\xd3V\xbeo\xf7\x1d') |
| 341 |
- |
| 342 |
- def test_b64decode_error(self): |
| 343 |
- self.assertRaises(TypeError, base64.b64decode, 'abc') |
| 344 |
- |
| 345 |
- def test_b32encode(self): |
| 346 |
- eq = self.assertEqual |
| 347 |
- eq(base64.b32encode(''), '') |
| 348 |
- eq(base64.b32encode('\x00'), 'AA======') |
| 349 |
- eq(base64.b32encode('a'), 'ME======') |
| 350 |
- eq(base64.b32encode('ab'), 'MFRA====') |
| 351 |
- eq(base64.b32encode('abc'), 'MFRGG===') |
| 352 |
- eq(base64.b32encode('abcd'), 'MFRGGZA=') |
| 353 |
- eq(base64.b32encode('abcde'), 'MFRGGZDF') |
| 354 |
- |
| 355 |
- def test_b32decode(self): |
| 356 |
- eq = self.assertEqual |
| 357 |
- eq(base64.b32decode(''), '') |
| 358 |
- eq(base64.b32decode('AA======'), '\x00') |
| 359 |
- eq(base64.b32decode('ME======'), 'a') |
| 360 |
- eq(base64.b32decode('MFRA===='), 'ab') |
| 361 |
- eq(base64.b32decode('MFRGG==='), 'abc') |
| 362 |
- eq(base64.b32decode('MFRGGZA='), 'abcd') |
| 363 |
- eq(base64.b32decode('MFRGGZDF'), 'abcde') |
| 364 |
- |
| 365 |
- def test_b32decode_casefold(self): |
| 366 |
- eq = self.assertEqual |
| 367 |
- eq(base64.b32decode('', True), '') |
| 368 |
- eq(base64.b32decode('ME======', True), 'a') |
| 369 |
- eq(base64.b32decode('MFRA====', True), 'ab') |
| 370 |
- eq(base64.b32decode('MFRGG===', True), 'abc') |
| 371 |
- eq(base64.b32decode('MFRGGZA=', True), 'abcd') |
| 372 |
- eq(base64.b32decode('MFRGGZDF', True), 'abcde') |
| 373 |
- # Lower cases |
| 374 |
- eq(base64.b32decode('me======', True), 'a') |
| 375 |
- eq(base64.b32decode('mfra====', True), 'ab') |
| 376 |
- eq(base64.b32decode('mfrgg===', True), 'abc') |
| 377 |
- eq(base64.b32decode('mfrggza=', True), 'abcd') |
| 378 |
- eq(base64.b32decode('mfrggzdf', True), 'abcde') |
| 379 |
- # Expected exceptions |
| 380 |
- self.assertRaises(TypeError, base64.b32decode, 'me======') |
| 381 |
- # Mapping zero and one |
| 382 |
- eq(base64.b32decode('MLO23456'), 'b\xdd\xad\xf3\xbe') |
| 383 |
- eq(base64.b32decode('M1023456', map01='L'), 'b\xdd\xad\xf3\xbe') |
| 384 |
- eq(base64.b32decode('M1023456', map01='I'), 'b\x1d\xad\xf3\xbe') |
| 385 |
- |
| 386 |
- def test_b32decode_error(self): |
| 387 |
- self.assertRaises(TypeError, base64.b32decode, 'abc') |
| 388 |
- self.assertRaises(TypeError, base64.b32decode, 'ABCDEF==') |
| 389 |
- |
| 390 |
- def test_b16encode(self): |
| 391 |
- eq = self.assertEqual |
| 392 |
- eq(base64.b16encode('\x01\x02\xab\xcd\xef'), '0102ABCDEF') |
| 393 |
- eq(base64.b16encode('\x00'), '00') |
| 394 |
- |
| 395 |
- def test_b16decode(self): |
| 396 |
- eq = self.assertEqual |
| 397 |
- eq(base64.b16decode('0102ABCDEF'), '\x01\x02\xab\xcd\xef') |
| 398 |
- eq(base64.b16decode('00'), '\x00') |
| 399 |
- # Lower case is not allowed without a flag |
| 400 |
- self.assertRaises(TypeError, base64.b16decode, '0102abcdef') |
| 401 |
- # Case fold |
| 402 |
- eq(base64.b16decode('0102abcdef', True), '\x01\x02\xab\xcd\xef') |
| 403 |
- |
| 404 |
- |
| 405 |
- |
| 406 |
-#from test import test_support |
| 407 |
-#def test_main(): |
| 408 |
-# test_support.run_unittest(__name__) |
| 409 |
-# |
| 410 |
-#if __name__ == '__main__': |
| 411 |
-# test_main() |
| 412 |
Index: kitchen/kitchen2/tests/test_collections.py |
| 413 |
=================================================================== |
| 414 |
--- kitchen.orig/kitchen2/tests/test_collections.py 2017-08-28 00:47:21.493143026 -0400 |
| 415 |
+++ kitchen/kitchen2/tests/test_collections.py 2017-08-28 00:47:21.485143105 -0400 |
| 416 |
@@ -3,9 +3,6 @@ |
| 417 |
import unittest |
| 418 |
from nose import tools |
| 419 |
|
| 420 |
-from kitchen.pycompat24.sets import add_builtin_set |
| 421 |
-add_builtin_set() |
| 422 |
- |
| 423 |
from kitchen import collections |
| 424 |
|
| 425 |
def test_strict_dict_get_set(): |
| 426 |
Index: kitchen/kitchen2/tests/test_defaultdict.py |
| 427 |
=================================================================== |
| 428 |
--- kitchen.orig/kitchen2/tests/test_defaultdict.py 2017-08-28 00:47:21.493143026 -0400 |
| 429 |
+++ /dev/null 1970-01-01 00:00:00.000000000 +0000 |
| 430 |
@@ -1,180 +0,0 @@ |
| 431 |
-"""Unit tests for collections.defaultdict.""" |
| 432 |
- |
| 433 |
-import os |
| 434 |
-import copy |
| 435 |
-import tempfile |
| 436 |
-import unittest |
| 437 |
- |
| 438 |
-from kitchen.pycompat25.collections._defaultdict import defaultdict |
| 439 |
- |
| 440 |
-def foobar(): |
| 441 |
- return list |
| 442 |
- |
| 443 |
-class TestDefaultDict(unittest.TestCase): |
| 444 |
- |
| 445 |
- def test_basic(self): |
| 446 |
- d1 = defaultdict() |
| 447 |
- self.assertEqual(d1.default_factory, None) |
| 448 |
- d1.default_factory = list |
| 449 |
- d1[12].append(42) |
| 450 |
- self.assertEqual(d1, {12: [42]}) |
| 451 |
- d1[12].append(24) |
| 452 |
- self.assertEqual(d1, {12: [42, 24]}) |
| 453 |
- d1[13] |
| 454 |
- d1[14] |
| 455 |
- self.assertEqual(d1, {12: [42, 24], 13: [], 14: []}) |
| 456 |
- self.assert_(d1[12] is not d1[13] is not d1[14]) |
| 457 |
- d2 = defaultdict(list, foo=1, bar=2) |
| 458 |
- self.assertEqual(d2.default_factory, list) |
| 459 |
- self.assertEqual(d2, {"foo": 1, "bar": 2}) |
| 460 |
- self.assertEqual(d2["foo"], 1) |
| 461 |
- self.assertEqual(d2["bar"], 2) |
| 462 |
- self.assertEqual(d2[42], []) |
| 463 |
- self.assert_("foo" in d2) |
| 464 |
- self.assert_("foo" in d2.keys()) |
| 465 |
- self.assert_("bar" in d2) |
| 466 |
- self.assert_("bar" in d2.keys()) |
| 467 |
- self.assert_(42 in d2) |
| 468 |
- self.assert_(42 in d2.keys()) |
| 469 |
- self.assert_(12 not in d2) |
| 470 |
- self.assert_(12 not in d2.keys()) |
| 471 |
- d2.default_factory = None |
| 472 |
- self.assertEqual(d2.default_factory, None) |
| 473 |
- try: |
| 474 |
- d2[15] |
| 475 |
- except KeyError, err: |
| 476 |
- self.assertEqual(err.args, (15,)) |
| 477 |
- else: |
| 478 |
- self.fail("d2[15] didn't raise KeyError") |
| 479 |
- self.assertRaises(TypeError, defaultdict, 1) |
| 480 |
- |
| 481 |
- def test_missing(self): |
| 482 |
- d1 = defaultdict() |
| 483 |
- self.assertRaises(KeyError, d1.__missing__, 42) |
| 484 |
- d1.default_factory = list |
| 485 |
- self.assertEqual(d1.__missing__(42), []) |
| 486 |
- |
| 487 |
- def test_repr(self): |
| 488 |
- d1 = defaultdict() |
| 489 |
- self.assertEqual(d1.default_factory, None) |
| 490 |
- self.assertEqual(repr(d1), "defaultdict(None, {})") |
| 491 |
- self.assertEqual(eval(repr(d1)), d1) |
| 492 |
- d1[11] = 41 |
| 493 |
- self.assertEqual(repr(d1), "defaultdict(None, {11: 41})") |
| 494 |
- d2 = defaultdict(int) |
| 495 |
- self.assertEqual(d2.default_factory, int) |
| 496 |
- d2[12] = 42 |
| 497 |
- self.assertEqual(repr(d2), "defaultdict(<type 'int'>, {12: 42})") |
| 498 |
- def foo(): return 43 |
| 499 |
- d3 = defaultdict(foo) |
| 500 |
- |
| 501 |
- self.assert_(d3.default_factory is foo) |
| 502 |
- d3[13] |
| 503 |
- self.assertEqual(repr(d3), "defaultdict(%s, {13: 43})" % repr(foo)) |
| 504 |
- |
| 505 |
- def test_print(self): |
| 506 |
- d1 = defaultdict() |
| 507 |
- def foo(): return 42 |
| 508 |
- d2 = defaultdict(foo, {1: 2}) |
| 509 |
- # NOTE: We can't use tempfile.[Named]TemporaryFile since this |
| 510 |
- # code must exercise the tp_print C code, which only gets |
| 511 |
- # invoked for *real* files. |
| 512 |
- tfn = tempfile.mktemp() |
| 513 |
- try: |
| 514 |
- f = open(tfn, "w+") |
| 515 |
- try: |
| 516 |
- print >>f, d1 |
| 517 |
- print >>f, d2 |
| 518 |
- f.seek(0) |
| 519 |
- self.assertEqual(f.readline(), repr(d1) + "\n") |
| 520 |
- self.assertEqual(f.readline(), repr(d2) + "\n") |
| 521 |
- finally: |
| 522 |
- f.close() |
| 523 |
- finally: |
| 524 |
- os.remove(tfn) |
| 525 |
- |
| 526 |
- def test_copy(self): |
| 527 |
- d1 = defaultdict() |
| 528 |
- d2 = d1.copy() |
| 529 |
- self.assertEqual(type(d2), defaultdict) |
| 530 |
- self.assertEqual(d2.default_factory, None) |
| 531 |
- self.assertEqual(d2, {}) |
| 532 |
- d1.default_factory = list |
| 533 |
- d3 = d1.copy() |
| 534 |
- self.assertEqual(type(d3), defaultdict) |
| 535 |
- self.assertEqual(d3.default_factory, list) |
| 536 |
- self.assertEqual(d3, {}) |
| 537 |
- d1[42] |
| 538 |
- d4 = d1.copy() |
| 539 |
- self.assertEqual(type(d4), defaultdict) |
| 540 |
- self.assertEqual(d4.default_factory, list) |
| 541 |
- self.assertEqual(d4, {42: []}) |
| 542 |
- d4[12] |
| 543 |
- self.assertEqual(d4, {42: [], 12: []}) |
| 544 |
- |
| 545 |
- # Issue 6637: Copy fails for empty default dict |
| 546 |
- d = defaultdict() |
| 547 |
- d['a'] = 42 |
| 548 |
- e = d.copy() |
| 549 |
- self.assertEqual(e['a'], 42) |
| 550 |
- |
| 551 |
- def test_shallow_copy(self): |
| 552 |
- d1 = defaultdict(foobar, {1: 1}) |
| 553 |
- d2 = copy.copy(d1) |
| 554 |
- self.assertEqual(d2.default_factory, foobar) |
| 555 |
- self.assertEqual(d2, d1) |
| 556 |
- d1.default_factory = list |
| 557 |
- d2 = copy.copy(d1) |
| 558 |
- self.assertEqual(d2.default_factory, list) |
| 559 |
- self.assertEqual(d2, d1) |
| 560 |
- |
| 561 |
- def test_deep_copy(self): |
| 562 |
- d1 = defaultdict(foobar, {1: [1]}) |
| 563 |
- d2 = copy.deepcopy(d1) |
| 564 |
- self.assertEqual(d2.default_factory, foobar) |
| 565 |
- self.assertEqual(d2, d1) |
| 566 |
- self.assert_(d1[1] is not d2[1]) |
| 567 |
- d1.default_factory = list |
| 568 |
- d2 = copy.deepcopy(d1) |
| 569 |
- self.assertEqual(d2.default_factory, list) |
| 570 |
- self.assertEqual(d2, d1) |
| 571 |
- |
| 572 |
- def test_keyerror_without_factory(self): |
| 573 |
- d1 = defaultdict() |
| 574 |
- try: |
| 575 |
- d1[(1,)] |
| 576 |
- except KeyError, err: |
| 577 |
- self.assertEqual(err.args[0], (1,)) |
| 578 |
- else: |
| 579 |
- self.fail("expected KeyError") |
| 580 |
- |
| 581 |
- def test_recursive_repr(self): |
| 582 |
- # Issue2045: stack overflow when default_factory is a bound method |
| 583 |
- class sub(defaultdict): |
| 584 |
- def __init__(self): |
| 585 |
- self.default_factory = self._factory |
| 586 |
- def _factory(self): |
| 587 |
- return [] |
| 588 |
- d = sub() |
| 589 |
- self.assert_(repr(d).startswith( |
| 590 |
- "defaultdict(<bound method sub._factory of defaultdict(...")) |
| 591 |
- |
| 592 |
- # NOTE: printing a subclass of a builtin type does not call its |
| 593 |
- # tp_print slot. So this part is essentially the same test as above. |
| 594 |
- tfn = tempfile.mktemp() |
| 595 |
- try: |
| 596 |
- f = open(tfn, "w+") |
| 597 |
- try: |
| 598 |
- print >>f, d |
| 599 |
- finally: |
| 600 |
- f.close() |
| 601 |
- finally: |
| 602 |
- os.remove(tfn) |
| 603 |
- |
| 604 |
- |
| 605 |
-#from test import test_support |
| 606 |
-#def test_main(): |
| 607 |
-# test_support.run_unittest(TestDefaultDict) |
| 608 |
-# |
| 609 |
-#if __name__ == "__main__": |
| 610 |
-# test_main() |
| 611 |
Index: kitchen/kitchen2/tests/test_pycompat.py |
| 612 |
=================================================================== |
| 613 |
--- kitchen.orig/kitchen2/tests/test_pycompat.py 2017-08-28 00:47:21.493143026 -0400 |
| 614 |
+++ /dev/null 1970-01-01 00:00:00.000000000 +0000 |
| 615 |
@@ -1,25 +0,0 @@ |
| 616 |
-# -*- coding: utf-8 -*- |
| 617 |
-# |
| 618 |
-import unittest |
| 619 |
-from nose import tools |
| 620 |
- |
| 621 |
-class TestUsableModules(unittest.TestCase): |
| 622 |
- def test_subprocess(self): |
| 623 |
- '''Test that importing subprocess as a module works |
| 624 |
- ''' |
| 625 |
- try: |
| 626 |
- from kitchen.pycompat24.subprocess import Popen |
| 627 |
- except ImportError: |
| 628 |
- tools.ok_(False, 'Unable to import pycompat24.subprocess as a module') |
| 629 |
- try: |
| 630 |
- from kitchen.pycompat27.subprocess import Popen |
| 631 |
- except ImportError: |
| 632 |
- tools.ok_(False, 'Unable to import pycompat27.subprocess as a module') |
| 633 |
- |
| 634 |
- def test_base64(self): |
| 635 |
- '''Test that importing base64 as a module works |
| 636 |
- ''' |
| 637 |
- try: |
| 638 |
- from kitchen.pycompat24.base64 import b64encode |
| 639 |
- except ImportError: |
| 640 |
- tools.ok_(False, 'Unable to import pycompat24.base64 as a module') |
| 641 |
Index: kitchen/kitchen2/tests/test_pycompat24.py |
| 642 |
=================================================================== |
| 643 |
--- kitchen.orig/kitchen2/tests/test_pycompat24.py 2017-08-28 00:47:21.493143026 -0400 |
| 644 |
+++ /dev/null 1970-01-01 00:00:00.000000000 +0000 |
| 645 |
@@ -1,109 +0,0 @@ |
| 646 |
-# -*- coding: utf-8 -*- |
| 647 |
-# |
| 648 |
-import unittest |
| 649 |
-from nose import tools |
| 650 |
-from nose.plugins.skip import SkipTest |
| 651 |
- |
| 652 |
-import __builtin__ |
| 653 |
-import base64 as py_b64 |
| 654 |
-import warnings |
| 655 |
- |
| 656 |
-from kitchen.pycompat24 import sets |
| 657 |
-from kitchen.pycompat24.base64 import _base64 as base64 |
| 658 |
- |
| 659 |
-class TestSetsNoOverwrite(unittest.TestCase): |
| 660 |
- def setUp(self): |
| 661 |
- self.set_val = None |
| 662 |
- self.frozenset_val = None |
| 663 |
- if not hasattr(__builtin__, 'set'): |
| 664 |
- __builtin__.set = self.set_val |
| 665 |
- else: |
| 666 |
- self.set_val = __builtin__.set |
| 667 |
- if not hasattr(__builtin__, 'frozenset'): |
| 668 |
- __builtin__.frozenset = self.frozenset_val |
| 669 |
- else: |
| 670 |
- self.frozenset_val = __builtin__.frozenset |
| 671 |
- |
| 672 |
- def tearDown(self): |
| 673 |
- if self.frozenset_val == None: |
| 674 |
- del(__builtin__.frozenset) |
| 675 |
- if self.set_val == None: |
| 676 |
- del(__builtin__.set) |
| 677 |
- |
| 678 |
- def test_sets_dont_overwrite(self): |
| 679 |
- '''Test that importing sets when there's already a set and frozenset defined does not overwrite |
| 680 |
- ''' |
| 681 |
- sets.add_builtin_set() |
| 682 |
- tools.ok_(__builtin__.set == self.set_val) |
| 683 |
- tools.ok_(__builtin__.frozenset == self.frozenset_val) |
| 684 |
- |
| 685 |
-class TestDefineSets(unittest.TestCase): |
| 686 |
- def setUp(self): |
| 687 |
- warnings.simplefilter('ignore', DeprecationWarning) |
| 688 |
- self.set_val = None |
| 689 |
- self.frozenset_val = None |
| 690 |
- if hasattr(__builtin__, 'set'): |
| 691 |
- self.set_val = __builtin__.set |
| 692 |
- del(__builtin__.set) |
| 693 |
- if hasattr(__builtin__, 'frozenset'): |
| 694 |
- self.frozenset_val = __builtin__.frozenset |
| 695 |
- del(__builtin__.frozenset) |
| 696 |
- |
| 697 |
- def tearDown(self): |
| 698 |
- warnings.simplefilter('default', DeprecationWarning) |
| 699 |
- if self.set_val: |
| 700 |
- __builtin__.set = self.set_val |
| 701 |
- else: |
| 702 |
- del(__builtin__.set) |
| 703 |
- if self.frozenset_val: |
| 704 |
- __builtin__.frozenset = self.frozenset_val |
| 705 |
- else: |
| 706 |
- del(__builtin__.frozenset) |
| 707 |
- |
| 708 |
- def test_pycompat_defines_set(self): |
| 709 |
- '''Test that calling pycompat24.add_builtin_set() adds set and frozenset to __builtin__ |
| 710 |
- ''' |
| 711 |
- import sets as py_sets |
| 712 |
- sets.add_builtin_set() |
| 713 |
- if self.set_val: |
| 714 |
- tools.ok_(__builtin__.set == self.set_val) |
| 715 |
- tools.ok_(__builtin__.frozenset == self.frozenset_val) |
| 716 |
- else: |
| 717 |
- tools.ok_(__builtin__.set == py_sets.Set) |
| 718 |
- tools.ok_(__builtin__.frozenset == py_sets.ImmutableSet) |
| 719 |
- |
| 720 |
-class TestSubprocess(unittest.TestCase): |
| 721 |
- pass |
| 722 |
- |
| 723 |
-class TestBase64(unittest.TestCase): |
| 724 |
- b_byte_chars = ' '.join(map(chr, range(0, 256))) |
| 725 |
- b_byte_encoded = 'ACABIAIgAyAEIAUgBiAHIAggCSAKIAsgDCANIA4gDyAQIBEgEiATIBQgFSAWIBcgGCAZIBogGyAcIB0gHiAfICAgISAiICMgJCAlICYgJyAoICkgKiArICwgLSAuIC8gMCAxIDIgMyA0IDUgNiA3IDggOSA6IDsgPCA9ID4gPyBAIEEgQiBDIEQgRSBGIEcgSCBJIEogSyBMIE0gTiBPIFAgUSBSIFMgVCBVIFYgVyBYIFkgWiBbIFwgXSBeIF8gYCBhIGIgYyBkIGUgZiBnIGggaSBqIGsgbCBtIG4gbyBwIHEgciBzIHQgdSB2IHcgeCB5IHogeyB8IH0gfiB/IIAggSCCIIMghCCFIIYghyCIIIkgiiCLIIwgjSCOII8gkCCRIJIgkyCUIJUgliCXIJggmSCaIJsgnCCdIJ4gnyCgIKEgoiCjIKQgpSCmIKcgqCCpIKogqyCsIK0griCvILAgsSCyILMgtCC1ILYgtyC4ILkguiC7ILwgvSC+IL8gwCDBIMIgwyDEIMUgxiDHIMggySDKIMsgzCDNIM4gzyDQINEg0iDTINQg1SDWINcg2CDZINog2yDcIN0g3iDfIOAg4SDiIOMg5CDlIOYg5yDoIOkg6iDrIOwg7SDuIO8g8CDxIPIg8yD0IPUg9iD3IPgg+SD6IPsg/CD9IP4g/w==' |
| 726 |
- b_byte_encoded_urlsafe = 'ACABIAIgAyAEIAUgBiAHIAggCSAKIAsgDCANIA4gDyAQIBEgEiATIBQgFSAWIBcgGCAZIBogGyAcIB0gHiAfICAgISAiICMgJCAlICYgJyAoICkgKiArICwgLSAuIC8gMCAxIDIgMyA0IDUgNiA3IDggOSA6IDsgPCA9ID4gPyBAIEEgQiBDIEQgRSBGIEcgSCBJIEogSyBMIE0gTiBPIFAgUSBSIFMgVCBVIFYgVyBYIFkgWiBbIFwgXSBeIF8gYCBhIGIgYyBkIGUgZiBnIGggaSBqIGsgbCBtIG4gbyBwIHEgciBzIHQgdSB2IHcgeCB5IHogeyB8IH0gfiB_IIAggSCCIIMghCCFIIYghyCIIIkgiiCLIIwgjSCOII8gkCCRIJIgkyCUIJUgliCXIJggmSCaIJsgnCCdIJ4gnyCgIKEgoiCjIKQgpSCmIKcgqCCpIKogqyCsIK0griCvILAgsSCyILMgtCC1ILYgtyC4ILkguiC7ILwgvSC-IL8gwCDBIMIgwyDEIMUgxiDHIMggySDKIMsgzCDNIM4gzyDQINEg0iDTINQg1SDWINcg2CDZINog2yDcIN0g3iDfIOAg4SDiIOMg5CDlIOYg5yDoIOkg6iDrIOwg7SDuIO8g8CDxIPIg8yD0IPUg9iD3IPgg-SD6IPsg_CD9IP4g_w==' |
| 727 |
- |
| 728 |
- def test_base64_encode(self): |
| 729 |
- tools.ok_(base64.b64encode(self.b_byte_chars) == self.b_byte_encoded) |
| 730 |
- tools.ok_(base64.b64encode(self.b_byte_chars, altchars='-_') == self.b_byte_encoded_urlsafe) |
| 731 |
- tools.ok_(base64.standard_b64encode(self.b_byte_chars) == self.b_byte_encoded) |
| 732 |
- tools.ok_(base64.urlsafe_b64encode(self.b_byte_chars) == self.b_byte_encoded_urlsafe) |
| 733 |
- |
| 734 |
- tools.ok_(base64.b64encode(self.b_byte_chars) == self.b_byte_encoded) |
| 735 |
- tools.ok_(base64.b64encode(self.b_byte_chars, altchars='-_') == self.b_byte_encoded_urlsafe) |
| 736 |
- tools.ok_(base64.standard_b64encode(self.b_byte_chars) == self.b_byte_encoded) |
| 737 |
- tools.ok_(base64.urlsafe_b64encode(self.b_byte_chars) == self.b_byte_encoded_urlsafe) |
| 738 |
- |
| 739 |
- def test_base64_decode(self): |
| 740 |
- tools.ok_(base64.b64decode(self.b_byte_encoded) == self.b_byte_chars) |
| 741 |
- tools.ok_(base64.b64decode(self.b_byte_encoded_urlsafe, altchars='-_') == self.b_byte_chars) |
| 742 |
- tools.ok_(base64.standard_b64decode(self.b_byte_encoded) == self.b_byte_chars) |
| 743 |
- tools.ok_(base64.urlsafe_b64decode(self.b_byte_encoded_urlsafe) == self.b_byte_chars) |
| 744 |
- |
| 745 |
- tools.ok_(base64.b64decode(self.b_byte_encoded) == self.b_byte_chars) |
| 746 |
- tools.ok_(base64.b64decode(self.b_byte_encoded_urlsafe, altchars='-_') == self.b_byte_chars) |
| 747 |
- tools.ok_(base64.standard_b64decode(self.b_byte_encoded) == self.b_byte_chars) |
| 748 |
- tools.ok_(base64.urlsafe_b64decode(self.b_byte_encoded_urlsafe) == self.b_byte_chars) |
| 749 |
- |
| 750 |
- def test_base64_stdlib_compat(self): |
| 751 |
- if not hasattr(py_b64, 'b64encode'): |
| 752 |
- raise SkipTest('Python-2.3 doesn\'t have b64encode to compare against') |
| 753 |
- tools.ok_(base64.b64encode(self.b_byte_chars) == py_b64.b64encode(self.b_byte_chars)) |
| 754 |
- tools.ok_(base64.b64decode(self.b_byte_chars) == py_b64.b64decode(self.b_byte_chars)) |
| 755 |
Index: kitchen/kitchen3/docs/api-overview.rst |
| 756 |
=================================================================== |
| 757 |
--- kitchen.orig/kitchen3/docs/api-overview.rst 2017-08-28 00:47:21.493143026 -0400 |
| 758 |
+++ kitchen/kitchen3/docs/api-overview.rst 2017-08-28 00:47:21.489143066 -0400 |
| 759 |
@@ -16,9 +16,6 @@ |
| 760 |
api-collections |
| 761 |
api-iterutils |
| 762 |
api-versioning |
| 763 |
- api-pycompat24 |
| 764 |
- api-pycompat25 |
| 765 |
- api-pycompat27 |
| 766 |
api-exceptions |
| 767 |
|
| 768 |
.. _`project webpage`: https://fedorahosted.org/kitchen |
| 769 |
Index: kitchen/kitchen3/docs/api-pycompat24.rst |
| 770 |
=================================================================== |
| 771 |
--- kitchen.orig/kitchen3/docs/api-pycompat24.rst 2017-08-28 00:47:21.493143026 -0400 |
| 772 |
+++ /dev/null 1970-01-01 00:00:00.000000000 +0000 |
| 773 |
@@ -1,34 +0,0 @@ |
| 774 |
-======================= |
| 775 |
-Python 2.4 Compatibiity |
| 776 |
-======================= |
| 777 |
- |
| 778 |
- |
| 779 |
-------------------- |
| 780 |
-Sets for python-2.3 |
| 781 |
-------------------- |
| 782 |
- |
| 783 |
-.. automodule:: kitchen.pycompat24.sets |
| 784 |
-.. autofunction:: kitchen.pycompat24.sets.add_builtin_set |
| 785 |
- |
| 786 |
----------------------------------- |
| 787 |
-Partial new style base64 interface |
| 788 |
----------------------------------- |
| 789 |
- |
| 790 |
-.. automodule:: kitchen.pycompat24.base64 |
| 791 |
- :members: |
| 792 |
- |
| 793 |
----------- |
| 794 |
-Subprocess |
| 795 |
----------- |
| 796 |
- |
| 797 |
-.. seealso:: |
| 798 |
- |
| 799 |
- :mod:`kitchen.pycompat27.subprocess` |
| 800 |
- Kitchen includes the python-2.7 version of subprocess which has a new |
| 801 |
- function, :func:`~kitchen.pycompat27.subprocess.check_output`. When |
| 802 |
- you import :mod:`pycompat24.subprocess` you will be getting the |
| 803 |
- python-2.7 version of subprocess rather than the 2.4 version (where |
| 804 |
- subprocess first appeared). This choice was made so that we can |
| 805 |
- concentrate our efforts on keeping the single version of subprocess up |
| 806 |
- to date rather than working on a 2.4 version that very few people |
| 807 |
- would need specifically. |
| 808 |
Index: kitchen/kitchen3/docs/api-pycompat25.rst |
| 809 |
=================================================================== |
| 810 |
--- kitchen.orig/kitchen3/docs/api-pycompat25.rst 2017-08-28 00:47:21.493143026 -0400 |
| 811 |
+++ /dev/null 1970-01-01 00:00:00.000000000 +0000 |
| 812 |
@@ -1,8 +0,0 @@ |
| 813 |
-======================== |
| 814 |
-Python 2.5 Compatibility |
| 815 |
-======================== |
| 816 |
- |
| 817 |
-.. automodule:: kitchen.pycompat25 |
| 818 |
- |
| 819 |
-.. automodule:: kitchen.pycompat25.collections.defaultdict |
| 820 |
- |
| 821 |
Index: kitchen/kitchen3/docs/api-pycompat27.rst |
| 822 |
=================================================================== |
| 823 |
--- kitchen.orig/kitchen3/docs/api-pycompat27.rst 2017-08-28 00:47:21.493143026 -0400 |
| 824 |
+++ /dev/null 1970-01-01 00:00:00.000000000 +0000 |
| 825 |
@@ -1,35 +0,0 @@ |
| 826 |
-======================== |
| 827 |
-Python 2.7 Compatibility |
| 828 |
-======================== |
| 829 |
- |
| 830 |
-.. module:: kitchen.pycompat27.subprocess |
| 831 |
- |
| 832 |
--------------------------- |
| 833 |
-Subprocess from Python 2.7 |
| 834 |
--------------------------- |
| 835 |
- |
| 836 |
-The :mod:`subprocess` module included here is a direct import from |
| 837 |
-python-2.7's |stdlib|_. You can access it via:: |
| 838 |
- |
| 839 |
- >>> from kitchen.pycompat27 import subprocess |
| 840 |
- |
| 841 |
-The motivation for including this module is that various API changing |
| 842 |
-improvements have been made to subprocess over time. The following is a list |
| 843 |
-of the known changes to :mod:`subprocess` with the python version they were |
| 844 |
-introduced in: |
| 845 |
- |
| 846 |
-==================================== === |
| 847 |
-New API Feature Ver |
| 848 |
-==================================== === |
| 849 |
-:exc:`subprocess.CalledProcessError` 2.5 |
| 850 |
-:func:`subprocess.check_call` 2.5 |
| 851 |
-:func:`subprocess.check_output` 2.7 |
| 852 |
-:meth:`subprocess.Popen.send_signal` 2.6 |
| 853 |
-:meth:`subprocess.Popen.terminate` 2.6 |
| 854 |
-:meth:`subprocess.Popen.kill` 2.6 |
| 855 |
-==================================== === |
| 856 |
- |
| 857 |
-.. seealso:: |
| 858 |
- |
| 859 |
- The stdlib :mod:`subprocess` documenation |
| 860 |
- For complete documentation on how to use subprocess |
| 861 |
Index: kitchen/kitchen3/tests/subprocessdata/sigchild_ignore.py |
| 862 |
=================================================================== |
| 863 |
--- kitchen.orig/kitchen3/tests/subprocessdata/sigchild_ignore.py 2017-08-28 00:47:21.493143026 -0400 |
| 864 |
+++ /dev/null 1970-01-01 00:00:00.000000000 +0000 |
| 865 |
@@ -1,11 +0,0 @@ |
| 866 |
-import os |
| 867 |
-import signal, sys |
| 868 |
-sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..', '..')) |
| 869 |
- |
| 870 |
-from kitchen.pycompat27.subprocess import _subprocess as subprocess |
| 871 |
- |
| 872 |
-# On Linux this causes os.waitpid to fail with OSError as the OS has already |
| 873 |
-# reaped our child process. The wait() passing the OSError on to the caller |
| 874 |
-# and causing us to exit with an error is what we are testing against. |
| 875 |
-signal.signal(signal.SIGCHLD, signal.SIG_IGN) |
| 876 |
-subprocess.Popen([sys.executable, '-c', 'print("albatross")']).wait() |
| 877 |
Index: kitchen/kitchen3/tests/test__all__.py |
| 878 |
=================================================================== |
| 879 |
--- kitchen.orig/kitchen3/tests/test__all__.py 2017-08-28 00:47:21.493143026 -0400 |
| 880 |
+++ kitchen/kitchen3/tests/test__all__.py 2017-08-28 00:47:21.489143066 -0400 |
| 881 |
@@ -4,8 +4,6 @@ |
| 882 |
import os |
| 883 |
import types |
| 884 |
import warnings |
| 885 |
-from kitchen.pycompat24.sets import add_builtin_set |
| 886 |
-add_builtin_set() |
| 887 |
|
| 888 |
def logit(msg): |
| 889 |
log = open('/var/tmp/test.log', 'a') |
| 890 |
Index: kitchen/kitchen3/tests/test_collections.py |
| 891 |
=================================================================== |
| 892 |
--- kitchen.orig/kitchen3/tests/test_collections.py 2017-08-28 00:47:21.493143026 -0400 |
| 893 |
+++ kitchen/kitchen3/tests/test_collections.py 2017-08-28 00:47:21.489143066 -0400 |
| 894 |
@@ -3,9 +3,6 @@ |
| 895 |
import unittest |
| 896 |
from nose import tools |
| 897 |
|
| 898 |
-from kitchen.pycompat24.sets import add_builtin_set |
| 899 |
-add_builtin_set() |
| 900 |
- |
| 901 |
from kitchen import collections |
| 902 |
|
| 903 |
def test_strict_dict_get_set(): |
| 904 |
Index: kitchen/kitchen3/tests/test_deprecation_py3.py |
| 905 |
=================================================================== |
| 906 |
--- kitchen.orig/kitchen3/tests/test_deprecation_py3.py 2017-08-28 00:47:21.493143026 -0400 |
| 907 |
+++ /dev/null 1970-01-01 00:00:00.000000000 +0000 |
| 908 |
@@ -1,65 +0,0 @@ |
| 909 |
-# -*- coding: utf-8 -*- |
| 910 |
- |
| 911 |
-from nose import tools |
| 912 |
- |
| 913 |
-import sys |
| 914 |
-import warnings |
| 915 |
- |
| 916 |
-import importlib |
| 917 |
-from kitchen.pycompat25.collections import defaultdict |
| 918 |
- |
| 919 |
-class TestPendingDeprecationModules(object): |
| 920 |
- def __init__(self): |
| 921 |
- kitchen_path = 'kitchen' |
| 922 |
- collections_path = 'kitchen/collections' |
| 923 |
- pycompat24_path = 'kitchen/pycompat24' |
| 924 |
- pycompat25_path = 'kitchen/pycompat25' |
| 925 |
- pycompat27_path = 'kitchen/pycompat27' |
| 926 |
- |
| 927 |
- self.module_data = ( |
| 928 |
- ('strictdict', 'kitchen.collections.strictdict', collections_path), |
| 929 |
- ('pycompat24', 'kitchen.pycompat24', kitchen_path), |
| 930 |
- ('base64', 'kitchen.pycompat24.base64', pycompat24_path), |
| 931 |
- ('sets', 'kitchen.pycompat24.sets', pycompat24_path), |
| 932 |
- ('subprocess', 'kitchen.pycompat24.subprocess', pycompat24_path), |
| 933 |
- ('pycompat25', 'kitchen.pycompat25', kitchen_path), |
| 934 |
- ('collections', 'kitchen.pycompat25.collections', pycompat25_path), |
| 935 |
- ('pycompat27', 'kitchen.pycompat27', kitchen_path), |
| 936 |
- ('subprocess', 'kitchen.pycompat27.subprocess', pycompat27_path), |
| 937 |
- ) |
| 938 |
- |
| 939 |
- def setUp(self): |
| 940 |
- for module in sys.modules.values(): |
| 941 |
- if hasattr(module, '__warningregistry__'): |
| 942 |
- del module.__warningregistry__ |
| 943 |
- |
| 944 |
- def check_modules(self, module_name, module_fqn, module_path): |
| 945 |
- with warnings.catch_warnings(record=True) as w: |
| 946 |
- warnings.simplefilter('always') |
| 947 |
- # imp.load_module will load even if it has already been loaded. |
| 948 |
- # We need to ensure that happens in order to trigger the |
| 949 |
- # deprecation warnings |
| 950 |
- importlib.find_loader(module_fqn, module_path).load_module() |
| 951 |
- warning_raised = False |
| 952 |
- for warning in (e.message for e in w): |
| 953 |
- if isinstance(warning, PendingDeprecationWarning) and \ |
| 954 |
- ('%s is deprecated' % module_name) in warning.args[0]: |
| 955 |
- warning_raised = True |
| 956 |
- break |
| 957 |
- tools.assert_true(warning_raised, msg='%s did not raise a PendingDeprecationWarning' % module_fqn) |
| 958 |
- |
| 959 |
- def test_modules(self): |
| 960 |
- for mod in self.module_data: |
| 961 |
- yield self.check_modules, mod[0], mod[1], mod[2] |
| 962 |
- |
| 963 |
- def test_defaultdict(self): |
| 964 |
- with warnings.catch_warnings(record=True) as w: |
| 965 |
- warnings.simplefilter('always') |
| 966 |
- defaultdict() |
| 967 |
- warning_raised = False |
| 968 |
- for warning in (e.message for e in w): |
| 969 |
- if isinstance(warning, PendingDeprecationWarning) and \ |
| 970 |
- ('defaultdict is deprecated') in warning.args[0]: |
| 971 |
- warning_raised = True |
| 972 |
- break |
| 973 |
- tools.assert_true(warning_raised, msg='kitchen.pycompat25.collections.defaultdict did not raise a PendingDeprecationWarning') |
| 974 |
Index: kitchen/kitchen3/tests/test_pycompat.py |
| 975 |
=================================================================== |
| 976 |
--- kitchen.orig/kitchen3/tests/test_pycompat.py 2017-08-28 00:47:21.493143026 -0400 |
| 977 |
+++ /dev/null 1970-01-01 00:00:00.000000000 +0000 |
| 978 |
@@ -1,25 +0,0 @@ |
| 979 |
-# -*- coding: utf-8 -*- |
| 980 |
-# |
| 981 |
-import unittest |
| 982 |
-from nose import tools |
| 983 |
- |
| 984 |
-class TestUsableModules(unittest.TestCase): |
| 985 |
- def test_subprocess(self): |
| 986 |
- '''Test that importing subprocess as a module works |
| 987 |
- ''' |
| 988 |
- try: |
| 989 |
- from kitchen.pycompat24.subprocess import Popen |
| 990 |
- except ImportError: |
| 991 |
- tools.ok_(False, 'Unable to import pycompat24.subprocess as a module') |
| 992 |
- try: |
| 993 |
- from kitchen.pycompat27.subprocess import Popen |
| 994 |
- except ImportError: |
| 995 |
- tools.ok_(False, 'Unable to import pycompat27.subprocess as a module') |
| 996 |
- |
| 997 |
- def test_base64(self): |
| 998 |
- '''Test that importing base64 as a module works |
| 999 |
- ''' |
| 1000 |
- try: |
| 1001 |
- from kitchen.pycompat24.base64 import b64encode |
| 1002 |
- except ImportError: |
| 1003 |
- tools.ok_(False, 'Unable to import pycompat24.base64 as a module') |
| 1004 |
Index: kitchen/setup.py |
| 1005 |
=================================================================== |
| 1006 |
--- kitchen.orig/setup.py 2017-08-28 00:47:21.493143026 -0400 |
| 1007 |
+++ kitchen/setup.py 2017-08-28 00:47:21.489143066 -0400 |
| 1008 |
@@ -15,13 +15,6 @@ |
| 1009 |
'kitchen.iterutils', |
| 1010 |
'kitchen.collections', |
| 1011 |
'kitchen.text', |
| 1012 |
- 'kitchen.pycompat24', |
| 1013 |
- 'kitchen.pycompat24.base64', |
| 1014 |
- 'kitchen.pycompat24.sets', |
| 1015 |
- 'kitchen.pycompat25', |
| 1016 |
- 'kitchen.pycompat25.collections', |
| 1017 |
- 'kitchen.pycompat27', |
| 1018 |
- 'kitchen.pycompat27.subprocess', |
| 1019 |
] |
| 1020 |
elif sys.version_info[0] == 3: |
| 1021 |
source_dir = 'kitchen3' |
| 1022 |
@@ -32,13 +25,6 @@ |
| 1023 |
'kitchen.iterutils', |
| 1024 |
'kitchen.collections', |
| 1025 |
'kitchen.text', |
| 1026 |
- 'kitchen.pycompat24', |
| 1027 |
- 'kitchen.pycompat24.base64', |
| 1028 |
- 'kitchen.pycompat24.sets', |
| 1029 |
- 'kitchen.pycompat25', |
| 1030 |
- 'kitchen.pycompat25.collections', |
| 1031 |
- 'kitchen.pycompat27', |
| 1032 |
- 'kitchen.pycompat27.subprocess', |
| 1033 |
] |
| 1034 |
else: |
| 1035 |
raise NotImplementedError("Python version unsupported %r" % sys.version) |
| 1036 |
Index: kitchen/kitchen2/tests/test_subprocess.py |
| 1037 |
=================================================================== |
| 1038 |
--- kitchen.orig/kitchen2/tests/test_subprocess.py 2017-08-28 00:41:05.800909917 -0400 |
| 1039 |
+++ /dev/null 1970-01-01 00:00:00.000000000 +0000 |
| 1040 |
@@ -1,1467 +0,0 @@ |
| 1041 |
-import unittest |
| 1042 |
-from nose.plugins.skip import SkipTest |
| 1043 |
-from kitchen.pycompat27.subprocess import _subprocess as subprocess |
| 1044 |
-import sys |
| 1045 |
-import StringIO |
| 1046 |
-import signal |
| 1047 |
-import os |
| 1048 |
-import errno |
| 1049 |
-import tempfile |
| 1050 |
-import time |
| 1051 |
-import re |
| 1052 |
-# Not available on python2.6 or less |
| 1053 |
-#import sysconfig |
| 1054 |
- |
| 1055 |
-mswindows = (sys.platform == "win32") |
| 1056 |
- |
| 1057 |
-# |
| 1058 |
-# Depends on the following external programs: Python |
| 1059 |
-# |
| 1060 |
- |
| 1061 |
-if mswindows: |
| 1062 |
- SETBINARY = ('import msvcrt; msvcrt.setmode(sys.stdout.fileno(), ' |
| 1063 |
- 'os.O_BINARY);') |
| 1064 |
-else: |
| 1065 |
- SETBINARY = '' |
| 1066 |
- |
| 1067 |
-def reap_children(): |
| 1068 |
- """Use this function at the end of test_main() whenever sub-processes |
| 1069 |
- are started. This will help ensure that no extra children (zombies) |
| 1070 |
- stick around to hog resources and create problems when looking |
| 1071 |
- for refleaks. |
| 1072 |
- """ |
| 1073 |
- |
| 1074 |
- # Reap all our dead child processes so we don't leave zombies around. |
| 1075 |
- # These hog resources and might be causing some of the buildbots to die. |
| 1076 |
- if hasattr(os, 'waitpid'): |
| 1077 |
- any_process = -1 |
| 1078 |
- while True: |
| 1079 |
- try: |
| 1080 |
- # This will raise an exception on Windows. That's ok. |
| 1081 |
- pid, status = os.waitpid(any_process, os.WNOHANG) |
| 1082 |
- if pid == 0: |
| 1083 |
- break |
| 1084 |
- except: |
| 1085 |
- break |
| 1086 |
- |
| 1087 |
-test_support = None |
| 1088 |
-try: |
| 1089 |
- from test import test_support |
| 1090 |
- if not hasattr(test_support, 'reap_children'): |
| 1091 |
- # No reap_children in python-2.3 |
| 1092 |
- test_support.reap_children = reap_children |
| 1093 |
-except ImportError: |
| 1094 |
- pass |
| 1095 |
- |
| 1096 |
-# In a debug build, stuff like "[6580 refs]" is printed to stderr at |
| 1097 |
-# shutdown time. That frustrates tests trying to check stderr produced |
| 1098 |
-# from a spawned Python process. |
| 1099 |
-def remove_stderr_debug_decorations(stderr): |
| 1100 |
- return re.sub(r"\[\d+ refs\]\r?\n?$", "", stderr) |
| 1101 |
- |
| 1102 |
-try: |
| 1103 |
- mkstemp = tempfile.mkstemp |
| 1104 |
-except AttributeError: |
| 1105 |
- # tempfile.mkstemp is not available |
| 1106 |
- def mkstemp(): |
| 1107 |
- """Replacement for mkstemp, calling mktemp.""" |
| 1108 |
- fname = tempfile.mktemp() |
| 1109 |
- return os.open(fname, os.O_RDWR|os.O_CREAT), fname |
| 1110 |
- |
| 1111 |
- |
| 1112 |
-class BaseTestCase(unittest.TestCase): |
| 1113 |
- def __init__(self, *args, **kwargs): |
| 1114 |
- unittest.TestCase.__init__(self, *args, **kwargs) |
| 1115 |
- if not hasattr(self, '_cleanups'): |
| 1116 |
- self._cleanups = [] |
| 1117 |
- if not hasattr(self, 'addCleanup'): |
| 1118 |
- self.addCleanup = self._addCleanup |
| 1119 |
- |
| 1120 |
- def _addCleanup(self, function, *args, **kwargs): |
| 1121 |
- self._cleanups.append((function, args, kwargs)) |
| 1122 |
- |
| 1123 |
- def setUp(self): |
| 1124 |
- # Try to minimize the number of children we have so this test |
| 1125 |
- # doesn't crash on some buildbots (Alphas in particular). |
| 1126 |
- if test_support: |
| 1127 |
- test_support.reap_children() |
| 1128 |
- |
| 1129 |
- def tearDown(self): |
| 1130 |
- for inst in subprocess._active: |
| 1131 |
- inst.wait() |
| 1132 |
- subprocess._cleanup() |
| 1133 |
- # assertFalse is not available in python-2.3 |
| 1134 |
- self.failIf(subprocess._active, "subprocess._active not empty") |
| 1135 |
- |
| 1136 |
- if not hasattr(self, 'doCleanups'): |
| 1137 |
- ok = True |
| 1138 |
- while self._cleanups: |
| 1139 |
- function, args, kwargs = self._cleanups.pop(-1) |
| 1140 |
- try: |
| 1141 |
- function(*args, **kwargs) |
| 1142 |
- except Exception: |
| 1143 |
- ok = False |
| 1144 |
- |
| 1145 |
- def assertStderrEqual(self, stderr, expected, msg=None): |
| 1146 |
- # In a debug build, stuff like "[6580 refs]" is printed to stderr at |
| 1147 |
- # shutdown time. That frustrates tests trying to check stderr produced |
| 1148 |
- # from a spawned Python process. |
| 1149 |
- actual = re.sub(r"\[\d+ refs\]\r?\n?$", "", stderr) |
| 1150 |
- self.assertEqual(actual, expected, msg) |
| 1151 |
- |
| 1152 |
- |
| 1153 |
-class ProcessTestCase(BaseTestCase): |
| 1154 |
- |
| 1155 |
- def test_call_seq(self): |
| 1156 |
- # call() function with sequence argument |
| 1157 |
- rc = subprocess.call([sys.executable, "-c", |
| 1158 |
- "import sys; sys.exit(47)"]) |
| 1159 |
- self.assertEqual(rc, 47) |
| 1160 |
- |
| 1161 |
- def test_check_call_zero(self): |
| 1162 |
- # check_call() function with zero return code |
| 1163 |
- rc = subprocess.check_call([sys.executable, "-c", |
| 1164 |
- "import sys; sys.exit(0)"]) |
| 1165 |
- self.assertEqual(rc, 0) |
| 1166 |
- |
| 1167 |
- def test_check_call_nonzero(self): |
| 1168 |
- # check_call() function with non-zero return code |
| 1169 |
- #with self.assertRaises(subprocess.CalledProcessError) as c: |
| 1170 |
- try: |
| 1171 |
- subprocess.check_call([sys.executable, "-c", |
| 1172 |
- "import sys; sys.exit(47)"]) |
| 1173 |
- #self.assertEqual(c.exception.returncode, 47) |
| 1174 |
- except subprocess.CalledProcessError, e: |
| 1175 |
- self.assertEqual(e.returncode, 47) |
| 1176 |
- else: |
| 1177 |
- self.fail("Expected CalledProcessError") |
| 1178 |
- |
| 1179 |
- def test_check_output(self): |
| 1180 |
- # check_output() function with zero return code |
| 1181 |
- output = subprocess.check_output( |
| 1182 |
- [sys.executable, "-c", "print 'BDFL'"]) |
| 1183 |
- #self.assertIn('BDFL', output) |
| 1184 |
- self.assert_('BDFL' in output) |
| 1185 |
- |
| 1186 |
- def test_check_output_nonzero(self): |
| 1187 |
- # check_call() function with non-zero return code |
| 1188 |
- #with self.assertRaises(subprocess.CalledProcessError) as c: |
| 1189 |
- try: |
| 1190 |
- subprocess.check_output( |
| 1191 |
- [sys.executable, "-c", "import sys; sys.exit(5)"]) |
| 1192 |
- #self.assertEqual(c.exception.returncode, 5) |
| 1193 |
- except subprocess.CalledProcessError, e: |
| 1194 |
- self.assertEqual(e.returncode, 5) |
| 1195 |
- else: |
| 1196 |
- self.fail("Expected CalledProcessError") |
| 1197 |
- |
| 1198 |
- def test_check_output_stderr(self): |
| 1199 |
- # check_output() function stderr redirected to stdout |
| 1200 |
- output = subprocess.check_output( |
| 1201 |
- [sys.executable, "-c", "import sys; sys.stderr.write('BDFL')"], |
| 1202 |
- stderr=subprocess.STDOUT) |
| 1203 |
- #self.assertIn('BDFL', output) |
| 1204 |
- self.assert_('BDFL' in output) |
| 1205 |
- |
| 1206 |
- def test_check_output_stdout_arg(self): |
| 1207 |
- # check_output() function stderr redirected to stdout |
| 1208 |
- #with self.assertRaises(ValueError) as c: |
| 1209 |
- try: |
| 1210 |
- output = subprocess.check_output( |
| 1211 |
- [sys.executable, "-c", "print 'will not be run'"], |
| 1212 |
- stdout=sys.stdout) |
| 1213 |
- #self.fail("Expected ValueError when stdout arg supplied.") |
| 1214 |
- #self.assertIn('stdout', c.exception.args[0]) |
| 1215 |
- except ValueError, e: |
| 1216 |
- #self.assertIn('stdout', e.args[0]) |
| 1217 |
- self.assert_('stdout' in e.args[0]) |
| 1218 |
- else: |
| 1219 |
- self.fail("Expected ValueError when stdout arg supplied.") |
| 1220 |
- |
| 1221 |
- def test_call_kwargs(self): |
| 1222 |
- # call() function with keyword args |
| 1223 |
- newenv = os.environ.copy() |
| 1224 |
- newenv["FRUIT"] = "banana" |
| 1225 |
- rc = subprocess.call([sys.executable, "-c", |
| 1226 |
- 'import sys, os;' |
| 1227 |
- 'sys.exit(os.getenv("FRUIT")=="banana")'], |
| 1228 |
- env=newenv) |
| 1229 |
- self.assertEqual(rc, 1) |
| 1230 |
- |
| 1231 |
- def test_invalid_args(self): |
| 1232 |
- # Popen() called with invalid arguments should raise TypeError |
| 1233 |
- # but Popen.__del__ should not complain (issue #12085) |
| 1234 |
- #with test_support.captured_stderr() as s: |
| 1235 |
- orig_stderr = getattr(sys, 'stderr') |
| 1236 |
- setattr(sys, 'stderr', StringIO.StringIO()) |
| 1237 |
- s = sys.stderr |
| 1238 |
- try: |
| 1239 |
- try: |
| 1240 |
- subprocess.Popen(invalid_arg_name=1) |
| 1241 |
- except TypeError: |
| 1242 |
- pass |
| 1243 |
- except: |
| 1244 |
- self.fail("Expected TypeError") |
| 1245 |
- else: |
| 1246 |
- self.fail("Expected TypeError") |
| 1247 |
- argcount = subprocess.Popen.__init__.func_code.co_argcount |
| 1248 |
- too_many_args = [0] * (argcount + 1) |
| 1249 |
- try: |
| 1250 |
- subprocess.Popen(*too_many_args) |
| 1251 |
- except TypeError: |
| 1252 |
- pass |
| 1253 |
- except: |
| 1254 |
- self.fail("Expected TypeError") |
| 1255 |
- else: |
| 1256 |
- self.fail("Expected TypeError") |
| 1257 |
- finally: |
| 1258 |
- setattr(sys, 'stderr', orig_stderr) |
| 1259 |
- self.assertEqual(s.getvalue(), '') |
| 1260 |
- |
| 1261 |
- def test_stdin_none(self): |
| 1262 |
- # .stdin is None when not redirected |
| 1263 |
- p = subprocess.Popen([sys.executable, "-c", 'print "banana"'], |
| 1264 |
- stdout=subprocess.PIPE, stderr=subprocess.PIPE) |
| 1265 |
- self.addCleanup(p.stdout.close) |
| 1266 |
- self.addCleanup(p.stderr.close) |
| 1267 |
- p.wait() |
| 1268 |
- self.assertEqual(p.stdin, None) |
| 1269 |
- |
| 1270 |
- def test_stdout_none(self): |
| 1271 |
- # .stdout is None when not redirected |
| 1272 |
- p = subprocess.Popen([sys.executable, "-c", |
| 1273 |
- 'print " this bit of output is from a ' |
| 1274 |
- 'test of stdout in a different ' |
| 1275 |
- 'process ..."'], |
| 1276 |
- stdin=subprocess.PIPE, stderr=subprocess.PIPE) |
| 1277 |
- self.addCleanup(p.stdin.close) |
| 1278 |
- self.addCleanup(p.stderr.close) |
| 1279 |
- p.wait() |
| 1280 |
- self.assertEqual(p.stdout, None) |
| 1281 |
- |
| 1282 |
- def test_stderr_none(self): |
| 1283 |
- # .stderr is None when not redirected |
| 1284 |
- p = subprocess.Popen([sys.executable, "-c", 'print "banana"'], |
| 1285 |
- stdin=subprocess.PIPE, stdout=subprocess.PIPE) |
| 1286 |
- self.addCleanup(p.stdout.close) |
| 1287 |
- self.addCleanup(p.stdin.close) |
| 1288 |
- p.wait() |
| 1289 |
- self.assertEqual(p.stderr, None) |
| 1290 |
- |
| 1291 |
- def test_executable_with_cwd(self): |
| 1292 |
- python_dir = os.path.dirname(os.path.realpath(sys.executable)) |
| 1293 |
- p = subprocess.Popen(["somethingyoudonthave", "-c", |
| 1294 |
- "import sys; sys.exit(47)"], |
| 1295 |
- executable=sys.executable, cwd=python_dir) |
| 1296 |
- p.wait() |
| 1297 |
- self.assertEqual(p.returncode, 47) |
| 1298 |
- |
| 1299 |
- # Not available on python2.3 and we know we're not building python itself |
| 1300 |
- #@unittest.skipIf(sysconfig.is_python_build(), |
| 1301 |
- # "need an installed Python. See #7774") |
| 1302 |
- def test_executable_without_cwd(self): |
| 1303 |
- # For a normal installation, it should work without 'cwd' |
| 1304 |
- # argument. For test runs in the build directory, see #7774. |
| 1305 |
- p = subprocess.Popen(["somethingyoudonthave", "-c", |
| 1306 |
- "import sys; sys.exit(47)"], |
| 1307 |
- executable=sys.executable) |
| 1308 |
- p.wait() |
| 1309 |
- self.assertEqual(p.returncode, 47) |
| 1310 |
- |
| 1311 |
- def test_stdin_pipe(self): |
| 1312 |
- # stdin redirection |
| 1313 |
- p = subprocess.Popen([sys.executable, "-c", |
| 1314 |
- 'import sys; sys.exit(sys.stdin.read() == "pear")'], |
| 1315 |
- stdin=subprocess.PIPE) |
| 1316 |
- p.stdin.write("pear") |
| 1317 |
- p.stdin.close() |
| 1318 |
- p.wait() |
| 1319 |
- self.assertEqual(p.returncode, 1) |
| 1320 |
- |
| 1321 |
- def test_stdin_filedes(self): |
| 1322 |
- # stdin is set to open file descriptor |
| 1323 |
- tf = tempfile.TemporaryFile() |
| 1324 |
- d = tf.fileno() |
| 1325 |
- os.write(d, "pear") |
| 1326 |
- os.lseek(d, 0, 0) |
| 1327 |
- p = subprocess.Popen([sys.executable, "-c", |
| 1328 |
- 'import sys; sys.exit(sys.stdin.read() == "pear")'], |
| 1329 |
- stdin=d) |
| 1330 |
- p.wait() |
| 1331 |
- self.assertEqual(p.returncode, 1) |
| 1332 |
- |
| 1333 |
- def test_stdin_fileobj(self): |
| 1334 |
- # stdin is set to open file object |
| 1335 |
- tf = tempfile.TemporaryFile() |
| 1336 |
- tf.write("pear") |
| 1337 |
- tf.seek(0) |
| 1338 |
- p = subprocess.Popen([sys.executable, "-c", |
| 1339 |
- 'import sys; sys.exit(sys.stdin.read() == "pear")'], |
| 1340 |
- stdin=tf) |
| 1341 |
- p.wait() |
| 1342 |
- self.assertEqual(p.returncode, 1) |
| 1343 |
- |
| 1344 |
- def test_stdout_pipe(self): |
| 1345 |
- # stdout redirection |
| 1346 |
- p = subprocess.Popen([sys.executable, "-c", |
| 1347 |
- 'import sys; sys.stdout.write("orange")'], |
| 1348 |
- stdout=subprocess.PIPE) |
| 1349 |
- self.addCleanup(p.stdout.close) |
| 1350 |
- self.assertEqual(p.stdout.read(), "orange") |
| 1351 |
- |
| 1352 |
- def test_stdout_filedes(self): |
| 1353 |
- # stdout is set to open file descriptor |
| 1354 |
- tf = tempfile.TemporaryFile() |
| 1355 |
- d = tf.fileno() |
| 1356 |
- p = subprocess.Popen([sys.executable, "-c", |
| 1357 |
- 'import sys; sys.stdout.write("orange")'], |
| 1358 |
- stdout=d) |
| 1359 |
- p.wait() |
| 1360 |
- os.lseek(d, 0, 0) |
| 1361 |
- self.assertEqual(os.read(d, 1024), "orange") |
| 1362 |
- |
| 1363 |
- def test_stdout_fileobj(self): |
| 1364 |
- # stdout is set to open file object |
| 1365 |
- tf = tempfile.TemporaryFile() |
| 1366 |
- p = subprocess.Popen([sys.executable, "-c", |
| 1367 |
- 'import sys; sys.stdout.write("orange")'], |
| 1368 |
- stdout=tf) |
| 1369 |
- p.wait() |
| 1370 |
- tf.seek(0) |
| 1371 |
- self.assertEqual(tf.read(), "orange") |
| 1372 |
- |
| 1373 |
- def test_stderr_pipe(self): |
| 1374 |
- # stderr redirection |
| 1375 |
- p = subprocess.Popen([sys.executable, "-c", |
| 1376 |
- 'import sys; sys.stderr.write("strawberry")'], |
| 1377 |
- stderr=subprocess.PIPE) |
| 1378 |
- self.addCleanup(p.stderr.close) |
| 1379 |
- #self.assertStderrEqual(p.stderr.read(), "strawberry") |
| 1380 |
- self.assertEqual(remove_stderr_debug_decorations(p.stderr.read()), |
| 1381 |
- "strawberry") |
| 1382 |
- |
| 1383 |
- def test_stderr_filedes(self): |
| 1384 |
- # stderr is set to open file descriptor |
| 1385 |
- tf = tempfile.TemporaryFile() |
| 1386 |
- d = tf.fileno() |
| 1387 |
- p = subprocess.Popen([sys.executable, "-c", |
| 1388 |
- 'import sys; sys.stderr.write("strawberry")'], |
| 1389 |
- stderr=d) |
| 1390 |
- p.wait() |
| 1391 |
- os.lseek(d, 0, 0) |
| 1392 |
- #self.assertStderrEqual(os.read(d, 1024), "strawberry") |
| 1393 |
- self.assertEqual(remove_stderr_debug_decorations(os.read(d, 1024)), |
| 1394 |
- "strawberry") |
| 1395 |
- |
| 1396 |
- def test_stderr_fileobj(self): |
| 1397 |
- # stderr is set to open file object |
| 1398 |
- tf = tempfile.TemporaryFile() |
| 1399 |
- p = subprocess.Popen([sys.executable, "-c", |
| 1400 |
- 'import sys; sys.stderr.write("strawberry")'], |
| 1401 |
- stderr=tf) |
| 1402 |
- p.wait() |
| 1403 |
- tf.seek(0) |
| 1404 |
- #self.assertStderrEqual(tf.read(), "strawberry") |
| 1405 |
- self.assertEqual(remove_stderr_debug_decorations(tf.read()), |
| 1406 |
- "strawberry") |
| 1407 |
- |
| 1408 |
- def test_stdout_stderr_pipe(self): |
| 1409 |
- # capture stdout and stderr to the same pipe |
| 1410 |
- p = subprocess.Popen([sys.executable, "-c", |
| 1411 |
- 'import sys;' |
| 1412 |
- 'sys.stdout.write("apple");' |
| 1413 |
- 'sys.stdout.flush();' |
| 1414 |
- 'sys.stderr.write("orange")'], |
| 1415 |
- stdout=subprocess.PIPE, |
| 1416 |
- stderr=subprocess.STDOUT) |
| 1417 |
- self.addCleanup(p.stdout.close) |
| 1418 |
- #self.assertStderrEqual(p.stdout.read(), "appleorange") |
| 1419 |
- output = p.stdout.read() |
| 1420 |
- stripped = remove_stderr_debug_decorations(output) |
| 1421 |
- self.assertEqual(stripped, "appleorange") |
| 1422 |
- |
| 1423 |
- def test_stdout_stderr_file(self): |
| 1424 |
- # capture stdout and stderr to the same open file |
| 1425 |
- tf = tempfile.TemporaryFile() |
| 1426 |
- p = subprocess.Popen([sys.executable, "-c", |
| 1427 |
- 'import sys;' |
| 1428 |
- 'sys.stdout.write("apple");' |
| 1429 |
- 'sys.stdout.flush();' |
| 1430 |
- 'sys.stderr.write("orange")'], |
| 1431 |
- stdout=tf, |
| 1432 |
- stderr=tf) |
| 1433 |
- p.wait() |
| 1434 |
- tf.seek(0) |
| 1435 |
- #self.assertStderrEqual(tf.read(), "appleorange") |
| 1436 |
- output = tf.read() |
| 1437 |
- stripped = remove_stderr_debug_decorations(output) |
| 1438 |
- self.assertEqual(stripped, "appleorange") |
| 1439 |
- |
| 1440 |
- def test_stdout_filedes_of_stdout(self): |
| 1441 |
- # stdout is set to 1 (#1531862). |
| 1442 |
- cmd = r"import sys, os; sys.exit(os.write(sys.stdout.fileno(), '.\n'))" |
| 1443 |
- rc = subprocess.call([sys.executable, "-c", cmd], stdout=1) |
| 1444 |
- self.assertEqual(rc, 2) |
| 1445 |
- |
| 1446 |
- def test_cwd(self): |
| 1447 |
- tmpdir = tempfile.gettempdir() |
| 1448 |
- # We cannot use os.path.realpath to canonicalize the path, |
| 1449 |
- # since it doesn't expand Tru64 {memb} strings. See bug 1063571. |
| 1450 |
- cwd = os.getcwd() |
| 1451 |
- os.chdir(tmpdir) |
| 1452 |
- tmpdir = os.getcwd() |
| 1453 |
- os.chdir(cwd) |
| 1454 |
- p = subprocess.Popen([sys.executable, "-c", |
| 1455 |
- 'import sys,os;' |
| 1456 |
- 'sys.stdout.write(os.getcwd())'], |
| 1457 |
- stdout=subprocess.PIPE, |
| 1458 |
- cwd=tmpdir) |
| 1459 |
- self.addCleanup(p.stdout.close) |
| 1460 |
- normcase = os.path.normcase |
| 1461 |
- self.assertEqual(normcase(p.stdout.read()), normcase(tmpdir)) |
| 1462 |
- |
| 1463 |
- def test_env(self): |
| 1464 |
- newenv = os.environ.copy() |
| 1465 |
- newenv["FRUIT"] = "orange" |
| 1466 |
- p = subprocess.Popen([sys.executable, "-c", |
| 1467 |
- 'import sys,os;' |
| 1468 |
- 'sys.stdout.write(os.getenv("FRUIT"))'], |
| 1469 |
- stdout=subprocess.PIPE, |
| 1470 |
- env=newenv) |
| 1471 |
- self.assertEqual(p.stdout.read(), "orange") |
| 1472 |
- |
| 1473 |
- def test_communicate_stdin(self): |
| 1474 |
- p = subprocess.Popen([sys.executable, "-c", |
| 1475 |
- 'import sys;' |
| 1476 |
- 'sys.exit(sys.stdin.read() == "pear")'], |
| 1477 |
- stdin=subprocess.PIPE) |
| 1478 |
- p.communicate("pear") |
| 1479 |
- self.assertEqual(p.returncode, 1) |
| 1480 |
- |
| 1481 |
- def test_communicate_stdout(self): |
| 1482 |
- p = subprocess.Popen([sys.executable, "-c", |
| 1483 |
- 'import sys; sys.stdout.write("pineapple")'], |
| 1484 |
- stdout=subprocess.PIPE) |
| 1485 |
- (stdout, stderr) = p.communicate() |
| 1486 |
- self.assertEqual(stdout, "pineapple") |
| 1487 |
- self.assertEqual(stderr, None) |
| 1488 |
- |
| 1489 |
- def test_communicate_stderr(self): |
| 1490 |
- p = subprocess.Popen([sys.executable, "-c", |
| 1491 |
- 'import sys; sys.stderr.write("pineapple")'], |
| 1492 |
- stderr=subprocess.PIPE) |
| 1493 |
- (stdout, stderr) = p.communicate() |
| 1494 |
- self.assertEqual(stdout, None) |
| 1495 |
- #self.assertStderrEqual(stderr, "pineapple") |
| 1496 |
- self.assertEqual(remove_stderr_debug_decorations(stderr), "pineapple") |
| 1497 |
- |
| 1498 |
- def test_communicate(self): |
| 1499 |
- p = subprocess.Popen([sys.executable, "-c", |
| 1500 |
- 'import sys,os;' |
| 1501 |
- 'sys.stderr.write("pineapple");' |
| 1502 |
- 'sys.stdout.write(sys.stdin.read())'], |
| 1503 |
- stdin=subprocess.PIPE, |
| 1504 |
- stdout=subprocess.PIPE, |
| 1505 |
- stderr=subprocess.PIPE) |
| 1506 |
- self.addCleanup(p.stdout.close) |
| 1507 |
- self.addCleanup(p.stderr.close) |
| 1508 |
- self.addCleanup(p.stdin.close) |
| 1509 |
- (stdout, stderr) = p.communicate("banana") |
| 1510 |
- self.assertEqual(stdout, "banana") |
| 1511 |
- #self.assertStderrEqual(stderr, "pineapple") |
| 1512 |
- self.assertEqual(remove_stderr_debug_decorations(stderr), |
| 1513 |
- "pineapple") |
| 1514 |
- |
| 1515 |
- # Not available with python-2.6's unittest: Reimplement by |
| 1516 |
- # raising SkipTest from nose |
| 1517 |
- # This test is Linux specific for simplicity to at least have |
| 1518 |
- # some coverage. It is not a platform specific bug. |
| 1519 |
- #@unittest.skipUnless(os.path.isdir('/proc/%d/fd' % os.getpid()), |
| 1520 |
- # "Linux specific") |
| 1521 |
- # Test for the fd leak reported in http://bugs.python.org/issue2791. |
| 1522 |
- def test_communicate_pipe_fd_leak(self): |
| 1523 |
- if not os.path.isdir('/proc/%d/fd' % os.getpid()): |
| 1524 |
- raise SkipTest('Linux specific') |
| 1525 |
- fd_directory = '/proc/%d/fd' % os.getpid() |
| 1526 |
- num_fds_before_popen = len(os.listdir(fd_directory)) |
| 1527 |
- p = subprocess.Popen([sys.executable, "-c", "print()"], |
| 1528 |
- stdout=subprocess.PIPE) |
| 1529 |
- p.communicate() |
| 1530 |
- num_fds_after_communicate = len(os.listdir(fd_directory)) |
| 1531 |
- del p |
| 1532 |
- num_fds_after_destruction = len(os.listdir(fd_directory)) |
| 1533 |
- self.assertEqual(num_fds_before_popen, num_fds_after_destruction) |
| 1534 |
- self.assertEqual(num_fds_before_popen, num_fds_after_communicate) |
| 1535 |
- |
| 1536 |
- def test_communicate_returns(self): |
| 1537 |
- # communicate() should return None if no redirection is active |
| 1538 |
- p = subprocess.Popen([sys.executable, "-c", |
| 1539 |
- "import sys; sys.exit(47)"]) |
| 1540 |
- (stdout, stderr) = p.communicate() |
| 1541 |
- self.assertEqual(stdout, None) |
| 1542 |
- self.assertEqual(stderr, None) |
| 1543 |
- |
| 1544 |
- def test_communicate_pipe_buf(self): |
| 1545 |
- # communicate() with writes larger than pipe_buf |
| 1546 |
- # This test will probably deadlock rather than fail, if |
| 1547 |
- # communicate() does not work properly. |
| 1548 |
- x, y = os.pipe() |
| 1549 |
- if mswindows: |
| 1550 |
- pipe_buf = 512 |
| 1551 |
- else: |
| 1552 |
- pipe_buf = os.fpathconf(x, "PC_PIPE_BUF") |
| 1553 |
- os.close(x) |
| 1554 |
- os.close(y) |
| 1555 |
- p = subprocess.Popen([sys.executable, "-c", |
| 1556 |
- 'import sys,os;' |
| 1557 |
- 'sys.stdout.write(sys.stdin.read(47));' |
| 1558 |
- 'sys.stderr.write("xyz"*%d);' |
| 1559 |
- 'sys.stdout.write(sys.stdin.read())' % pipe_buf], |
| 1560 |
- stdin=subprocess.PIPE, |
| 1561 |
- stdout=subprocess.PIPE, |
| 1562 |
- stderr=subprocess.PIPE) |
| 1563 |
- self.addCleanup(p.stdout.close) |
| 1564 |
- self.addCleanup(p.stderr.close) |
| 1565 |
- self.addCleanup(p.stdin.close) |
| 1566 |
- string_to_write = "abc"*pipe_buf |
| 1567 |
- (stdout, stderr) = p.communicate(string_to_write) |
| 1568 |
- self.assertEqual(stdout, string_to_write) |
| 1569 |
- |
| 1570 |
- def test_writes_before_communicate(self): |
| 1571 |
- # stdin.write before communicate() |
| 1572 |
- p = subprocess.Popen([sys.executable, "-c", |
| 1573 |
- 'import sys,os;' |
| 1574 |
- 'sys.stdout.write(sys.stdin.read())'], |
| 1575 |
- stdin=subprocess.PIPE, |
| 1576 |
- stdout=subprocess.PIPE, |
| 1577 |
- stderr=subprocess.PIPE) |
| 1578 |
- self.addCleanup(p.stdout.close) |
| 1579 |
- self.addCleanup(p.stderr.close) |
| 1580 |
- self.addCleanup(p.stdin.close) |
| 1581 |
- p.stdin.write("banana") |
| 1582 |
- (stdout, stderr) = p.communicate("split") |
| 1583 |
- self.assertEqual(stdout, "bananasplit") |
| 1584 |
- #self.assertStderrEqual(stderr, "") |
| 1585 |
- self.assertEqual(remove_stderr_debug_decorations(stderr), "") |
| 1586 |
- |
| 1587 |
- def test_universal_newlines(self): |
| 1588 |
- p = subprocess.Popen([sys.executable, "-c", |
| 1589 |
- 'import sys,os;' + SETBINARY + |
| 1590 |
- 'sys.stdout.write("line1\\n");' |
| 1591 |
- 'sys.stdout.flush();' |
| 1592 |
- 'sys.stdout.write("line2\\r");' |
| 1593 |
- 'sys.stdout.flush();' |
| 1594 |
- 'sys.stdout.write("line3\\r\\n");' |
| 1595 |
- 'sys.stdout.flush();' |
| 1596 |
- 'sys.stdout.write("line4\\r");' |
| 1597 |
- 'sys.stdout.flush();' |
| 1598 |
- 'sys.stdout.write("\\nline5");' |
| 1599 |
- 'sys.stdout.flush();' |
| 1600 |
- 'sys.stdout.write("\\nline6");'], |
| 1601 |
- stdout=subprocess.PIPE, |
| 1602 |
- universal_newlines=1) |
| 1603 |
- self.addCleanup(p.stdout.close) |
| 1604 |
- stdout = p.stdout.read() |
| 1605 |
- if hasattr(file, 'newlines'): |
| 1606 |
- # Interpreter with universal newline support |
| 1607 |
- self.assertEqual(stdout, |
| 1608 |
- "line1\nline2\nline3\nline4\nline5\nline6") |
| 1609 |
- else: |
| 1610 |
- # Interpreter without universal newline support |
| 1611 |
- self.assertEqual(stdout, |
| 1612 |
- "line1\nline2\rline3\r\nline4\r\nline5\nline6") |
| 1613 |
- |
| 1614 |
- def test_universal_newlines_communicate(self): |
| 1615 |
- # universal newlines through communicate() |
| 1616 |
- p = subprocess.Popen([sys.executable, "-c", |
| 1617 |
- 'import sys,os;' + SETBINARY + |
| 1618 |
- 'sys.stdout.write("line1\\n");' |
| 1619 |
- 'sys.stdout.flush();' |
| 1620 |
- 'sys.stdout.write("line2\\r");' |
| 1621 |
- 'sys.stdout.flush();' |
| 1622 |
- 'sys.stdout.write("line3\\r\\n");' |
| 1623 |
- 'sys.stdout.flush();' |
| 1624 |
- 'sys.stdout.write("line4\\r");' |
| 1625 |
- 'sys.stdout.flush();' |
| 1626 |
- 'sys.stdout.write("\\nline5");' |
| 1627 |
- 'sys.stdout.flush();' |
| 1628 |
- 'sys.stdout.write("\\nline6");'], |
| 1629 |
- stdout=subprocess.PIPE, stderr=subprocess.PIPE, |
| 1630 |
- universal_newlines=1) |
| 1631 |
- self.addCleanup(p.stdout.close) |
| 1632 |
- self.addCleanup(p.stderr.close) |
| 1633 |
- (stdout, stderr) = p.communicate() |
| 1634 |
- if hasattr(file, 'newlines'): |
| 1635 |
- # Interpreter with universal newline support |
| 1636 |
- self.assertEqual(stdout, |
| 1637 |
- "line1\nline2\nline3\nline4\nline5\nline6") |
| 1638 |
- else: |
| 1639 |
- # Interpreter without universal newline support |
| 1640 |
- self.assertEqual(stdout, |
| 1641 |
- "line1\nline2\rline3\r\nline4\r\nline5\nline6") |
| 1642 |
- |
| 1643 |
- def test_no_leaking(self): |
| 1644 |
- if not test_support: |
| 1645 |
- raise SkipTest("No test_support module available.") |
| 1646 |
- |
| 1647 |
- # Make sure we leak no resources |
| 1648 |
- if not mswindows: |
| 1649 |
- max_handles = 1026 # too much for most UNIX systems |
| 1650 |
- else: |
| 1651 |
- max_handles = 2050 # too much for (at least some) Windows setups |
| 1652 |
- handles = [] |
| 1653 |
- try: |
| 1654 |
- for i in range(max_handles): |
| 1655 |
- try: |
| 1656 |
- handles.append(os.open(test_support.TESTFN, |
| 1657 |
- os.O_WRONLY | os.O_CREAT)) |
| 1658 |
- except OSError, e: |
| 1659 |
- if e.errno != errno.EMFILE: |
| 1660 |
- raise |
| 1661 |
- break |
| 1662 |
- else: |
| 1663 |
- # python-2.3 unittest doesn't have skipTest. Reimplement with nose |
| 1664 |
- #self.skipTest("failed to reach the file descriptor limit " |
| 1665 |
- # "(tried %d)" % max_handles) |
| 1666 |
- raise SkipTest("failed to reach the file descriptor limit " |
| 1667 |
- "(tried %d)" % max_handles) |
| 1668 |
- |
| 1669 |
- # Close a couple of them (should be enough for a subprocess) |
| 1670 |
- for i in range(10): |
| 1671 |
- os.close(handles.pop()) |
| 1672 |
- # Loop creating some subprocesses. If one of them leaks some fds, |
| 1673 |
- # the next loop iteration will fail by reaching the max fd limit. |
| 1674 |
- for i in range(15): |
| 1675 |
- p = subprocess.Popen([sys.executable, "-c", |
| 1676 |
- "import sys;" |
| 1677 |
- "sys.stdout.write(sys.stdin.read())"], |
| 1678 |
- stdin=subprocess.PIPE, |
| 1679 |
- stdout=subprocess.PIPE, |
| 1680 |
- stderr=subprocess.PIPE) |
| 1681 |
- data = p.communicate("lime")[0] |
| 1682 |
- self.assertEqual(data, "lime") |
| 1683 |
- finally: |
| 1684 |
- for h in handles: |
| 1685 |
- os.close(h) |
| 1686 |
- |
| 1687 |
- def test_list2cmdline(self): |
| 1688 |
- self.assertEqual(subprocess.list2cmdline(['a b c', 'd', 'e']), |
| 1689 |
- '"a b c" d e') |
| 1690 |
- self.assertEqual(subprocess.list2cmdline(['ab"c', '\\', 'd']), |
| 1691 |
- 'ab\\"c \\ d') |
| 1692 |
- self.assertEqual(subprocess.list2cmdline(['ab"c', ' \\', 'd']), |
| 1693 |
- 'ab\\"c " \\\\" d') |
| 1694 |
- self.assertEqual(subprocess.list2cmdline(['a\\\\\\b', 'de fg', 'h']), |
| 1695 |
- 'a\\\\\\b "de fg" h') |
| 1696 |
- self.assertEqual(subprocess.list2cmdline(['a\\"b', 'c', 'd']), |
| 1697 |
- 'a\\\\\\"b c d') |
| 1698 |
- self.assertEqual(subprocess.list2cmdline(['a\\\\b c', 'd', 'e']), |
| 1699 |
- '"a\\\\b c" d e') |
| 1700 |
- self.assertEqual(subprocess.list2cmdline(['a\\\\b\\ c', 'd', 'e']), |
| 1701 |
- '"a\\\\b\\ c" d e') |
| 1702 |
- self.assertEqual(subprocess.list2cmdline(['ab', '']), |
| 1703 |
- 'ab ""') |
| 1704 |
- |
| 1705 |
- |
| 1706 |
- def test_poll(self): |
| 1707 |
- p = subprocess.Popen([sys.executable, |
| 1708 |
- "-c", "import time; time.sleep(1)"]) |
| 1709 |
- count = 0 |
| 1710 |
- while p.poll() is None: |
| 1711 |
- time.sleep(0.1) |
| 1712 |
- count += 1 |
| 1713 |
- # We expect that the poll loop probably went around about 10 times, |
| 1714 |
- # but, based on system scheduling we can't control, it's possible |
| 1715 |
- # poll() never returned None. It "should be" very rare that it |
| 1716 |
- # didn't go around at least twice. |
| 1717 |
- #self.assertGreaterEqual(count, 2) |
| 1718 |
- self.assert_(count >= 2) |
| 1719 |
- # Subsequent invocations should just return the returncode |
| 1720 |
- self.assertEqual(p.poll(), 0) |
| 1721 |
- |
| 1722 |
- |
| 1723 |
- def test_wait(self): |
| 1724 |
- p = subprocess.Popen([sys.executable, |
| 1725 |
- "-c", "import time; time.sleep(2)"]) |
| 1726 |
- self.assertEqual(p.wait(), 0) |
| 1727 |
- # Subsequent invocations should just return the returncode |
| 1728 |
- self.assertEqual(p.wait(), 0) |
| 1729 |
- |
| 1730 |
- |
| 1731 |
- def test_invalid_bufsize(self): |
| 1732 |
- # an invalid type of the bufsize argument should raise |
| 1733 |
- # TypeError. |
| 1734 |
- #with self.assertRaises(TypeError): |
| 1735 |
- try: |
| 1736 |
- subprocess.Popen([sys.executable, "-c", "pass"], "orange") |
| 1737 |
- except TypeError: |
| 1738 |
- pass |
| 1739 |
- else: |
| 1740 |
- self.fail("Expected TypeError") |
| 1741 |
- |
| 1742 |
- def test_leaking_fds_on_error(self): |
| 1743 |
- # see bug #5179: Popen leaks file descriptors to PIPEs if |
| 1744 |
- # the child fails to execute; this will eventually exhaust |
| 1745 |
- # the maximum number of open fds. 1024 seems a very common |
| 1746 |
- # value for that limit, but Windows has 2048, so we loop |
| 1747 |
- # 1024 times (each call leaked two fds). |
| 1748 |
- for i in range(1024): |
| 1749 |
- # Windows raises IOError. Others raise OSError. |
| 1750 |
- #with self.assertRaises(EnvironmentError) as c: |
| 1751 |
- try: |
| 1752 |
- subprocess.Popen(['nonexisting_i_hope'], |
| 1753 |
- stdout=subprocess.PIPE, |
| 1754 |
- stderr=subprocess.PIPE) |
| 1755 |
- #if c.exception.errno != 2: # ignore "no such file" |
| 1756 |
- # raise c.exception |
| 1757 |
- # Windows raises IOError |
| 1758 |
- except EnvironmentError, err: |
| 1759 |
- if err.errno not in (errno.ENOENT, errno.EACCES): # ignore "no such file" |
| 1760 |
- raise err |
| 1761 |
- except: |
| 1762 |
- self.fail("Expected EnvironmentError") |
| 1763 |
- else: |
| 1764 |
- self.fail("Expected EnvironmentError") |
| 1765 |
- |
| 1766 |
- def test_handles_closed_on_exception(self): |
| 1767 |
- # If CreateProcess exits with an error, ensure the |
| 1768 |
- # duplicate output handles are released |
| 1769 |
- ifhandle, ifname = mkstemp() |
| 1770 |
- ofhandle, ofname = mkstemp() |
| 1771 |
- efhandle, efname = mkstemp() |
| 1772 |
- try: |
| 1773 |
- subprocess.Popen(["*"], stdin=ifhandle, stdout=ofhandle, |
| 1774 |
- stderr=efhandle) |
| 1775 |
- except OSError: |
| 1776 |
- os.close(ifhandle) |
| 1777 |
- os.remove(ifname) |
| 1778 |
- os.close(ofhandle) |
| 1779 |
- os.remove(ofname) |
| 1780 |
- os.close(efhandle) |
| 1781 |
- os.remove(efname) |
| 1782 |
- self.assert_(not os.path.exists(ifname)) |
| 1783 |
- self.assert_(not os.path.exists(ofname)) |
| 1784 |
- self.assert_(not os.path.exists(efname)) |
| 1785 |
- |
| 1786 |
- def test_communicate_epipe(self): |
| 1787 |
- # Issue 10963: communicate() should hide EPIPE |
| 1788 |
- p = subprocess.Popen([sys.executable, "-c", 'pass'], |
| 1789 |
- stdin=subprocess.PIPE, |
| 1790 |
- stdout=subprocess.PIPE, |
| 1791 |
- stderr=subprocess.PIPE) |
| 1792 |
- self.addCleanup(p.stdout.close) |
| 1793 |
- self.addCleanup(p.stderr.close) |
| 1794 |
- self.addCleanup(p.stdin.close) |
| 1795 |
- p.communicate("x" * 2**20) |
| 1796 |
- |
| 1797 |
- def test_communicate_epipe_only_stdin(self): |
| 1798 |
- # Issue 10963: communicate() should hide EPIPE |
| 1799 |
- p = subprocess.Popen([sys.executable, "-c", 'pass'], |
| 1800 |
- stdin=subprocess.PIPE) |
| 1801 |
- self.addCleanup(p.stdin.close) |
| 1802 |
- time.sleep(2) |
| 1803 |
- p.communicate("x" * 2**20) |
| 1804 |
- |
| 1805 |
-# context manager |
| 1806 |
-class _SuppressCoreFiles(object): |
| 1807 |
- """Try to prevent core files from being created.""" |
| 1808 |
- old_limit = None |
| 1809 |
- |
| 1810 |
- def __enter__(self): |
| 1811 |
- """Try to save previous ulimit, then set it to (0, 0).""" |
| 1812 |
- try: |
| 1813 |
- import resource |
| 1814 |
- self.old_limit = resource.getrlimit(resource.RLIMIT_CORE) |
| 1815 |
- resource.setrlimit(resource.RLIMIT_CORE, (0, 0)) |
| 1816 |
- except (ImportError, ValueError, resource.error): |
| 1817 |
- pass |
| 1818 |
- |
| 1819 |
- if sys.platform == 'darwin': |
| 1820 |
- # Check if the 'Crash Reporter' on OSX was configured |
| 1821 |
- # in 'Developer' mode and warn that it will get triggered |
| 1822 |
- # when it is. |
| 1823 |
- # |
| 1824 |
- # This assumes that this context manager is used in tests |
| 1825 |
- # that might trigger the next manager. |
| 1826 |
- value = subprocess.Popen(['/usr/bin/defaults', 'read', |
| 1827 |
- 'com.apple.CrashReporter', 'DialogType'], |
| 1828 |
- stdout=subprocess.PIPE).communicate()[0] |
| 1829 |
- if value.strip() == 'developer': |
| 1830 |
- print "this tests triggers the Crash Reporter, that is intentional" |
| 1831 |
- sys.stdout.flush() |
| 1832 |
- |
| 1833 |
- def __exit__(self, *args): |
| 1834 |
- """Return core file behavior to default.""" |
| 1835 |
- if self.old_limit is None: |
| 1836 |
- return |
| 1837 |
- try: |
| 1838 |
- import resource |
| 1839 |
- resource.setrlimit(resource.RLIMIT_CORE, self.old_limit) |
| 1840 |
- except (ImportError, ValueError, resource.error): |
| 1841 |
- pass |
| 1842 |
- |
| 1843 |
- # python-2.3 unittest doesn't have skipUnless. Reimplement as SkipTest from nose |
| 1844 |
- #@unittest.skipUnless(hasattr(signal, 'SIGALRM'), |
| 1845 |
- # "Requires signal.SIGALRM") |
| 1846 |
- def test_communicate_eintr(self): |
| 1847 |
- if not hasattr(signal, 'SIGALRM'): |
| 1848 |
- raise SkipTest('Requires signal.SIGALRM') |
| 1849 |
- # Issue #12493: communicate() should handle EINTR |
| 1850 |
- def handler(signum, frame): |
| 1851 |
- pass |
| 1852 |
- old_handler = signal.signal(signal.SIGALRM, handler) |
| 1853 |
- self.addCleanup(signal.signal, signal.SIGALRM, old_handler) |
| 1854 |
- |
| 1855 |
- # the process is running for 2 seconds |
| 1856 |
- args = [sys.executable, "-c", 'import time; time.sleep(2)'] |
| 1857 |
- for stream in ('stdout', 'stderr'): |
| 1858 |
- kw = {stream: subprocess.PIPE} |
| 1859 |
- #with subprocess.Popen(args, **kw) as process: |
| 1860 |
- try: |
| 1861 |
- process = subprocess.Popen(args, **kw) |
| 1862 |
- signal.alarm(1) |
| 1863 |
- # communicate() will be interrupted by SIGALRM |
| 1864 |
- process.communicate() |
| 1865 |
- finally: |
| 1866 |
- process.close() |
| 1867 |
- |
| 1868 |
- |
| 1869 |
-# Not available with python-2.3's unittest. Reimplement with SkipTest from |
| 1870 |
-# nose |
| 1871 |
-#@unittest.skipIf(mswindows, "POSIX specific tests") |
| 1872 |
-class POSIXProcessTestCase(BaseTestCase): |
| 1873 |
- def setUp(self): |
| 1874 |
- if mswindows: |
| 1875 |
- raise SkipTest('POSIX specific tests') |
| 1876 |
- |
| 1877 |
- def test_exceptions(self): |
| 1878 |
- # caught & re-raised exceptions |
| 1879 |
- #with self.assertRaises(OSError) as c: |
| 1880 |
- try: |
| 1881 |
- p = subprocess.Popen([sys.executable, "-c", ""], |
| 1882 |
- cwd="/this/path/does/not/exist") |
| 1883 |
- # The attribute child_traceback should contain "os.chdir" somewhere. |
| 1884 |
- #self.assertIn("os.chdir", c.exception.child_traceback) |
| 1885 |
- except OSError, e: |
| 1886 |
- self.assertNotEqual(e.child_traceback.find("os.chdir"), -1) |
| 1887 |
- except: |
| 1888 |
- self.fail("Expected OSError") |
| 1889 |
- else: |
| 1890 |
- self.fail("Expected OSError") |
| 1891 |
- |
| 1892 |
- def _suppress_core_files(self): |
| 1893 |
- """Try to prevent core files from being created. |
| 1894 |
- Returns previous ulimit if successful, else None. |
| 1895 |
- """ |
| 1896 |
- try: |
| 1897 |
- import resource |
| 1898 |
- old_limit = resource.getrlimit(resource.RLIMIT_CORE) |
| 1899 |
- resource.setrlimit(resource.RLIMIT_CORE, (0, 0)) |
| 1900 |
- return old_limit |
| 1901 |
- except (ImportError, ValueError, resource.error): |
| 1902 |
- return None |
| 1903 |
- |
| 1904 |
- def _unsuppress_core_files(self, old_limit): |
| 1905 |
- """Return core file behavior to default.""" |
| 1906 |
- if old_limit is None: |
| 1907 |
- return |
| 1908 |
- try: |
| 1909 |
- import resource |
| 1910 |
- resource.setrlimit(resource.RLIMIT_CORE, old_limit) |
| 1911 |
- except (ImportError, ValueError, resource.error): |
| 1912 |
- return |
| 1913 |
- |
| 1914 |
- def test_run_abort(self): |
| 1915 |
- # returncode handles signal termination |
| 1916 |
- #with _SuppressCoreFiles(): |
| 1917 |
- old_limit = self._suppress_core_files() |
| 1918 |
- try: |
| 1919 |
- p = subprocess.Popen([sys.executable, "-c", |
| 1920 |
- "import os; os.abort()"]) |
| 1921 |
- finally: |
| 1922 |
- self._unsuppress_core_files(old_limit) |
| 1923 |
- |
| 1924 |
- #p.wait() |
| 1925 |
- p.wait() |
| 1926 |
- self.assertEqual(-p.returncode, signal.SIGABRT) |
| 1927 |
- |
| 1928 |
- def test_preexec(self): |
| 1929 |
- # preexec function |
| 1930 |
- p = subprocess.Popen([sys.executable, "-c", |
| 1931 |
- "import sys, os;" |
| 1932 |
- "sys.stdout.write(os.getenv('FRUIT'))"], |
| 1933 |
- stdout=subprocess.PIPE, |
| 1934 |
- preexec_fn=lambda: os.putenv("FRUIT", "apple")) |
| 1935 |
- self.addCleanup(p.stdout.close) |
| 1936 |
- self.assertEqual(p.stdout.read(), "apple") |
| 1937 |
- |
| 1938 |
- def test_args_string(self): |
| 1939 |
- # args is a string |
| 1940 |
- f, fname = mkstemp() |
| 1941 |
- os.write(f, "#!/bin/sh\n") |
| 1942 |
- os.write(f, "exec '%s' -c 'import sys; sys.exit(47)'\n" % |
| 1943 |
- sys.executable) |
| 1944 |
- os.close(f) |
| 1945 |
- # 0o is not available in python2.5 |
| 1946 |
- #os.chmod(fname, 0o700) |
| 1947 |
- os.chmod(fname, 0700) |
| 1948 |
- p = subprocess.Popen(fname) |
| 1949 |
- p.wait() |
| 1950 |
- os.remove(fname) |
| 1951 |
- self.assertEqual(p.returncode, 47) |
| 1952 |
- |
| 1953 |
- def test_invalid_args(self): |
| 1954 |
- # invalid arguments should raise ValueError |
| 1955 |
- self.assertRaises(ValueError, subprocess.call, |
| 1956 |
- [sys.executable, "-c", |
| 1957 |
- "import sys; sys.exit(47)"], |
| 1958 |
- startupinfo=47) |
| 1959 |
- self.assertRaises(ValueError, subprocess.call, |
| 1960 |
- [sys.executable, "-c", |
| 1961 |
- "import sys; sys.exit(47)"], |
| 1962 |
- creationflags=47) |
| 1963 |
- |
| 1964 |
- def test_shell_sequence(self): |
| 1965 |
- # Run command through the shell (sequence) |
| 1966 |
- newenv = os.environ.copy() |
| 1967 |
- newenv["FRUIT"] = "apple" |
| 1968 |
- p = subprocess.Popen(["echo $FRUIT"], shell=1, |
| 1969 |
- stdout=subprocess.PIPE, |
| 1970 |
- env=newenv) |
| 1971 |
- self.addCleanup(p.stdout.close) |
| 1972 |
- self.assertEqual(p.stdout.read().strip(), "apple") |
| 1973 |
- |
| 1974 |
- def test_shell_string(self): |
| 1975 |
- # Run command through the shell (string) |
| 1976 |
- newenv = os.environ.copy() |
| 1977 |
- newenv["FRUIT"] = "apple" |
| 1978 |
- p = subprocess.Popen("echo $FRUIT", shell=1, |
| 1979 |
- stdout=subprocess.PIPE, |
| 1980 |
- env=newenv) |
| 1981 |
- self.addCleanup(p.stdout.close) |
| 1982 |
- self.assertEqual(p.stdout.read().strip(), "apple") |
| 1983 |
- |
| 1984 |
- def test_call_string(self): |
| 1985 |
- # call() function with string argument on UNIX |
| 1986 |
- f, fname = mkstemp() |
| 1987 |
- os.write(f, "#!/bin/sh\n") |
| 1988 |
- os.write(f, "exec '%s' -c 'import sys; sys.exit(47)'\n" % |
| 1989 |
- sys.executable) |
| 1990 |
- os.close(f) |
| 1991 |
- os.chmod(fname, 0700) |
| 1992 |
- rc = subprocess.call(fname) |
| 1993 |
- os.remove(fname) |
| 1994 |
- self.assertEqual(rc, 47) |
| 1995 |
- |
| 1996 |
- def test_specific_shell(self): |
| 1997 |
- # Issue #9265: Incorrect name passed as arg[0]. |
| 1998 |
- shells = [] |
| 1999 |
- for prefix in ['/bin', '/usr/bin/', '/usr/local/bin']: |
| 2000 |
- for name in ['bash', 'ksh']: |
| 2001 |
- sh = os.path.join(prefix, name) |
| 2002 |
- if os.path.isfile(sh): |
| 2003 |
- shells.append(sh) |
| 2004 |
- if not shells: # Will probably work for any shell but csh. |
| 2005 |
- |
| 2006 |
- # skipTest unavailable on python<2.7 reimplement with nose |
| 2007 |
- #self.skipTest("bash or ksh required for this test") |
| 2008 |
- raise SkipTest("bash or ksh required for this test") |
| 2009 |
- sh = '/bin/sh' |
| 2010 |
- if os.path.isfile(sh) and not os.path.islink(sh): |
| 2011 |
- # Test will fail if /bin/sh is a symlink to csh. |
| 2012 |
- shells.append(sh) |
| 2013 |
- for sh in shells: |
| 2014 |
- p = subprocess.Popen("echo $0", executable=sh, shell=True, |
| 2015 |
- stdout=subprocess.PIPE) |
| 2016 |
- self.addCleanup(p.stdout.close) |
| 2017 |
- self.assertEqual(p.stdout.read().strip(), sh) |
| 2018 |
- |
| 2019 |
- def _kill_process(self, method, *args): |
| 2020 |
- # Do not inherit file handles from the parent. |
| 2021 |
- # It should fix failures on some platforms. |
| 2022 |
- p = subprocess.Popen([sys.executable, "-c", """if 1: |
| 2023 |
- import sys, time |
| 2024 |
- sys.stdout.write('x\\n') |
| 2025 |
- sys.stdout.flush() |
| 2026 |
- time.sleep(30) |
| 2027 |
- """], |
| 2028 |
- close_fds=True, |
| 2029 |
- stdin=subprocess.PIPE, |
| 2030 |
- stdout=subprocess.PIPE, |
| 2031 |
- stderr=subprocess.PIPE) |
| 2032 |
- # Wait for the interpreter to be completely initialized before |
| 2033 |
- # sending any signal. |
| 2034 |
- p.stdout.read(1) |
| 2035 |
- getattr(p, method)(*args) |
| 2036 |
- return p |
| 2037 |
- |
| 2038 |
- # These are still hanging with x86_64 Fedora 12 (python-2.6) subprocess |
| 2039 |
- # backport from current trunk run under nosetests |
| 2040 |
- |
| 2041 |
- def test_send_signal(self): |
| 2042 |
- #if hang DISABLED #2777 |
| 2043 |
- p = self._kill_process('send_signal', signal.SIGINT) |
| 2044 |
- _, stderr = p.communicate() |
| 2045 |
- self.assert_('KeyboardInterrupt' in stderr) |
| 2046 |
- self.assertNotEqual(p.wait(), 0) |
| 2047 |
- |
| 2048 |
- def test_kill(self): |
| 2049 |
- #if hang DISABLED #2777 |
| 2050 |
- p = self._kill_process('kill') |
| 2051 |
- _, stderr = p.communicate() |
| 2052 |
- self.assertStderrEqual(stderr, '') |
| 2053 |
- self.assertEqual(p.wait(), -signal.SIGKILL) |
| 2054 |
- |
| 2055 |
- def test_terminate(self): |
| 2056 |
- #if hang DISABLED #2777 |
| 2057 |
- p = self._kill_process('terminate') |
| 2058 |
- _, stderr = p.communicate() |
| 2059 |
- self.assertStderrEqual(stderr, '') |
| 2060 |
- self.assertEqual(p.wait(), -signal.SIGTERM) |
| 2061 |
- |
| 2062 |
- def check_close_std_fds(self, fds): |
| 2063 |
- # Issue #9905: test that subprocess pipes still work properly with |
| 2064 |
- # some standard fds closed |
| 2065 |
- stdin = 0 |
| 2066 |
- newfds = [] |
| 2067 |
- for a in fds: |
| 2068 |
- b = os.dup(a) |
| 2069 |
- newfds.append(b) |
| 2070 |
- if a == 0: |
| 2071 |
- stdin = b |
| 2072 |
- try: |
| 2073 |
- for fd in fds: |
| 2074 |
- os.close(fd) |
| 2075 |
- out, err = subprocess.Popen([sys.executable, "-c", |
| 2076 |
- 'import sys;' |
| 2077 |
- 'sys.stdout.write("apple");' |
| 2078 |
- 'sys.stdout.flush();' |
| 2079 |
- 'sys.stderr.write("orange")'], |
| 2080 |
- stdin=stdin, |
| 2081 |
- stdout=subprocess.PIPE, |
| 2082 |
- stderr=subprocess.PIPE).communicate() |
| 2083 |
- err = re.sub(r"\[\d+ refs\]\r?\n?$", "", err).strip() |
| 2084 |
- self.assertEqual((out, err), ('apple', 'orange')) |
| 2085 |
- finally: |
| 2086 |
- for b, a in zip(newfds, fds): |
| 2087 |
- os.dup2(b, a) |
| 2088 |
- for b in newfds: |
| 2089 |
- os.close(b) |
| 2090 |
- |
| 2091 |
- def test_close_fd_0(self): |
| 2092 |
- self.check_close_std_fds([0]) |
| 2093 |
- |
| 2094 |
- def test_close_fd_1(self): |
| 2095 |
- self.check_close_std_fds([1]) |
| 2096 |
- |
| 2097 |
- def test_close_fd_2(self): |
| 2098 |
- self.check_close_std_fds([2]) |
| 2099 |
- |
| 2100 |
- def test_close_fds_0_1(self): |
| 2101 |
- self.check_close_std_fds([0, 1]) |
| 2102 |
- |
| 2103 |
- def test_close_fds_0_2(self): |
| 2104 |
- self.check_close_std_fds([0, 2]) |
| 2105 |
- |
| 2106 |
- def test_close_fds_1_2(self): |
| 2107 |
- self.check_close_std_fds([1, 2]) |
| 2108 |
- |
| 2109 |
- def test_close_fds_0_1_2(self): |
| 2110 |
- # Issue #10806: test that subprocess pipes still work properly with |
| 2111 |
- # all standard fds closed. |
| 2112 |
- self.check_close_std_fds([0, 1, 2]) |
| 2113 |
- |
| 2114 |
- def check_swap_fds(self, stdin_no, stdout_no, stderr_no): |
| 2115 |
- # open up some temporary files |
| 2116 |
- temps = [mkstemp() for i in range(3)] |
| 2117 |
- temp_fds = [fd for fd, fname in temps] |
| 2118 |
- try: |
| 2119 |
- # unlink the files -- we won't need to reopen them |
| 2120 |
- for fd, fname in temps: |
| 2121 |
- os.unlink(fname) |
| 2122 |
- |
| 2123 |
- # save a copy of the standard file descriptors |
| 2124 |
- saved_fds = [os.dup(fd) for fd in range(3)] |
| 2125 |
- try: |
| 2126 |
- # duplicate the temp files over the standard fd's 0, 1, 2 |
| 2127 |
- for fd, temp_fd in enumerate(temp_fds): |
| 2128 |
- os.dup2(temp_fd, fd) |
| 2129 |
- |
| 2130 |
- # write some data to what will become stdin, and rewind |
| 2131 |
- os.write(stdin_no, "STDIN") |
| 2132 |
- os.lseek(stdin_no, 0, 0) |
| 2133 |
- |
| 2134 |
- # now use those files in the given order, so that subprocess |
| 2135 |
- # has to rearrange them in the child |
| 2136 |
- p = subprocess.Popen([sys.executable, "-c", |
| 2137 |
- 'import sys; got = sys.stdin.read();' |
| 2138 |
- 'sys.stdout.write("got %s"%got); sys.stderr.write("err")'], |
| 2139 |
- stdin=stdin_no, |
| 2140 |
- stdout=stdout_no, |
| 2141 |
- stderr=stderr_no) |
| 2142 |
- p.wait() |
| 2143 |
- |
| 2144 |
- for fd in temp_fds: |
| 2145 |
- os.lseek(fd, 0, 0) |
| 2146 |
- |
| 2147 |
- out = os.read(stdout_no, 1024) |
| 2148 |
- err = re.sub(r"\[\d+ refs\]\r?\n?$", "", os.read(stderr_no, 1024)).strip() |
| 2149 |
- finally: |
| 2150 |
- for std, saved in enumerate(saved_fds): |
| 2151 |
- os.dup2(saved, std) |
| 2152 |
- os.close(saved) |
| 2153 |
- |
| 2154 |
- self.assertEqual(out, "got STDIN") |
| 2155 |
- self.assertEqual(err, "err") |
| 2156 |
- |
| 2157 |
- finally: |
| 2158 |
- for fd in temp_fds: |
| 2159 |
- os.close(fd) |
| 2160 |
- |
| 2161 |
- # When duping fds, if there arises a situation where one of the fds is |
| 2162 |
- # either 0, 1 or 2, it is possible that it is overwritten (#12607). |
| 2163 |
- # This tests all combinations of this. |
| 2164 |
- def test_swap_fds(self): |
| 2165 |
- self.check_swap_fds(0, 1, 2) |
| 2166 |
- self.check_swap_fds(0, 2, 1) |
| 2167 |
- self.check_swap_fds(1, 0, 2) |
| 2168 |
- self.check_swap_fds(1, 2, 0) |
| 2169 |
- self.check_swap_fds(2, 0, 1) |
| 2170 |
- self.check_swap_fds(2, 1, 0) |
| 2171 |
- |
| 2172 |
- def test_wait_when_sigchild_ignored(self): |
| 2173 |
- # NOTE: sigchild_ignore.py may not be an effective test on all OSes. |
| 2174 |
- if not test_support: |
| 2175 |
- raise SkipTest("No test_support module available.") |
| 2176 |
- sigchild_ignore = test_support.findfile(os.path.join("subprocessdata", |
| 2177 |
- "sigchild_ignore.py")) |
| 2178 |
- p = subprocess.Popen([sys.executable, sigchild_ignore], |
| 2179 |
- stdout=subprocess.PIPE, stderr=subprocess.PIPE) |
| 2180 |
- stdout, stderr = p.communicate() |
| 2181 |
- self.assertEqual(0, p.returncode, "sigchild_ignore.py exited" |
| 2182 |
- " non-zero with this error:\n%s" % stderr) |
| 2183 |
- |
| 2184 |
- |
| 2185 |
- def test_zombie_fast_process_del(self): |
| 2186 |
- # Issue #12650: on Unix, if Popen.__del__() was called before the |
| 2187 |
- # process exited, it wouldn't be added to subprocess._active, and would |
| 2188 |
- # remain a zombie. |
| 2189 |
- # spawn a Popen, and delete its reference before it exits |
| 2190 |
- p = subprocess.Popen([sys.executable, "-c", |
| 2191 |
- 'import sys, time;' |
| 2192 |
- 'time.sleep(0.2)'], |
| 2193 |
- stdout=subprocess.PIPE, |
| 2194 |
- stderr=subprocess.PIPE) |
| 2195 |
- self.addCleanup(p.stdout.close) |
| 2196 |
- self.addCleanup(p.stderr.close) |
| 2197 |
- ident = id(p) |
| 2198 |
- pid = p.pid |
| 2199 |
- del p |
| 2200 |
- # check that p is in the active processes list |
| 2201 |
- # assertIn not in python< 2.7 |
| 2202 |
- #self.assertIn(ident, [id(o) for o in subprocess._active]) |
| 2203 |
- self.assert_(ident in [id(o) for o in subprocess._active]) |
| 2204 |
- |
| 2205 |
- def test_leak_fast_process_del_killed(self): |
| 2206 |
- # Issue #12650: on Unix, if Popen.__del__() was called before the |
| 2207 |
- # process exited, and the process got killed by a signal, it would never |
| 2208 |
- # be removed from subprocess._active, which triggered a FD and memory |
| 2209 |
- # leak. |
| 2210 |
- # spawn a Popen, delete its reference and kill it |
| 2211 |
- p = subprocess.Popen([sys.executable, "-c", |
| 2212 |
- 'import time;' |
| 2213 |
- 'time.sleep(3)'], |
| 2214 |
- stdout=subprocess.PIPE, |
| 2215 |
- stderr=subprocess.PIPE) |
| 2216 |
- self.addCleanup(p.stdout.close) |
| 2217 |
- self.addCleanup(p.stderr.close) |
| 2218 |
- ident = id(p) |
| 2219 |
- pid = p.pid |
| 2220 |
- del p |
| 2221 |
- os.kill(pid, signal.SIGKILL) |
| 2222 |
- # check that p is in the active processes list |
| 2223 |
- # assertIn not in python < 2.7 |
| 2224 |
- self.assert_(ident in [id(o) for o in subprocess._active]) |
| 2225 |
- #self.assertIn(ident, [id(o) for o in subprocess._active]) |
| 2226 |
- |
| 2227 |
- # let some time for the process to exit, and create a new Popen: this |
| 2228 |
- # should trigger the wait() of p |
| 2229 |
- time.sleep(0.2) |
| 2230 |
- #with self.assertRaises(EnvironmentError) as c: |
| 2231 |
- try: |
| 2232 |
- try: |
| 2233 |
- proc = subprocess.Popen(['nonexisting_i_hope'], |
| 2234 |
- stdout=subprocess.PIPE, |
| 2235 |
- stderr=subprocess.PIPE) |
| 2236 |
- finally: |
| 2237 |
- pass |
| 2238 |
- except EnvironmentError: |
| 2239 |
- pass |
| 2240 |
- except: |
| 2241 |
- self.fail('Expected EnvironmentError') |
| 2242 |
- else: |
| 2243 |
- self.fail('Expected EnvironmentError') |
| 2244 |
- # p should have been wait()ed on, and removed from the _active list |
| 2245 |
- #self.assertRaises(OSError, os.waitpid, pid, 0) |
| 2246 |
- try: |
| 2247 |
- os.waitpid(pid, 0) |
| 2248 |
- except OSError: |
| 2249 |
- pass |
| 2250 |
- except: |
| 2251 |
- self.fail('Expected OSError') |
| 2252 |
- else: |
| 2253 |
- self.fail('Expected OSError') |
| 2254 |
- #self.assertNotIn(ident, [id(o) for o in subprocess._active]) |
| 2255 |
- self.assert_(ident not in [id(o) for o in subprocess._active]) |
| 2256 |
- |
| 2257 |
- def test_pipe_cloexec(self): |
| 2258 |
- # Issue 12786: check that the communication pipes' FDs are set CLOEXEC, |
| 2259 |
- # and are not inherited by another child process. |
| 2260 |
- p1 = subprocess.Popen([sys.executable, "-c", |
| 2261 |
- 'import os;' |
| 2262 |
- 'os.read(0, 1)' |
| 2263 |
- ], |
| 2264 |
- stdin=subprocess.PIPE, stdout=subprocess.PIPE, |
| 2265 |
- stderr=subprocess.PIPE) |
| 2266 |
- |
| 2267 |
- p2 = subprocess.Popen([sys.executable, "-c", """if True: |
| 2268 |
- import os, errno, sys |
| 2269 |
- for fd in %r: |
| 2270 |
- try: |
| 2271 |
- os.close(fd) |
| 2272 |
- except OSError, e: |
| 2273 |
- if e.errno != errno.EBADF: |
| 2274 |
- raise |
| 2275 |
- else: |
| 2276 |
- sys.exit(1) |
| 2277 |
- sys.exit(0) |
| 2278 |
- """ % [f.fileno() for f in (p1.stdin, p1.stdout, |
| 2279 |
- p1.stderr)] |
| 2280 |
- ], |
| 2281 |
- stdin=subprocess.PIPE, stdout=subprocess.PIPE, |
| 2282 |
- stderr=subprocess.PIPE, close_fds=False) |
| 2283 |
- p1.communicate('foo') |
| 2284 |
- _, stderr = p2.communicate() |
| 2285 |
- |
| 2286 |
- self.assertEqual(p2.returncode, 0, "Unexpected error: " + repr(stderr)) |
| 2287 |
- |
| 2288 |
- |
| 2289 |
-# Not available with python-2.3's unittest, reimplement with SkipTest from |
| 2290 |
-# nose |
| 2291 |
-##@unittest.skipUnless(mswindows, "Windows specific tests") |
| 2292 |
-class Win32ProcessTestCase(BaseTestCase): |
| 2293 |
- def setUp(self): |
| 2294 |
- if not mswindows: |
| 2295 |
- raise SkipTest('Windows specific tests') |
| 2296 |
- |
| 2297 |
- def test_startupinfo(self): |
| 2298 |
- # startupinfo argument |
| 2299 |
- # We uses hardcoded constants, because we do not want to |
| 2300 |
- # depend on win32all. |
| 2301 |
- STARTF_USESHOWWINDOW = 1 |
| 2302 |
- SW_MAXIMIZE = 3 |
| 2303 |
- startupinfo = subprocess.STARTUPINFO() |
| 2304 |
- startupinfo.dwFlags = STARTF_USESHOWWINDOW |
| 2305 |
- startupinfo.wShowWindow = SW_MAXIMIZE |
| 2306 |
- # Since Python is a console process, it won't be affected |
| 2307 |
- # by wShowWindow, but the argument should be silently |
| 2308 |
- # ignored |
| 2309 |
- subprocess.call([sys.executable, "-c", "import sys; sys.exit(0)"], |
| 2310 |
- startupinfo=startupinfo) |
| 2311 |
- |
| 2312 |
- def test_creationflags(self): |
| 2313 |
- # creationflags argument |
| 2314 |
- CREATE_NEW_CONSOLE = 16 |
| 2315 |
- sys.stderr.write(" a DOS box should flash briefly ...\n") |
| 2316 |
- subprocess.call(sys.executable + |
| 2317 |
- ' -c "import time; time.sleep(0.25)"', |
| 2318 |
- creationflags=CREATE_NEW_CONSOLE) |
| 2319 |
- |
| 2320 |
- def test_invalid_args(self): |
| 2321 |
- # invalid arguments should raise ValueError |
| 2322 |
- self.assertRaises(ValueError, subprocess.call, |
| 2323 |
- [sys.executable, "-c", |
| 2324 |
- "import sys; sys.exit(47)"], |
| 2325 |
- preexec_fn=lambda: 1) |
| 2326 |
- self.assertRaises(ValueError, subprocess.call, |
| 2327 |
- [sys.executable, "-c", |
| 2328 |
- "import sys; sys.exit(47)"], |
| 2329 |
- stdout=subprocess.PIPE, |
| 2330 |
- close_fds=True) |
| 2331 |
- |
| 2332 |
- def test_close_fds(self): |
| 2333 |
- # close file descriptors |
| 2334 |
- rc = subprocess.call([sys.executable, "-c", |
| 2335 |
- "import sys; sys.exit(47)"], |
| 2336 |
- close_fds=True) |
| 2337 |
- self.assertEqual(rc, 47) |
| 2338 |
- |
| 2339 |
- def test_shell_sequence(self): |
| 2340 |
- # Run command through the shell (sequence) |
| 2341 |
- newenv = os.environ.copy() |
| 2342 |
- newenv["FRUIT"] = "physalis" |
| 2343 |
- p = subprocess.Popen(["set"], shell=1, |
| 2344 |
- stdout=subprocess.PIPE, |
| 2345 |
- env=newenv) |
| 2346 |
- self.addCleanup(p.stdout.close) |
| 2347 |
- #self.assertIn("physalis", p.stdout.read()) |
| 2348 |
- self.assert_("physalis" in p.stdout.read()) |
| 2349 |
- |
| 2350 |
- def test_shell_string(self): |
| 2351 |
- # Run command through the shell (string) |
| 2352 |
- newenv = os.environ.copy() |
| 2353 |
- newenv["FRUIT"] = "physalis" |
| 2354 |
- p = subprocess.Popen("set", shell=1, |
| 2355 |
- stdout=subprocess.PIPE, |
| 2356 |
- env=newenv) |
| 2357 |
- self.addCleanup(p.stdout.close) |
| 2358 |
- #self.assertIn("physalis", p.stdout.read()) |
| 2359 |
- self.assert_("physalis" in p.stdout.read()) |
| 2360 |
- |
| 2361 |
- def test_call_string(self): |
| 2362 |
- # call() function with string argument on Windows |
| 2363 |
- rc = subprocess.call(sys.executable + |
| 2364 |
- ' -c "import sys; sys.exit(47)"') |
| 2365 |
- self.assertEqual(rc, 47) |
| 2366 |
- |
| 2367 |
- def _kill_process(self, method, *args): |
| 2368 |
- # Some win32 buildbot raises EOFError if stdin is inherited |
| 2369 |
- p = subprocess.Popen([sys.executable, "-c", """if 1: |
| 2370 |
- import sys, time |
| 2371 |
- sys.stdout.write('x\\n') |
| 2372 |
- sys.stdout.flush() |
| 2373 |
- time.sleep(30) |
| 2374 |
- """], |
| 2375 |
- stdin=subprocess.PIPE, |
| 2376 |
- stdout=subprocess.PIPE, |
| 2377 |
- stderr=subprocess.PIPE) |
| 2378 |
- self.addCleanup(p.stdout.close) |
| 2379 |
- self.addCleanup(p.stderr.close) |
| 2380 |
- self.addCleanup(p.stdin.close) |
| 2381 |
- # Wait for the interpreter to be completely initialized before |
| 2382 |
- # sending any signal. |
| 2383 |
- p.stdout.read(1) |
| 2384 |
- getattr(p, method)(*args) |
| 2385 |
- _, stderr = p.communicate() |
| 2386 |
- self.assertStderrEqual(stderr, '') |
| 2387 |
- returncode = p.wait() |
| 2388 |
- self.assertNotEqual(returncode, 0) |
| 2389 |
- |
| 2390 |
- def test_send_signal(self): |
| 2391 |
- #if hang DISABLED #2777 |
| 2392 |
- self._kill_process('send_signal', signal.SIGTERM) |
| 2393 |
- |
| 2394 |
- def test_kill(self): |
| 2395 |
- #if hang DISABLED #2777 |
| 2396 |
- self._kill_process('kill') |
| 2397 |
- |
| 2398 |
- def test_terminate(self): |
| 2399 |
- #if hang DISABLED #2777 |
| 2400 |
- self._kill_process('terminate') |
| 2401 |
- |
| 2402 |
- |
| 2403 |
-# Not available with python-2.3's unittest. reimplement with SkipTest from |
| 2404 |
-# nose |
| 2405 |
-#@unittest.skipUnless(getattr(subprocess, '_has_poll', False), |
| 2406 |
-# "poll system call not supported") |
| 2407 |
-class ProcessTestCaseNoPoll(ProcessTestCase): |
| 2408 |
- def setUp(self): |
| 2409 |
- if not getattr(subprocess, '_has_poll', False): |
| 2410 |
- raise SkipTest('poll system call not supported') |
| 2411 |
- subprocess._has_poll = False |
| 2412 |
- ProcessTestCase.setUp(self) |
| 2413 |
- |
| 2414 |
- def tearDown(self): |
| 2415 |
- subprocess._has_poll = True |
| 2416 |
- ProcessTestCase.tearDown(self) |
| 2417 |
- |
| 2418 |
- |
| 2419 |
-class HelperFunctionTests(unittest.TestCase): |
| 2420 |
- # Not available with python-2.3's unittest. reimplement with SkipTest from |
| 2421 |
- # nose |
| 2422 |
- #@unittest.skipIf(mswindows, "errno and EINTR make no sense on windows") |
| 2423 |
- def test_eintr_retry_call(self): |
| 2424 |
- if mswindows: |
| 2425 |
- raise SkipTest('errno and EINTR make no sense on windows') |
| 2426 |
- record_calls = [] |
| 2427 |
- def fake_os_func(*args): |
| 2428 |
- record_calls.append(args) |
| 2429 |
- if len(record_calls) == 2: |
| 2430 |
- raise OSError(errno.EINTR, "fake interrupted system call") |
| 2431 |
- # reversed() is not available in python-2.3 |
| 2432 |
- args = list(args) |
| 2433 |
- args.reverse() |
| 2434 |
- return tuple(args) |
| 2435 |
- |
| 2436 |
- self.assertEqual((999, 256), |
| 2437 |
- subprocess._eintr_retry_call(fake_os_func, 256, 999)) |
| 2438 |
- self.assertEqual([(256, 999)], record_calls) |
| 2439 |
- # This time there will be an EINTR so it will loop once. |
| 2440 |
- self.assertEqual((666,), |
| 2441 |
- subprocess._eintr_retry_call(fake_os_func, 666)) |
| 2442 |
- self.assertEqual([(256, 999), (666,), (666,)], record_calls) |
| 2443 |
- |
| 2444 |
- |
| 2445 |
-# SkipUnless is not available on python < 2.7, reimplement with nose |
| 2446 |
-#@unittest.skipUnless(mswindows, "mswindows only") |
| 2447 |
-class CommandsWithSpaces (BaseTestCase): |
| 2448 |
- |
| 2449 |
- def setUp(self): |
| 2450 |
- if not mswindows: |
| 2451 |
- raise SkipTest('mswindows only') |
| 2452 |
- |
| 2453 |
- super(CommandsWithSpaces, self).setUp() |
| 2454 |
- f, fname = mkstemp(".py", "te st") |
| 2455 |
- self.fname = fname.lower() |
| 2456 |
- os.write(f, "import sys;" |
| 2457 |
- "sys.stdout.write('%d %s' % (len(sys.argv), [a.lower () for a in sys.argv]))" |
| 2458 |
- ) |
| 2459 |
- os.close(f) |
| 2460 |
- |
| 2461 |
- def tearDown(self): |
| 2462 |
- os.remove(self.fname) |
| 2463 |
- super(CommandsWithSpaces, self).tearDown() |
| 2464 |
- |
| 2465 |
- def with_spaces(self, *args, **kwargs): |
| 2466 |
- kwargs['stdout'] = subprocess.PIPE |
| 2467 |
- p = subprocess.Popen(*args, **kwargs) |
| 2468 |
- self.addCleanup(p.stdout.close) |
| 2469 |
- self.assertEqual( |
| 2470 |
- p.stdout.read().decode("mbcs"), |
| 2471 |
- "2 [%r, 'ab cd']" % self.fname |
| 2472 |
- ) |
| 2473 |
- |
| 2474 |
- def test_shell_string_with_spaces(self): |
| 2475 |
- # call() function with string argument with spaces on Windows |
| 2476 |
- self.with_spaces('"%s" "%s" "%s"' % (sys.executable, self.fname, |
| 2477 |
- "ab cd"), shell=1) |
| 2478 |
- |
| 2479 |
- def test_shell_sequence_with_spaces(self): |
| 2480 |
- # call() function with sequence argument with spaces on Windows |
| 2481 |
- self.with_spaces([sys.executable, self.fname, "ab cd"], shell=1) |
| 2482 |
- |
| 2483 |
- def test_noshell_string_with_spaces(self): |
| 2484 |
- # call() function with string argument with spaces on Windows |
| 2485 |
- self.with_spaces('"%s" "%s" "%s"' % (sys.executable, self.fname, |
| 2486 |
- "ab cd")) |
| 2487 |
- |
| 2488 |
- def test_noshell_sequence_with_spaces(self): |
| 2489 |
- # call() function with sequence argument with spaces on Windows |
| 2490 |
- self.with_spaces([sys.executable, self.fname, "ab cd"]) |
| 2491 |
- |
| 2492 |
- |
| 2493 |
-# We're using nosetests so we don't need this. This just leads to tests being |
| 2494 |
-# run twice |
| 2495 |
-#def test_main(): |
| 2496 |
-# unit_tests = (ProcessTestCase, |
| 2497 |
-# POSIXProcessTestCase, |
| 2498 |
-# Win32ProcessTestCase, |
| 2499 |
-# ProcessTestCaseNoPoll, |
| 2500 |
-# HelperFunctionTests |
| 2501 |
-# ) |
| 2502 |
-# |
| 2503 |
-# test_support.run_unittest(*unit_tests) |
| 2504 |
-# test_support.reap_children() |
| 2505 |
-# |
| 2506 |
-#if __name__ == "__main__": |
| 2507 |
-# test_main() |