Changeset 65500de in trunk


Ignore:
Timestamp:
2020-07-24T18:13:28Z (5 years ago)
Author:
Itamar Turner-Trauring <itamar@…>
Branches:
master
Children:
7d0f773
Parents:
8bcd6dd (diff), 383c564 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge remote-tracking branch 'origin/master' into 3346.abbreviate-and-time_format-py3

Files:
2 added
6 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified misc/python3/ratchet-passing

    r8bcd6dd r65500de  
    5353allmydata.test.test_observer.Observer.test_oneshot
    5454allmydata.test.test_observer.Observer.test_oneshot_fireagain
     55allmydata.test.test_pipeline.Pipeline.test_basic
     56allmydata.test.test_pipeline.Pipeline.test_errors
     57allmydata.test.test_pipeline.Pipeline.test_errors2
    5558allmydata.test.test_python3.Python3PortingEffortTests.test_finished_porting
    5659allmydata.test.test_python3.Python3PortingEffortTests.test_ported_modules_distinct
  • TabularUnified src/allmydata/test/test_observer.py

    r8bcd6dd r65500de  
     1"""
     2Tests for allmydata.util.observer.
     3
     4Ported to Python 3.
     5"""
     6
     7from __future__ import absolute_import
     8from __future__ import division
     9from __future__ import print_function
     10from __future__ import unicode_literals
     11
     12from future.utils import PY2
     13if PY2:
     14    from builtins import filter, map, zip, ascii, chr, hex, input, next, oct, open, pow, round, super, bytes, dict, int, list, object, range, str, max, min  # noqa: F401
    115
    216from twisted.trial import unittest
  • TabularUnified src/allmydata/test/test_util.py

    r8bcd6dd r65500de  
    66import os, time, sys
    77import yaml
    8 import gc  # support PyPy
    98
    109from six.moves import StringIO
     
    1211from twisted.internet import defer, reactor
    1312from twisted.python.failure import Failure
    14 from twisted.python import log
    1513
    1614from allmydata.util import idlib, mathutil
    1715from allmydata.util import fileutil
    1816from allmydata.util import limiter, pollmixin
    19 from allmydata.util import statistics, dictutil, pipeline, yamlutil
     17from allmydata.util import statistics, dictutil, yamlutil
    2018from allmydata.util import log as tahoe_log
    2119from allmydata.util.spans import Spans, overlap, DataSpans
     
    752750        self.failUnlessEqual(d.get_aux("one"), None)
    753751
    754 class Pipeline(unittest.TestCase):
    755     def pause(self, *args, **kwargs):
    756         d = defer.Deferred()
    757         self.calls.append( (d, args, kwargs) )
    758         return d
    759 
    760     def failUnlessCallsAre(self, expected):
    761         #print self.calls
    762         #print expected
    763         self.failUnlessEqual(len(self.calls), len(expected), self.calls)
    764         for i,c in enumerate(self.calls):
    765             self.failUnlessEqual(c[1:], expected[i], str(i))
    766 
    767     def test_basic(self):
    768         self.calls = []
    769         finished = []
    770         p = pipeline.Pipeline(100)
    771 
    772         d = p.flush() # fires immediately
    773         d.addCallbacks(finished.append, log.err)
    774         self.failUnlessEqual(len(finished), 1)
    775         finished = []
    776 
    777         d = p.add(10, self.pause, "one")
    778         # the call should start right away, and our return Deferred should
    779         # fire right away
    780         d.addCallbacks(finished.append, log.err)
    781         self.failUnlessEqual(len(finished), 1)
    782         self.failUnlessEqual(finished[0], None)
    783         self.failUnlessCallsAre([ ( ("one",) , {} ) ])
    784         self.failUnlessEqual(p.gauge, 10)
    785 
    786         # pipeline: [one]
    787 
    788         finished = []
    789         d = p.add(20, self.pause, "two", kw=2)
    790         # pipeline: [one, two]
    791 
    792         # the call and the Deferred should fire right away
    793         d.addCallbacks(finished.append, log.err)
    794         self.failUnlessEqual(len(finished), 1)
    795         self.failUnlessEqual(finished[0], None)
    796         self.failUnlessCallsAre([ ( ("one",) , {} ),
    797                                   ( ("two",) , {"kw": 2} ),
    798                                   ])
    799         self.failUnlessEqual(p.gauge, 30)
    800 
    801         self.calls[0][0].callback("one-result")
    802         # pipeline: [two]
    803         self.failUnlessEqual(p.gauge, 20)
    804 
    805         finished = []
    806         d = p.add(90, self.pause, "three", "posarg1")
    807         # pipeline: [two, three]
    808         flushed = []
    809         fd = p.flush()
    810         fd.addCallbacks(flushed.append, log.err)
    811         self.failUnlessEqual(flushed, [])
    812 
    813         # the call will be made right away, but the return Deferred will not,
    814         # because the pipeline is now full.
    815         d.addCallbacks(finished.append, log.err)
    816         self.failUnlessEqual(len(finished), 0)
    817         self.failUnlessCallsAre([ ( ("one",) , {} ),
    818                                   ( ("two",) , {"kw": 2} ),
    819                                   ( ("three", "posarg1"), {} ),
    820                                   ])
    821         self.failUnlessEqual(p.gauge, 110)
    822 
    823         self.failUnlessRaises(pipeline.SingleFileError, p.add, 10, self.pause)
    824 
    825         # retiring either call will unblock the pipeline, causing the #3
    826         # Deferred to fire
    827         self.calls[2][0].callback("three-result")
    828         # pipeline: [two]
    829 
    830         self.failUnlessEqual(len(finished), 1)
    831         self.failUnlessEqual(finished[0], None)
    832         self.failUnlessEqual(flushed, [])
    833 
    834         # retiring call#2 will finally allow the flush() Deferred to fire
    835         self.calls[1][0].callback("two-result")
    836         self.failUnlessEqual(len(flushed), 1)
    837 
    838     def test_errors(self):
    839         self.calls = []
    840         p = pipeline.Pipeline(100)
    841 
    842         d1 = p.add(200, self.pause, "one")
    843         d2 = p.flush()
    844 
    845         finished = []
    846         d1.addBoth(finished.append)
    847         self.failUnlessEqual(finished, [])
    848 
    849         flushed = []
    850         d2.addBoth(flushed.append)
    851         self.failUnlessEqual(flushed, [])
    852 
    853         self.calls[0][0].errback(ValueError("oops"))
    854 
    855         self.failUnlessEqual(len(finished), 1)
    856         f = finished[0]
    857         self.failUnless(isinstance(f, Failure))
    858         self.failUnless(f.check(pipeline.PipelineError))
    859         self.failUnlessIn("PipelineError", str(f.value))
    860         self.failUnlessIn("ValueError", str(f.value))
    861         r = repr(f.value)
    862         self.failUnless("ValueError" in r, r)
    863         f2 = f.value.error
    864         self.failUnless(f2.check(ValueError))
    865 
    866         self.failUnlessEqual(len(flushed), 1)
    867         f = flushed[0]
    868         self.failUnless(isinstance(f, Failure))
    869         self.failUnless(f.check(pipeline.PipelineError))
    870         f2 = f.value.error
    871         self.failUnless(f2.check(ValueError))
    872 
    873         # now that the pipeline is in the failed state, any new calls will
    874         # fail immediately
    875 
    876         d3 = p.add(20, self.pause, "two")
    877 
    878         finished = []
    879         d3.addBoth(finished.append)
    880         self.failUnlessEqual(len(finished), 1)
    881         f = finished[0]
    882         self.failUnless(isinstance(f, Failure))
    883         self.failUnless(f.check(pipeline.PipelineError))
    884         r = repr(f.value)
    885         self.failUnless("ValueError" in r, r)
    886         f2 = f.value.error
    887         self.failUnless(f2.check(ValueError))
    888 
    889         d4 = p.flush()
    890         flushed = []
    891         d4.addBoth(flushed.append)
    892         self.failUnlessEqual(len(flushed), 1)
    893         f = flushed[0]
    894         self.failUnless(isinstance(f, Failure))
    895         self.failUnless(f.check(pipeline.PipelineError))
    896         f2 = f.value.error
    897         self.failUnless(f2.check(ValueError))
    898 
    899     def test_errors2(self):
    900         self.calls = []
    901         p = pipeline.Pipeline(100)
    902 
    903         d1 = p.add(10, self.pause, "one")
    904         d2 = p.add(20, self.pause, "two")
    905         d3 = p.add(30, self.pause, "three")
    906         d4 = p.flush()
    907 
    908         # one call fails, then the second one succeeds: make sure
    909         # ExpandableDeferredList tolerates the second one
    910 
    911         flushed = []
    912         d4.addBoth(flushed.append)
    913         self.failUnlessEqual(flushed, [])
    914 
    915         self.calls[0][0].errback(ValueError("oops"))
    916         self.failUnlessEqual(len(flushed), 1)
    917         f = flushed[0]
    918         self.failUnless(isinstance(f, Failure))
    919         self.failUnless(f.check(pipeline.PipelineError))
    920         f2 = f.value.error
    921         self.failUnless(f2.check(ValueError))
    922 
    923         self.calls[1][0].callback("two-result")
    924         self.calls[2][0].errback(ValueError("three-error"))
    925 
    926         del d1,d2,d3,d4
    927         gc.collect()  # for PyPy
    928752
    929753class SampleError(Exception):
  • TabularUnified src/allmydata/util/_python3.py

    r8bcd6dd r65500de  
    2727    "allmydata.util.namespace",
    2828    "allmydata.util.netstring",
     29    "allmydata.util.observer",
     30    "allmydata.util.pipeline",
    2931    "allmydata.util.pollmixin",
    3032    "allmydata.util._python3",
     
    4244    "allmydata.test.test_humanreadable",
    4345    "allmydata.test.test_netstring",
     46    "allmydata.test.test_observer",
     47    "allmydata.test.test_pipeline",
    4448    "allmydata.test.test_python3",
    4549    "allmydata.test.test_time_format",
  • TabularUnified src/allmydata/util/observer.py

    r8bcd6dd r65500de  
    1 # -*- test-case-name: allmydata.test.test_observer -*-
     1"""
     2Observer for Twisted code.
     3
     4Ported to Python 3.
     5"""
     6
     7from __future__ import absolute_import
     8from __future__ import division
     9from __future__ import print_function
     10from __future__ import unicode_literals
     11
     12from future.utils import PY2
     13if PY2:
     14    from builtins import filter, map, zip, ascii, chr, hex, input, next, oct, open, pow, round, super, bytes, dict, int, list, object, range, str, max, min  # noqa: F401
    215
    316import weakref
  • TabularUnified src/allmydata/util/pipeline.py

    r8bcd6dd r65500de  
     1"""
     2A pipeline of Deferreds.
     3
     4Ported to Python 3.
     5"""
     6
     7from __future__ import absolute_import
     8from __future__ import division
     9from __future__ import print_function
     10from __future__ import unicode_literals
     11
     12from future.utils import PY2
     13if PY2:
     14    from builtins import filter, map, zip, ascii, chr, hex, input, next, oct, open, pow, round, super, bytes, dict, int, list, object, range, str, max, min  # noqa: F401
    115
    216from twisted.internet import defer
     
    418from twisted.python import log
    519from allmydata.util.assertutil import precondition
     20
    621
    722class PipelineError(Exception):
Note: See TracChangeset for help on using the changeset viewer.