=== modified file 'doc/core/development/policy/test-standard.xhtml'
|
old
|
new
|
|
| 292 | 292 | old code has decent coverage. Passing the <code>--coverage</code> option to |
| 293 | 293 | to Trial will generate the coverage information in a file called |
| 294 | 294 | <code>coverage</code> which can be found in the <code>_trial_temp</code> |
| 295 | | folder. This option requires Python 2.3.3 or newer.</p> |
| | 295 | folder.</p> |
| 296 | 296 | |
| 297 | 297 | <h2>Associating Test Cases With Source Files</h2> |
| 298 | 298 | |
=== modified file 'twisted/conch/test/test_cftp.py'
|
old
|
new
|
|
| 14 | 14 | |
| 15 | 15 | _reason = None |
| 16 | 16 | if Crypto and pyasn1: |
| 17 | | try: |
| 18 | | from twisted.conch import unix |
| 19 | | from twisted.conch.scripts import cftp |
| 20 | | from twisted.conch.test.test_filetransfer import FileTransferForTestAvatar |
| 21 | | except ImportError, e: |
| 22 | | # Python 2.3 compatibility fix |
| 23 | | sys.modules.pop("twisted.conch.unix", None) |
| 24 | | unix = None |
| 25 | | _reason = str(e) |
| 26 | | del e |
| | 17 | from twisted.conch import unix |
| | 18 | from twisted.conch.scripts import cftp |
| | 19 | from twisted.conch.test.test_filetransfer import FileTransferForTestAvatar |
| 27 | 20 | else: |
| 28 | 21 | unix = None |
| 29 | 22 | |
=== modified file 'twisted/lore/lint.py'
|
old
|
new
|
|
| 13 | 13 | from twisted.python import reflect |
| 14 | 14 | |
| 15 | 15 | |
| 16 | | # parser.suite in Python 2.3 raises SyntaxError, <2.3 raises parser.ParserError |
| 17 | | parserErrors = (SyntaxError, parser.ParserError) |
| 18 | | |
| 19 | 16 | class TagChecker: |
| 20 | 17 | |
| 21 | 18 | def check(self, dom, filename): |
| … |
… |
|
| 131 | 128 | text = '\n'.join(lines) + '\n' |
| 132 | 129 | try: |
| 133 | 130 | parser.suite(text) |
| 134 | | except parserErrors, e: |
| | 131 | except SyntaxError: |
| 135 | 132 | # Pretend the "..." idiom is syntactically valid |
| 136 | 133 | text = text.replace("...","'...'") |
| 137 | 134 | parser.suite(text) |
| 138 | | except parserErrors, e: |
| | 135 | except SyntaxError, e: |
| 139 | 136 | self._reportError(filename, node, |
| 140 | 137 | 'invalid python code:' + str(e)) |
| 141 | 138 | |
=== modified file 'twisted/python/_release.py'
|
old
|
new
|
|
| 424 | 424 | """ |
| 425 | 425 | Generate API documentation from source files using |
| 426 | 426 | U{pydoctor<http://codespeak.net/~mwh/pydoctor/>}. This requires |
| 427 | | pydoctor to be installed and usable (which means you won't be able to |
| 428 | | use it with Python 2.3). |
| | 427 | pydoctor to be installed and usable. |
| 429 | 428 | """ |
| 430 | 429 | def build(self, projectName, projectURL, sourceURL, packagePath, |
| 431 | 430 | outputPath): |
=== modified file 'twisted/python/reflect.py'
|
old
|
new
|
|
| 438 | 438 | @raise _NoModuleFound: if no module was found. |
| 439 | 439 | """ |
| 440 | 440 | try: |
| 441 | | try: |
| 442 | | return __import__(importName) |
| 443 | | except ImportError: |
| 444 | | excType, excValue, excTraceback = sys.exc_info() |
| 445 | | while excTraceback: |
| 446 | | execName = excTraceback.tb_frame.f_globals["__name__"] |
| 447 | | if (execName is None or # python 2.4+, post-cleanup |
| 448 | | execName == importName): # python 2.3, no cleanup |
| 449 | | raise excType, excValue, excTraceback |
| 450 | | excTraceback = excTraceback.tb_next |
| 451 | | raise _NoModuleFound() |
| 452 | | except: |
| 453 | | # Necessary for cleaning up modules in 2.3. |
| 454 | | sys.modules.pop(importName, None) |
| 455 | | raise |
| | 441 | return __import__(importName) |
| | 442 | except ImportError: |
| | 443 | excType, excValue, excTraceback = sys.exc_info() |
| | 444 | while excTraceback: |
| | 445 | execName = excTraceback.tb_frame.f_globals["__name__"] |
| | 446 | if execName is None: |
| | 447 | raise excType, excValue, excTraceback |
| | 448 | excTraceback = excTraceback.tb_next |
| | 449 | raise _NoModuleFound() |
| 456 | 450 | |
| 457 | 451 | |
| 458 | 452 | |
=== modified file 'twisted/python/syslog.py'
|
old
|
new
|
|
| 12 | 12 | |
| 13 | 13 | from twisted.python import log |
| 14 | 14 | |
| 15 | | # These defaults come from the Python 2.3 syslog docs. |
| | 15 | # These defaults come from the Python syslog docs. |
| 16 | 16 | DEFAULT_OPTIONS = 0 |
| 17 | 17 | DEFAULT_FACILITY = syslog.LOG_USER |
| 18 | 18 | |
=== modified file 'twisted/python/util.py'
|
old
|
new
|
|
| 791 | 791 | representation makes sense. |
| 792 | 792 | |
| 793 | 793 | This is mostly necessary in Python 2.4 which implements L{id} to sometimes |
| 794 | | return a negative value. Python 2.3 shares this behavior, but also |
| 795 | | implements hex and the %x format specifier to represent negative values as |
| 796 | | though they were positive ones, obscuring the behavior of L{id}. Python |
| 797 | | 2.5's implementation of L{id} always returns positive values. |
| | 794 | return a negative value. Python 2.5's implementation of L{id} always |
| | 795 | returns positive values. |
| 798 | 796 | """ |
| 799 | 797 | rval = _idFunction(obj) |
| 800 | 798 | if rval < 0: |
| … |
… |
|
| 807 | 805 | Overwrite C{g}'s name and docstring with values from C{f}. Update |
| 808 | 806 | C{g}'s instance dictionary with C{f}'s. |
| 809 | 807 | |
| 810 | | To use this function safely you must use the return value. In Python 2.3, |
| 811 | | L{mergeFunctionMetadata} will create a new function. In later versions of |
| 812 | | Python, C{g} will be mutated and returned. |
| | 808 | To use this function safely you must use the return value. C{g} will |
| | 809 | be mutated and returned. |
| 813 | 810 | |
| 814 | 811 | @return: A function that has C{g}'s behavior and metadata merged from |
| 815 | 812 | C{f}. |
| … |
… |
|
| 817 | 814 | try: |
| 818 | 815 | g.__name__ = f.__name__ |
| 819 | 816 | except TypeError: |
| 820 | | try: |
| 821 | | merged = types.FunctionType( |
| 822 | | g.func_code, g.func_globals, |
| 823 | | f.__name__, inspect.getargspec(g)[-1], |
| 824 | | g.func_closure) |
| 825 | | except TypeError: |
| 826 | | pass |
| | 817 | pass |
| 827 | 818 | else: |
| 828 | 819 | merged = g |
| 829 | 820 | try: |
=== modified file 'twisted/spread/jelly.py'
|
old
|
new
|
|
| 54 | 54 | The C{set} builtin and the C{sets.Set} class are serialized to the same |
| 55 | 55 | thing, and unserialized to C{set} if available, else to C{sets.Set}. It means |
| 56 | 56 | that there's a possibility of type switching in the serialization process. The |
| 57 | | solution is to always use C{set} if possible, and only use C{sets.Set} under |
| 58 | | Python 2.3; this can be accomplished by using L{twisted.python.compat.set}. |
| | 57 | solution is to always use C{set} if possible; this can be accomplished by using L{twisted.python.compat.set}. |
| 59 | 58 | |
| 60 | 59 | The same rule applies for C{frozenset} and C{sets.ImmutableSet}. |
| 61 | 60 | |
=== modified file 'twisted/test/test_reflect.py'
|
old
|
new
|
|
| 217 | 217 | self.assertRaises( |
| 218 | 218 | ZeroDivisionError, |
| 219 | 219 | reflect.namedAny, "twisted.test.reflect_helper_ZDE") |
| 220 | | # Make sure that this behavior is *consistent* for 2.3, where there is |
| 221 | | # no post-failed-import cleanup |
| 222 | 220 | self.assertRaises( |
| 223 | 221 | ZeroDivisionError, |
| 224 | 222 | reflect.namedAny, "twisted.test.reflect_helper_ZDE") |
| … |
… |
|
| 413 | 411 | self.assertEqual(['[0]', '[1][0]'], reflect.objgrep(d, a, reflect.isSame, maxDepth=2)) |
| 414 | 412 | self.assertEqual(['[0]', '[1][0]', '[1][1][0]'], reflect.objgrep(d, a, reflect.isSame, maxDepth=3)) |
| 415 | 413 | |
| 416 | | def test_deque(self): |
| 417 | | """ |
| 418 | | Test references search through a deque object. Only for Python > 2.3. |
| 419 | | """ |
| 420 | | o = object() |
| 421 | | D = deque() |
| 422 | | D.append(None) |
| 423 | | D.append(o) |
| 424 | | |
| 425 | | self.assertIn("[1]", reflect.objgrep(D, o, reflect.isSame)) |
| 426 | | |
| 427 | | if deque is None: |
| 428 | | test_deque.skip = "Deque not available" |
| 429 | | |
| 430 | 414 | |
| 431 | 415 | class GetClass(unittest.TestCase): |
| 432 | 416 | def testOld(self): |
=== modified file 'twisted/trial/runner.py'
|
old
|
new
|
|
| 189 | 189 | DEPRECATED in Twisted 8.0. |
| 190 | 190 | |
| 191 | 191 | This class decorates the pyunit.TestCase class, mainly to work around the |
| 192 | | differences between unittest in Python 2.3, 2.4, and 2.5. These |
| | 192 | differences between unittest in Python 2.4, and 2.5. These |
| 193 | 193 | differences are:: |
| 194 | 194 | |
| 195 | 195 | - The way doctest unittests describe themselves |
| … |
… |
|
| 239 | 239 | |
| 240 | 240 | |
| 241 | 241 | |
| 242 | | class DocTestCase(PyUnitTestCase): |
| 243 | | """ |
| 244 | | DEPRECATED in Twisted 8.0. |
| 245 | | """ |
| 246 | | |
| 247 | | def id(self): |
| 248 | | """ |
| 249 | | In Python 2.4, doctests have correct id() behaviour. In Python 2.3, |
| 250 | | id() returns 'runit'. |
| 251 | | |
| 252 | | Here we override id() so that at least it will always contain the |
| 253 | | fully qualified Python name of the doctest. |
| 254 | | """ |
| 255 | | return self._test.shortDescription() |
| 256 | | |
| 257 | | |
| 258 | 242 | class TrialSuite(TestSuite): |
| 259 | 243 | """ |
| 260 | 244 | Suite to wrap around every single test in a C{trial} run. Used internally |
=== modified file 'twisted/trial/test/test_doctest.py'
|
old
|
new
|
|
| 14 | 14 | Tests for Twisted's doctest support. |
| 15 | 15 | """ |
| 16 | 16 | |
| 17 | | def test_id(self): |
| 18 | | """ |
| 19 | | Check that the id() of the doctests' case object contains the FQPN of |
| 20 | | the actual tests. We need this because id() has weird behaviour w/ |
| 21 | | doctest in Python 2.3. |
| 22 | | """ |
| 23 | | loader = runner.TestLoader() |
| 24 | | suite = loader.loadDoctests(mockdoctest) |
| 25 | | idPrefix = 'twisted.trial.test.mockdoctest.Counter' |
| 26 | | for test in suite._tests: |
| 27 | | self.assertIn(idPrefix, itrial.ITestCase(test).id()) |
| 28 | | |
| 29 | | |
| 30 | 17 | def test_basicTrialIntegration(self): |
| 31 | 18 | """ |
| 32 | 19 | L{loadDoctests} loads all of the doctests in the given module. |
| … |
… |
|
| 43 | 30 | result = reporter.TestResult() |
| 44 | 31 | suite.run(result) |
| 45 | 32 | self.assertEqual(5, result.successes) |
| 46 | | # doctest reports failures as errors in 2.3 |
| 47 | | self.assertEqual(2, len(result.errors) + len(result.failures)) |
| | 33 | self.assertEqual(2, len(result.failures)) |
| 48 | 34 | |
| 49 | 35 | |
| 50 | 36 | def test_expectedResults(self, count=1): |
=== modified file 'twisted/trial/test/test_loader.py'
|
old
|
new
|
|
| 510 | 510 | |
| 511 | 511 | |
| 512 | 512 | class PackageOrderingTest(packages.SysPathManglingTest): |
| 513 | | if sys.version_info < (2, 4): |
| 514 | | skip = ( |
| 515 | | "Python 2.3 import semantics make this behavior incorrect on that " |
| 516 | | "version of Python as well as difficult to test. The second " |
| 517 | | "import of a package which raised an exception the first time it " |
| 518 | | "was imported will succeed on Python 2.3, whereas it will fail on " |
| 519 | | "later versions of Python. Trial does not account for this, so " |
| 520 | | "this test fails with inconsistencies between the expected and " |
| 521 | | "the received loader errors.") |
| 522 | 513 | |
| 523 | 514 | def setUp(self): |
| 524 | 515 | self.loader = runner.TestLoader() |
=== modified file 'twisted/trial/unittest.py'
|
old
|
new
|
|
| 1401 | 1401 | return self.run(result) |
| 1402 | 1402 | |
| 1403 | 1403 | |
| 1404 | | def run(self, result): |
| 1405 | | """ |
| 1406 | | Call C{run} on every member of the suite. |
| 1407 | | """ |
| 1408 | | # we implement this because Python 2.3 unittest defines this code |
| 1409 | | # in __call__, whereas 2.4 defines the code in run. |
| 1410 | | for test in self._tests: |
| 1411 | | if result.shouldStop: |
| 1412 | | break |
| 1413 | | test(result) |
| 1414 | | return result |
| 1415 | | |
| 1416 | | |
| 1417 | | |
| 1418 | 1404 | class TestDecorator(components.proxyForInterface(itrial.ITestCase, |
| 1419 | 1405 | "_originalTest")): |
| 1420 | 1406 | """ |
| … |
… |
|
| 1570 | 1556 | |
| 1571 | 1557 | |
| 1572 | 1558 | |
| 1573 | | # Support for Python 2.3 |
| 1574 | | try: |
| 1575 | | iter(pyunit.TestSuite()) |
| 1576 | | except TypeError: |
| 1577 | | # Python 2.3's TestSuite doesn't support iteration. Let's monkey patch it! |
| 1578 | | def __iter__(self): |
| 1579 | | return iter(self._tests) |
| 1580 | | pyunit.TestSuite.__iter__ = __iter__ |
| | 1559 | iter(pyunit.TestSuite()) |
| 1581 | 1560 | |
| 1582 | 1561 | |
| 1583 | 1562 | |
=== modified file 'twisted/web/http_headers.py'
|
old
|
new
|
|
| 78 | 78 | return dict(self.items()) |
| 79 | 79 | |
| 80 | 80 | |
| 81 | | # Python 2.3 DictMixin.setdefault is defined so as not to have a default |
| 82 | | # for the value parameter. This is necessary to make this setdefault look |
| 83 | | # like dict.setdefault on Python 2.3. -exarkun |
| 84 | | def setdefault(self, name, value=None): |
| 85 | | """ |
| 86 | | Retrieve the last value for the given header name. If there are no |
| 87 | | values present for that header, set the value to C{value} and return |
| 88 | | that instead. Note that C{None} is the default for C{value} for |
| 89 | | backwards compatibility, but header values may only be of type C{str}. |
| 90 | | """ |
| 91 | | return DictMixin.setdefault(self, name, value) |
| 92 | | |
| 93 | | |
| 94 | 81 | # The remaining methods are only for efficiency. The same behavior |
| 95 | 82 | # should remain even if they are removed. For details, see |
| 96 | 83 | # <http://docs.python.org/lib/module-UserDict.html>. |
=== modified file 'twisted/words/protocols/jabber/sasl.py'
|
old
|
new
|
|
| 5 | 5 | XMPP-specific SASL profile. |
| 6 | 6 | """ |
| 7 | 7 | |
| | 8 | from base64 import b64decode, b64encode |
| 8 | 9 | import re |
| 9 | 10 | from twisted.internet import defer |
| 10 | 11 | from twisted.words.protocols.jabber import sasl_mechanisms, xmlstream |
| 11 | 12 | from twisted.words.xish import domish |
| 12 | 13 | |
| 13 | | # The b64decode and b64encode functions from the base64 module are new in |
| 14 | | # Python 2.4. For Python 2.3 compatibility, the legacy interface is used while |
| 15 | | # working around MIMEisms. |
| 16 | | |
| 17 | | try: |
| 18 | | from base64 import b64decode, b64encode |
| 19 | | except ImportError: |
| 20 | | import base64 |
| 21 | | |
| 22 | | def b64encode(s): |
| 23 | | return "".join(base64.encodestring(s).split("\n")) |
| 24 | | |
| 25 | | b64decode = base64.decodestring |
| 26 | | |
| 27 | 14 | NS_XMPP_SASL = 'urn:ietf:params:xml:ns:xmpp-sasl' |
| 28 | 15 | |
| 29 | 16 | def get_mechanisms(xs): |
=== modified file 'twisted/words/protocols/jabber/xmpp_stringprep.py'
|
old
|
new
|
|
| 20 | 20 | |
| 21 | 21 | warnings.warn("Accented and non-Western Jabber IDs will not be properly " |
| 22 | 22 | "case-folded with this version of Python, resulting in " |
| 23 | | "incorrect protocol-level behavior. It is strongly " |
| 24 | | "recommended you upgrade to Python 2.3.2 or newer if you " |
| 25 | | "intend to use Twisted's Jabber support.") |
| | 23 | "incorrect protocol-level behavior.") |
| 26 | 24 | |
| 27 | 25 | else: |
| 28 | 26 | import stringprep |