~ubuntu-branches/ubuntu/precise/ubuntuone-client/precise-201112142106

« back to all changes in this revision

Viewing changes to tests/syncdaemon/test_fileshelf.py

  • Committer: Bazaar Package Importer
  • Author(s): Rodney Dawes
  • Date: 2011-08-09 12:47:56 UTC
  • mfrom: (1.1.53 upstream)
  • Revision ID: james.westby@ubuntu.com-20110809124756-7nzilp3oix0a1yl9
Tags: 1.7.1-0ubuntu1
* New upstream release.
* debian/*:
  - Removed obsolete pycompat file
  - Removed ubuntuone-client-gnome deps and binary packaging, as it was
    moved out to separate project upstream.
  - Updated copyright to remove obsolete file reference
* debian/patches:
  - Removed patches which have been included upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
import os
23
23
import hashlib
24
24
import unittest
25
 
import shutil
26
 
 
 
25
 
 
26
from twisted.internet import defer
 
27
 
 
28
from ubuntuone.devtools.testcase import skipIfOS
 
29
from ubuntuone.platform import path_exists, open_file
27
30
from ubuntuone.syncdaemon.file_shelf import (
28
31
    FileShelf,
29
32
    CachedFileShelf,
30
33
    LRUCache,
31
34
    CacheInconsistencyError,
32
35
)
33
 
from contrib.testing import testcase
 
36
from contrib.testing.testcase import BaseTwistedTestCase
34
37
 
35
38
 
36
39
BROKEN_PICKLE = '\axb80\x02}q\x01(U\x01aU\x04testq\x02U\x01bU\x06brokenq\x03u.'
37
40
 
38
41
 
39
 
class TestFileShelf(testcase.BaseTwistedTestCase):
 
42
class TestFileShelf(BaseTwistedTestCase):
40
43
    """ Test the FileShelf """
41
44
    fileshelf_class = FileShelf
42
45
 
 
46
    @defer.inlineCallbacks
43
47
    def setUp(self):
44
48
        """ Sets up a test. """
45
 
        testcase.BaseTwistedTestCase.setUp(self)
 
49
        yield super(TestFileShelf, self).setUp()
46
50
        self.path = self.mktemp('shelf')
47
51
        self.shelf = self.fileshelf_class(self.path)
48
52
 
49
 
    def tearDown(self):
50
 
        """Clean up the tests."""
51
 
        shutil.rmtree(self.path)
52
 
        testcase.BaseTwistedTestCase.tearDown(self)
53
 
 
54
53
    def test_bad_depth(self):
55
54
        """ test that the shelf reject invalid depth at creation time """
56
55
        self.assertRaises(ValueError, self.fileshelf_class, self.path, depth=-1)
77
76
            # test __setitem__
78
77
            shelf[key] = 'foo'
79
78
            key_path = os.path.join(path, *[key[i] for i in xrange(0, idx)])
80
 
            self.assertTrue(os.path.exists(os.path.join(key_path, key)))
 
79
            self.assertTrue(path_exists(os.path.join(key_path, key)))
81
80
            # test __getitem__
82
81
            self.assertEquals('foo', shelf[key])
83
82
            # test __delitem__
206
205
        path = self.shelf.key_file('foo')
207
206
        open(self.shelf.key_file('foo'), 'w').close()
208
207
        for _ in xrange(20):
209
 
            open(path+'.old', 'w').close()
 
208
            open_file(path+'.old', 'w').close()
210
209
            path=path+'.old'
211
210
        self.assertRaises(KeyError, self.shelf.__getitem__, 'foo')
212
211
 
224
223
        self.assertFalse(os.path.exists(path+'.old'), 'there is a .old file!')
225
224
        self.assertFalse(os.path.exists(path+'.new'), 'there is a .new file!')
226
225
 
 
226
    @skipIfOS('win32', 'Skipped because code is deprecated on Windows.')
227
227
    def test_custom_unpickle(self):
228
228
        """Test the _pickle and _unpikle methods."""
229
229
        self.mktemp('my_shelf')
467
467
            cache['key2']
468
468
        except CacheInconsistencyError, e:
469
469
            self.fail(e)
470
 
 
471
 
 
472
 
def test_suite():
473
 
    # pylint: disable-msg=C0111
474
 
    return unittest.TestLoader().loadTestsFromName(__name__)
475
 
 
476
 
if __name__ == "__main__":
477
 
    unittest.main()
478