~johnleach/duplicity/1315437-swift-container-create

« back to all changes in this revision

Viewing changes to duplicity/util.py

  • Committer: Kenneth Loafman
  • Date: 2014-04-20 15:32:17 UTC
  • mfrom: (977.1.8 test-reorg)
  • Revision ID: kenneth@loafman.com-20140420153217-n4jt28oo4q7d6bzu
# Merged in lp:~mterry/duplicity/more-test-reorg
  - Here's another test reorganization / modernization branch. It does the
    following things:
    - Drop duplicity/misc.py. It is confusing to have both misc.py and util.py,
      and most of the code in misc.py was no longer used. I moved the one
      function that was still used into util.py.
    - Consolidated the various ways to run tests into just one. I made tox runs
      go through ./setup.py test, rather than nosetests. And I made the
      ./testing/run-tests scripts just call tox. Now we no longer need nosetests
      as a test dependency (although you can still use it if you want).
    - Added two more code quality automated tests: a pep8 one and a pylint one.
      I disabled almost all checks in each program that gave a warning. These
      tests just establish a baseline for future improvement.
    - Moved the test helper code into TestCase subclasses that all tests can
      use. And used more code sharing and setUp/tearDown cleverness to remove
      duplicated code.
    - Reorganized the tests in ./testing/tests into ./testing/functional and
      ./testing/unit -- for whether they drive duplicity as a subprocess or
      whether they import and test code directly. Each dir can have specialized
      TestCase subclasses now.
    - Renamed the files in ./testing/unit to more clearly indicate which file
      in ./duplicity they are unit testing.
    - Added some helper methods for tests to set environment and globals.*
      parameters more safely (i.e. without affecting other tests) by
      automatically cleaning up any such changes during test tearDown.
    - Removed test_unicode.py, since it is kind of dumb. It used to be more
      useful, but now with py2.6, we are just testing that one line of code
      in it is actually there.

Show diffs side-by-side

added added

removed removed

Lines of Context:
145
145
        except UnlockError:
146
146
            pass
147
147
 
 
148
def copyfileobj(infp, outfp, byte_count = -1):
 
149
    """Copy byte_count bytes from infp to outfp, or all if byte_count < 0
 
150
 
 
151
    Returns the number of bytes actually written (may be less than
 
152
    byte_count if find eof.  Does not close either fileobj.
 
153
 
 
154
    """
 
155
    blocksize = 64 * 1024
 
156
    bytes_written = 0
 
157
    if byte_count < 0:
 
158
        while 1:
 
159
            buf = infp.read(blocksize)
 
160
            if not buf:
 
161
                break
 
162
            bytes_written += len(buf)
 
163
            outfp.write(buf)
 
164
    else:
 
165
        while bytes_written + blocksize <= byte_count:
 
166
            buf = infp.read(blocksize)
 
167
            if not buf:
 
168
                break
 
169
            bytes_written += len(buf)
 
170
            outfp.write(buf)
 
171
        buf = infp.read(byte_count - bytes_written)
 
172
        bytes_written += len(buf)
 
173
        outfp.write(buf)
 
174
    return bytes_written