~ed.so/duplicity/webdav200fix-0.7

« back to all changes in this revision

Viewing changes to testing/tests/test_misc.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:
1
 
# -*- Mode:Python; indent-tabs-mode:nil; tab-width:4 -*-
2
 
#
3
 
# Copyright 2002 Ben Escoto <ben@emerose.org>
4
 
# Copyright 2007 Kenneth Loafman <kenneth@loafman.com>
5
 
#
6
 
# This file is part of duplicity.
7
 
#
8
 
# Duplicity is free software; you can redistribute it and/or modify it
9
 
# under the terms of the GNU General Public License as published by the
10
 
# Free Software Foundation; either version 2 of the License, or (at your
11
 
# option) any later version.
12
 
#
13
 
# Duplicity is distributed in the hope that it will be useful, but
14
 
# WITHOUT ANY WARRANTY; without even the implied warranty of
15
 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16
 
# General Public License for more details.
17
 
#
18
 
# You should have received a copy of the GNU General Public License
19
 
# along with duplicity; if not, write to the Free Software Foundation,
20
 
# Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21
 
 
22
 
import helper
23
 
import sys, os, unittest, cStringIO
24
 
 
25
 
from duplicity import misc
26
 
 
27
 
helper.setup()
28
 
 
29
 
class MiscTest(unittest.TestCase):
30
 
    """Test functions/classes in misc.py"""
31
 
    def setUp(self):
32
 
        assert not os.system("tar xzf testfiles.tar.gz > /dev/null 2>&1")
33
 
 
34
 
    def tearDown(self):
35
 
        assert not os.system("rm -rf testfiles tempdir temp2.tar")
36
 
 
37
 
    def deltmp(self):
38
 
        assert not os.system("rm -rf testfiles/output")
39
 
        os.mkdir("testfiles/output")
40
 
 
41
 
    def test_file_volume_writer(self):
42
 
        """Test FileVolumeWriter class"""
43
 
        self.deltmp()
44
 
        s = "hello" * 10000
45
 
        assert len(s) == 50000
46
 
        infp = cStringIO.StringIO(s)
47
 
        fvw = misc.FileVolumeWriter(infp, "testfiles/output/volume")
48
 
        fvw.volume_size = 20000
49
 
        fvw.blocksize = 5000
50
 
 
51
 
        l = []
52
 
        for filename in fvw: l.append(filename)
53
 
        assert l == ['testfiles/output/volume.1',
54
 
                     'testfiles/output/volume.2',
55
 
                     'testfiles/output/volume.3'], l
56
 
 
57
 
        s2 = ""
58
 
        for filename in l:
59
 
            infp2 = open(filename, "rb")
60
 
            s2 += infp2.read()
61
 
            assert not infp2.close()
62
 
 
63
 
        assert s2 == s
64
 
 
65
 
    def test_file_volume_writer2(self):
66
 
        """Test again but one volume this time"""
67
 
        self.deltmp()
68
 
        fvw = misc.FileVolumeWriter(cStringIO.StringIO("hello, world!"),
69
 
                                    "testfiles/output/one_vol")
70
 
        assert fvw.next() == "testfiles/output/one_vol"
71
 
        self.assertRaises(StopIteration, fvw.next)
72
 
 
73
 
    def test_file_volume_writer3(self):
74
 
        """Test case when end of file falls exactly on volume boundary"""
75
 
        self.deltmp()
76
 
        s = "hello" * 10000
77
 
        assert len(s) == 50000
78
 
        infp = cStringIO.StringIO(s)
79
 
        fvw = misc.FileVolumeWriter(infp, "testfiles/output/volume")
80
 
        fvw.volume_size = 25000
81
 
        fvw.blocksize = 5000
82
 
 
83
 
        l = []
84
 
        for filename in fvw: l.append(filename)
85
 
        assert l == ['testfiles/output/volume.1',
86
 
                     'testfiles/output/volume.2']
87
 
 
88
 
 
89
 
 
90
 
if __name__ == "__main__":
91
 
    unittest.main()