Merge lp:~mandel/ubuntuone-client/fix-file-shelf-windows into lp:ubuntuone-client

Proposed by Manuel de la Peña
Status: Merged
Approved by: Natalia Bidart
Approved revision: 1129
Merged at revision: 1094
Proposed branch: lp:~mandel/ubuntuone-client/fix-file-shelf-windows
Merge into: lp:ubuntuone-client
Prerequisite: lp:~mandel/ubuntuone-client/fix-aq-tests-windows
Diff against target: 129 lines (+18/-19)
3 files modified
tests/syncdaemon/test_fileshelf.py (+5/-2)
tests/syncdaemon/test_vm.py (+5/-9)
ubuntuone/syncdaemon/file_shelf.py (+8/-8)
To merge this branch: bzr merge lp:~mandel/ubuntuone-client/fix-file-shelf-windows
Reviewer Review Type Date Requested Status
Natalia Bidart (community) Approve
Review via email: mp+70021@code.launchpad.net

Commit message

Ensure that file_shelf tests do pass on windows and that the module uses the os_helper methods.

Description of the change

Ensure that file_shelf tests do pass on windows and that the module uses the os_helper methods.

To post a comment you must log in.
Revision history for this message
Natalia Bidart (nataliabidart) wrote :

This change:

25 - key = fd.name.strip('.new')
26 + key = os.path.split(fd.name.strip('.new'))[1]

does not seem appropriate to me, you're hiding the fact that in windows, somehow, fd.name is a full path and in linux is not.

Like we talked about in IRC, we should just skip the test suite for file_shelf in windows since that code will not be used there.

review: Needs Fixing
1126. By Manuel de la Peña

Skipped problematic test on Windows since the code is deprecated in that platform.

Revision history for this message
Manuel de la Peña (mandel) wrote :

I have updated the branch to skip such test so that we ignore the fact that open_file does work in a different way. As food for though I think we should consider update or test case to add an assertEqualPath (or something of the like) so that we can ignore this facts.

1127. By Manuel de la Peña

Merged with trunk.

1128. By Manuel de la Peña

Use open_file instead of open in the tests.

1129. By Manuel de la Peña

Re add the new line.

Revision history for this message
Natalia Bidart (nataliabidart) wrote :

Looks much better now!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'tests/syncdaemon/test_fileshelf.py'
2--- tests/syncdaemon/test_fileshelf.py 2011-07-27 14:26:36 +0000
3+++ tests/syncdaemon/test_fileshelf.py 2011-08-05 15:23:53 +0000
4@@ -25,6 +25,8 @@
5
6 from twisted.internet import defer
7
8+from ubuntuone.devtools.testcase import skipIfOS
9+from ubuntuone.platform import path_exists, open_file
10 from ubuntuone.syncdaemon.file_shelf import (
11 FileShelf,
12 CachedFileShelf,
13@@ -74,7 +76,7 @@
14 # test __setitem__
15 shelf[key] = 'foo'
16 key_path = os.path.join(path, *[key[i] for i in xrange(0, idx)])
17- self.assertTrue(os.path.exists(os.path.join(key_path, key)))
18+ self.assertTrue(path_exists(os.path.join(key_path, key)))
19 # test __getitem__
20 self.assertEquals('foo', shelf[key])
21 # test __delitem__
22@@ -203,7 +205,7 @@
23 path = self.shelf.key_file('foo')
24 open(self.shelf.key_file('foo'), 'w').close()
25 for _ in xrange(20):
26- open(path+'.old', 'w').close()
27+ open_file(path+'.old', 'w').close()
28 path=path+'.old'
29 self.assertRaises(KeyError, self.shelf.__getitem__, 'foo')
30
31@@ -221,6 +223,7 @@
32 self.assertFalse(os.path.exists(path+'.old'), 'there is a .old file!')
33 self.assertFalse(os.path.exists(path+'.new'), 'there is a .new file!')
34
35+ @skipIfOS('win32', 'Skipped because code is deprecated on Windows.')
36 def test_custom_unpickle(self):
37 """Test the _pickle and _unpikle methods."""
38 self.mktemp('my_shelf')
39
40=== modified file 'tests/syncdaemon/test_vm.py'
41--- tests/syncdaemon/test_vm.py 2011-08-04 16:30:54 +0000
42+++ tests/syncdaemon/test_vm.py 2011-08-05 15:23:53 +0000
43@@ -3844,10 +3844,8 @@
44 os_helper_rename = mocker.replace('ubuntuone.platform.rename')
45 is_string = lambda x: isinstance(x, str)
46 os_helper_rename(MATCH(is_string), MATCH(is_string))
47- mocker.replay()
48- self.md_upgrader._upgrade_names(dirpath, files)
49- mocker.restore()
50- mocker.verify()
51+ with mocker:
52+ self.md_upgrader._upgrade_names(dirpath, files)
53
54 def test_upgrade_metadata_5_no_os_rename(self):
55 """Test that when we upgrade we use the os_helper.rename."""
56@@ -3861,12 +3859,10 @@
57 os_helper_rename = mocker.replace('ubuntuone.platform.rename')
58 is_string = lambda x: isinstance(x, str)
59 os_helper_rename(MATCH(is_string), MATCH(is_string))
60- os_helper_rename(MATCH(is_string), MATCH(is_string))
61+ mocker.count(3)
62 self.md_upgrader._upgrade_metadata_6(6)
63- mocker.replay()
64- self.md_upgrader._upgrade_metadata_5(6)
65- mocker.restore()
66- mocker.verify()
67+ with mocker:
68+ self.md_upgrader._upgrade_metadata_5(6)
69
70
71 class VMTritcaskShelfTests(BaseTwistedTestCase):
72
73=== modified file 'ubuntuone/syncdaemon/file_shelf.py'
74--- ubuntuone/syncdaemon/file_shelf.py 2011-06-24 01:47:50 +0000
75+++ ubuntuone/syncdaemon/file_shelf.py 2011-08-05 15:23:53 +0000
76@@ -26,7 +26,7 @@
77 import errno
78 from collections import deque
79
80-from ubuntuone.platform import open_file
81+from ubuntuone.platform import make_dir, open_file, remove_file, rename, stat_path
82
83 class FileShelf(object, DictMixin):
84 """ File based shelf.
85@@ -52,16 +52,16 @@
86 creates it
87 """
88 try:
89- stat_result = os.stat(path)
90+ stat_result = stat_path(path)
91 # is a regular file?
92 if stat.S_ISREG(stat_result.st_mode):
93 os.unlink(path)
94- os.makedirs(path)
95+ make_dir(path, True)
96 # else, the dir is already there
97 except OSError, e:
98 if e.errno == errno.ENOENT:
99 # the file or dir don't exist
100- os.makedirs(path)
101+ make_dir(path, True)
102 else:
103 raise
104
105@@ -158,20 +158,20 @@
106 self._pickle(value, fh, protocol=2)
107 fh.flush()
108 if os.path.exists(path):
109- os.rename(path, old_path)
110- os.rename(new_path, path)
111+ rename(path, old_path)
112+ rename(new_path, path)
113
114 def __delitem__(self, key):
115 """ delitem backed by the file storage """
116 path = self.key_file(key)
117 try:
118- os.remove(self.key_file(key))
119+ remove_file(self.key_file(key))
120 except OSError:
121 raise KeyError(key)
122 # also delete backup files
123 for path in [path+'.old', path+'.new']:
124 try:
125- os.remove(path)
126+ remove_file(path)
127 except OSError:
128 # ignore any OSError
129 pass

Subscribers

People subscribed via source and target branches