Merge lp:~dobey/ubuntuone-client/update-from-trunk into lp:ubuntuone-client/stable-3-0
- update-from-trunk
- Merge into stable-3-0
Status: | Merged |
---|---|
Approved by: | dobey |
Approved revision: | no longer in the source branch. |
Merged at revision: | 1169 |
Proposed branch: | lp:~dobey/ubuntuone-client/update-from-trunk |
Merge into: | lp:ubuntuone-client/stable-3-0 |
Diff against target: |
756 lines (+146/-118) 20 files modified
contrib/testing/testcase.py (+4/-5) run-tests.bat (+66/-17) tests/platform/linux/eventlog/test_zg_listener.py (+0/-14) tests/platform/linux/test_filesystem_notifications.py (+0/-1) tests/platform/linux/test_notification.py (+4/-0) tests/platform/linux/test_vm.py (+4/-2) tests/platform/test_filesystem_notifications.py (+0/-1) tests/platform/test_os_helper.py (+3/-6) tests/platform/test_tools.py (+0/-3) tests/syncdaemon/test_action_queue.py (+6/-20) tests/syncdaemon/test_eq_inotify.py (+0/-4) tests/syncdaemon/test_eventqueue.py (+0/-1) tests/syncdaemon/test_localrescan.py (+0/-14) tests/syncdaemon/test_main.py (+1/-0) tests/syncdaemon/test_pathlockingtree.py (+20/-0) tests/syncdaemon/test_vm.py (+0/-7) tests/syncdaemon/test_vm_helper.py (+15/-0) ubuntuone/platform/__init__.py (+0/-1) ubuntuone/syncdaemon/action_queue.py (+22/-20) ubuntuone/syncdaemon/vm_helper.py (+1/-2) |
To merge this branch: | bzr merge lp:~dobey/ubuntuone-client/update-from-trunk |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Natalia Bidart (community) | Approve | ||
Review via email: mp+91166@code.launchpad.net |
Commit message
[Facundo Batista]
- Two small memory improvements, "unblocked cancels" and "better deferred usage in PLT".
[Diego Sarmentero]
- Fixed: Problem trying to create an udf with unicode username (LP: #921703 ).
- Fixed: tests are now not modifying the real user home (LP: #915380).
[Natalia Bidart]
- Skip NotificationTes
[Manuel de la Peña]
- Adds the possibility to skip the lint checks on windows when passing the /skip-lint parameter to run-tests.bat.
Description of the change
- 1169. By Facundo Batista
-
[Facundo Batista]
- Two small memory improvements, "unblocked cancels" and "better deferred usage in PLT".
[Diego Sarmentero]
- Fixed: Problem trying to create an udf with unicode username (LP: #921703 ).
- Fixed: tests are now not modifying the real user home (LP: #915380).[Natalia Bidart]
- Skip NotificationTes
tCase tests (LP: #921574). [Manuel de la Peña]
- Adds the possibility to skip the lint checks on windows when passing the /skip-lint parameter to run-tests.bat.
Preview Diff
1 | === modified file 'contrib/testing/testcase.py' |
2 | --- contrib/testing/testcase.py 2011-12-29 14:44:10 +0000 |
3 | +++ contrib/testing/testcase.py 2012-02-01 20:50:24 +0000 |
4 | @@ -48,6 +48,7 @@ |
5 | tritcask, |
6 | ) |
7 | from ubuntuone.syncdaemon import logger |
8 | +from ubuntuone import platform |
9 | from ubuntuone.platform import ( |
10 | can_write, |
11 | make_dir, |
12 | @@ -377,6 +378,9 @@ |
13 | self.log = logging.getLogger("ubuntuone.SyncDaemon.TEST") |
14 | self.log.info("starting test %s.%s", self.__class__.__name__, |
15 | self._testMethodName) |
16 | + # Patch the user home |
17 | + self.home_dir = self.mktemp('ubuntuonehacker') |
18 | + self.patch(platform, "xdg_home", self.home_dir) |
19 | |
20 | |
21 | class FakeMainTestCase(BaseTwistedTestCase): |
22 | @@ -389,11 +393,6 @@ |
23 | """Setup the infrastructure for the test.""" |
24 | yield super(FakeMainTestCase, self).setUp() |
25 | |
26 | - self.home_dir = self.tmpdir |
27 | - old_home = os.environ['HOME'] |
28 | - os.environ['HOME'] = self.home_dir |
29 | - self.addCleanup(os.environ.__setitem__, 'HOME', old_home) |
30 | - |
31 | self.data_dir = self.mktemp('data_dir') |
32 | self.partials_dir = self.mktemp('partials') |
33 | self.root_dir = self.mktemp('root_dir') |
34 | |
35 | === modified file 'run-tests.bat' |
36 | --- run-tests.bat 2012-01-12 13:06:51 +0000 |
37 | +++ run-tests.bat 2012-02-01 20:50:24 +0000 |
38 | @@ -1,6 +1,4 @@ |
39 | -:: Author: Manuel de la Pena <manuel@canonical.com> |
40 | -:: |
41 | -:: Copyright 2010 Canonical Ltd. |
42 | +:: Copyright 2010-12 Canonical Ltd. |
43 | :: |
44 | :: This program is free software: you can redistribute it and/or modify it |
45 | :: under the terms of the GNU General Public License version 3, as published |
46 | @@ -13,53 +11,104 @@ |
47 | :: |
48 | :: You should have received a copy of the GNU General Public License along |
49 | :: with this program. If not, see <http://www.gnu.org/licenses/>. |
50 | + |
51 | @ECHO off |
52 | + |
53 | :: We could have Python 2.6 or 2.7 on Windows. In order to check availability, |
54 | :: we should first check for 2.7, and run the tests, otherwise fall back to 2.6. |
55 | +SET REGQUERY27="REG QUERY HKLM\Software\Python\PythonCore\2.7\InstallPath /ve" |
56 | +SET REGQUERY2732="REG QUERY HKLM\Software\Wow6432Node\Python\PythonCore\2.7\InstallPath /ve" |
57 | +SET REGQUERY26="REG QUERY HKLM\Software\Python\PythonCore\2.6\InstallPath /ve" |
58 | +SET REGQUERY2632="REG QUERY HKLM\Software\Wow6432Node\Python\PythonCore\2.6\InstallPath /ve" |
59 | SET PYTHONEXEPATH="" |
60 | + |
61 | :: This is very annoying; FOR /F will work differently depending on the output |
62 | :: of reg which is not consistent between OS versions (XP, 7). We must choose |
63 | :: the tokens according to OS version. |
64 | SET PYTHONPATHTOKENS=3 |
65 | VER | FIND "XP" > nul |
66 | -IF %ERRORLEVEL% == 0 SET PYTHONPATHTOKENS=4 |
67 | +IF %ERRORLEVEL% == 0 ( |
68 | + SET PYTHONPATHTOKENS=4) |
69 | + |
70 | ECHO Checking if python 2.7 is in the system |
71 | + |
72 | :: Look for python 2.7 |
73 | -FOR /F "tokens=%PYTHONPATHTOKENS%" %%A IN ('REG QUERY HKLM\Software\Python\PythonCore\2.7\InstallPath /ve') DO @SET PYTHONEXEPATH=%%A |
74 | -IF NOT %PYTHONEXEPATH% == "" GOTO :PYTHONPRESENT |
75 | +FOR /F "tokens=%PYTHONPATHTOKENS%" %%A IN ('%REGQUERY27%') DO @SET PYTHONEXEPATH=%%A |
76 | + |
77 | +IF NOT %PYTHONEXEPATH% == "" ( |
78 | + GOTO :PYTHONPRESENT) |
79 | + |
80 | ECHO Checking if python 2.6 is in the system |
81 | :: we do not have python 2.7 in the system, try to find 2.6 |
82 | -FOR /F "tokens=%PYTHONPATHTOKENS%" %%A IN ('REG QUERY HKLM\Software\Python\PythonCore\2.6\InstallPath /ve') DO @SET PYTHONEXEPATH=%%A |
83 | -IF NOT %PYTHONEXEPATH% == "" GOTO :PYTHONPRESENT |
84 | +FOR /F "tokens=%PYTHONPATHTOKENS%" %%A IN ('%REGQUERY26%') DO @SET PYTHONEXEPATH=%%A |
85 | + |
86 | +IF NOT %PYTHONEXEPATH% == "" ( |
87 | + GOTO :PYTHONPRESENT) |
88 | |
89 | :: we do not have python (2.6 or 2.7) this could hapen in the case that the |
90 | :: user installed the 32version in a 64 machine, let check if the software was installed in the wow key |
91 | |
92 | :: Look for python 2.7 in WoW64 |
93 | ECHO Checking if python 2.7 32 is in the system |
94 | -FOR /F "tokens=%PYTHONPATHTOKENS%" %%A IN ('REG QUERY HKLM\Software\Wow6432Node\Python\PythonCore\2.7\InstallPath /ve') DO @SET PYTHONEXEPATH=%%A |
95 | -IF NOT %PYTHONEXEPATH% == "" GOTO :PYTHONPRESENT |
96 | +FOR /F "tokens=%PYTHONPATHTOKENS%" %%A IN ('%REGQUERY2732%') DO @SET PYTHONEXEPATH=%%A |
97 | + |
98 | +IF NOT %PYTHONEXEPATH% == "" ( |
99 | + GOTO :PYTHONPRESENT) |
100 | + |
101 | ECHO Checking if python 2.6 32 is in the system |
102 | :: we do not have python 2.7 in the system, try to find 2.6 |
103 | -FOR /F "tokens=%PYTHONPATHTOKENS%" %%A IN ('REG QUERY HKLM\Software\Wow6432Node\Python\PythonCore\2.6\InstallPath /ve') DO @SET PYTHONEXEPATH=%%A |
104 | -IF NOT %PYTHONEXEPATH% == "" GOTO :PYTHONPRESENT |
105 | +FOR /F "tokens=%PYTHONPATHTOKENS%" %%A IN ('%REGQUERY2632%') DO @SET PYTHONEXEPATH=%%A |
106 | + |
107 | +IF NOT %PYTHONEXEPATH% == "" ( |
108 | + GOTO :PYTHONPRESENT) |
109 | |
110 | ECHO Please ensure you have python installed |
111 | GOTO :END |
112 | |
113 | |
114 | :PYTHONPRESENT |
115 | + |
116 | +:: throw the first parameter away if is /skip-lint, |
117 | +:: the way we do this is to ensure that /skip-lint |
118 | +:: is the first parameter and copy all the rest in a loop |
119 | +:: the main reason for that is that %* is not affected |
120 | +:: by SHIFT, that is, it allways have all passed parameters |
121 | + |
122 | +SET PARAMS=%* |
123 | +SET SKIPLINT=0 |
124 | +IF "%1" == "/skip-lint" ( |
125 | + SET SKIPLINT=1 |
126 | + GOTO :CLEANPARAMS |
127 | +)ELSE ( |
128 | + GOTO :CONTINUEBATCH) |
129 | +:CLEANPARAMS |
130 | + |
131 | +SHIFT |
132 | +SET PARAMS=%1 |
133 | +:GETREST |
134 | +SHIFT |
135 | +if [%1]==[] ( |
136 | + GOTO CONTINUEBATCH) |
137 | +SET PARAMS=%PARAMS% %1 |
138 | +GOTO GETREST |
139 | +:CONTINUEBATCH |
140 | + |
141 | ECHO Python found, executing the tests... |
142 | COPY windows\clientdefs.py ubuntuone\clientdefs.py |
143 | COPY windows\logging.conf data\logging.conf |
144 | :: execute the tests with a number of ignored linux only modules |
145 | -"%PYTHONEXEPATH%\python.exe" "%PYTHONEXEPATH%\Scripts\u1trial" --reactor=twisted -c -p tests\platform\linux %* tests |
146 | +"%PYTHONEXEPATH%\python.exe" "%PYTHONEXEPATH%\Scripts\u1trial" --reactor=twisted -c -p tests\platform\linux %PARAMS% tests |
147 | + |
148 | +IF %SKIPLINT% == 1 ( |
149 | + ECHO Skipping style checks |
150 | + GOTO :CLEAN) |
151 | "%PYTHONEXEPATH%\python.exe" "%PYTHONEXEPATH%\Scripts\u1lint" |
152 | :: test for style if we can, if pep8 is not present, move to the end |
153 | -IF EXIST "%PYTHONEXEPATH%\Scripts\pep8.exe" |
154 | -"%PYTHONEXEPATH%\Scripts\pep8.exe" --repeat ubuntuone |
155 | -ELSE |
156 | -ECHO Style checks were not done |
157 | +IF EXIST "%PYTHONEXEPATH%\Scripts\pep8.exe" ( |
158 | + "%PYTHONEXEPATH%\Scripts\pep8.exe" --repeat ubuntuone |
159 | +)ELSE ( |
160 | + ECHO Style checks were not done) |
161 | +:CLEAN |
162 | :: Delete the temp folders |
163 | RMDIR /s /q _trial_temp |
164 | RMDIR /s /q .coverage |
165 | |
166 | === modified file 'tests/platform/linux/eventlog/test_zg_listener.py' |
167 | --- tests/platform/linux/eventlog/test_zg_listener.py 2011-11-09 20:03:15 +0000 |
168 | +++ tests/platform/linux/eventlog/test_zg_listener.py 2012-02-01 20:50:24 +0000 |
169 | @@ -368,20 +368,6 @@ |
170 | class ZeitgeistUDFsTestCase(ZeitgeistListenerTestCase): |
171 | """Tests for all UDFs-related zeitgeist events.""" |
172 | |
173 | - @defer.inlineCallbacks |
174 | - def setUp(self): |
175 | - """Initialize this test instance.""" |
176 | - yield super(ZeitgeistUDFsTestCase, self).setUp() |
177 | - self.home_dir = self.mktemp('ubuntuonehacker') |
178 | - self._old_home = os.environ['HOME'] |
179 | - os.environ['HOME'] = self.home_dir |
180 | - |
181 | - @defer.inlineCallbacks |
182 | - def tearDown(self): |
183 | - """Finalize this test instance.""" |
184 | - os.environ['HOME'] = self._old_home |
185 | - yield super(ZeitgeistUDFsTestCase, self).tearDown() |
186 | - |
187 | def _create_udf(self, id, node_id, suggested_path, subscribed=True): |
188 | """Create an UDF and returns it and the volume.""" |
189 | path = get_udf_path(suggested_path) |
190 | |
191 | === modified file 'tests/platform/linux/test_filesystem_notifications.py' |
192 | --- tests/platform/linux/test_filesystem_notifications.py 2011-09-02 16:09:41 +0000 |
193 | +++ tests/platform/linux/test_filesystem_notifications.py 2012-02-01 20:50:24 +0000 |
194 | @@ -99,7 +99,6 @@ |
195 | fsmdir = self.mktemp('fsmdir') |
196 | partials_dir = self.mktemp('partials_dir') |
197 | self.root_dir = self.mktemp('root_dir') |
198 | - self.home_dir = self.mktemp('home_dir') |
199 | self.vm = testcase.FakeVolumeManager(self.root_dir) |
200 | self.tritcask_dir = self.mktemp("tritcask_dir") |
201 | self.db = Tritcask(self.tritcask_dir) |
202 | |
203 | === modified file 'tests/platform/linux/test_notification.py' |
204 | --- tests/platform/linux/test_notification.py 2011-10-27 11:39:43 +0000 |
205 | +++ tests/platform/linux/test_notification.py 2012-02-01 20:50:24 +0000 |
206 | @@ -112,3 +112,7 @@ |
207 | notifier = Notification(FAKE_APP_NAME) |
208 | notifier.send_notification(FAKE_TITLE, FAKE_MESSAGE, append=True) |
209 | notifier.send_notification(FAKE_TITLE, FAKE_APPENDAGE, append=True) |
210 | + |
211 | + |
212 | +NotificationTestCase.skip = "Not working when the GI Notify module is used " \ |
213 | +"(LP: #921574)." |
214 | |
215 | === modified file 'tests/platform/linux/test_vm.py' |
216 | --- tests/platform/linux/test_vm.py 2011-11-17 19:19:08 +0000 |
217 | +++ tests/platform/linux/test_vm.py 2012-02-01 20:50:24 +0000 |
218 | @@ -459,9 +459,11 @@ |
219 | @defer.inlineCallbacks |
220 | def setUp(self): |
221 | yield super(MetadataNewLayoutTests, self).setUp() |
222 | - self.share_md_dir = os.path.join(self.vm_data_dir, 'shares') |
223 | - self.shared_md_dir = os.path.join(self.vm_data_dir, 'shared') |
224 | + # We need to define home_dir here to add 'home' to the path |
225 | + # and avoid crashes between existing paths. |
226 | self.home_dir = os.path.join(self.tmpdir, 'home', 'ubuntuonehacker') |
227 | + self.share_md_dir = os.path.join(self.vm_data_dir, 'shares') |
228 | + self.shared_md_dir = os.path.join(self.vm_data_dir, 'shared') |
229 | self.u1_dir = os.path.join(self.home_dir, os.path.split(self.u1_dir)[1]) |
230 | self.root_dir = self.u1_dir |
231 | self.shares_dir = os.path.join(self.tmpdir, 'shares') |
232 | |
233 | === modified file 'tests/platform/test_filesystem_notifications.py' |
234 | --- tests/platform/test_filesystem_notifications.py 2011-10-21 13:40:09 +0000 |
235 | +++ tests/platform/test_filesystem_notifications.py 2012-02-01 20:50:24 +0000 |
236 | @@ -99,7 +99,6 @@ |
237 | fsmdir = self.mktemp('fsmdir') |
238 | partials_dir = self.mktemp('partials_dir') |
239 | self.root_dir = self.mktemp('root_dir') |
240 | - self.home_dir = self.mktemp('home_dir') |
241 | self.vm = FakeVolumeManager(self.root_dir) |
242 | self.tritcask_dir = self.mktemp("tritcask_dir") |
243 | self.db = Tritcask(self.tritcask_dir) |
244 | |
245 | === modified file 'tests/platform/test_os_helper.py' |
246 | --- tests/platform/test_os_helper.py 2012-01-12 14:01:38 +0000 |
247 | +++ tests/platform/test_os_helper.py 2012-02-01 20:50:24 +0000 |
248 | @@ -28,7 +28,6 @@ |
249 | BaseTwistedTestCase, |
250 | skip_if_win32_and_uses_readonly, |
251 | ) |
252 | -from ubuntuone import platform |
253 | from ubuntuone.platform import ( |
254 | access, |
255 | allow_writes, |
256 | @@ -91,8 +90,6 @@ |
257 | yield super(OSWrapperTests, self).setUp( |
258 | test_dir_name=test_dir_name, test_file_name=test_file_name, |
259 | valid_file_path_builder=valid_file_path_builder) |
260 | - self.my_home = 'myhome' |
261 | - self.patch(platform, "xdg_home", self.my_home) |
262 | # make sure the file exists |
263 | open_file(self.testfile, 'w').close() |
264 | |
265 | @@ -395,21 +392,21 @@ |
266 | """Test the expand_user function with a path like: ~/userpath.""" |
267 | path = os.path.join('~', 'userpath') |
268 | result = expand_user(path) |
269 | - expected = os.path.join(self.my_home, 'userpath') |
270 | + expected = os.path.join(self.home_dir, 'userpath') |
271 | self.assertEqual(expected, result) |
272 | |
273 | def test_expand_user_tilde_and_backslash(self): |
274 | """Test the expand_user function with tilde and backslash.""" |
275 | tilde = '~' + os.path.sep |
276 | result = expand_user(tilde) |
277 | - expected = self.my_home + os.path.sep |
278 | + expected = self.home_dir + os.path.sep |
279 | self.assertEqual(expected, result) |
280 | |
281 | def test_expand_user_only_tilde(self): |
282 | """Test the expand_user function returns with only tilde input.""" |
283 | tilde = '~' |
284 | result = expand_user(tilde) |
285 | - self.assertEqual(self.my_home, result) |
286 | + self.assertEqual(self.home_dir, result) |
287 | self.assertFalse(result.endswith(os.path.sep)) |
288 | |
289 | def test_expand_user_fails_if_not_bytes(self): |
290 | |
291 | === modified file 'tests/platform/test_tools.py' |
292 | --- tests/platform/test_tools.py 2012-01-11 21:40:51 +0000 |
293 | +++ tests/platform/test_tools.py 2012-02-01 20:50:24 +0000 |
294 | @@ -31,7 +31,6 @@ |
295 | states, |
296 | volume_manager, |
297 | ) |
298 | -from ubuntuone import platform |
299 | from ubuntuone.platform import tools |
300 | from tests.platform import IPCTestCase |
301 | |
302 | @@ -533,7 +532,6 @@ |
303 | @defer.inlineCallbacks |
304 | def test_create_folder(self): |
305 | """Test for Folders.create.""" |
306 | - self.patch(platform, 'xdg_home', self.home_dir) |
307 | path = os.path.join(self.home_dir, u'ñoño') |
308 | volume_id = 'volume_id' |
309 | node_id = 'node_id' |
310 | @@ -552,7 +550,6 @@ |
311 | @defer.inlineCallbacks |
312 | def test_create_folder_error(self): |
313 | """Test for Folders.create with error.""" |
314 | - self.patch(platform, 'xdg_home', self.home_dir) |
315 | path = os.path.join(self.home_dir, u'ñoño') |
316 | |
317 | def create_udf(path, name, marker): |
318 | |
319 | === modified file 'tests/syncdaemon/test_action_queue.py' |
320 | --- tests/syncdaemon/test_action_queue.py 2011-12-20 10:58:38 +0000 |
321 | +++ tests/syncdaemon/test_action_queue.py 2012-02-01 20:50:24 +0000 |
322 | @@ -219,8 +219,8 @@ |
323 | """Init.""" |
324 | yield super(BasicTestCase, self).setUp() |
325 | |
326 | + self.home = self.home_dir |
327 | self.root = self.mktemp('root') |
328 | - self.home = self.mktemp('home') |
329 | self.data = self.mktemp('data') |
330 | self.shares = self.mktemp('shares') |
331 | self.partials = self.mktemp('partials') |
332 | @@ -1744,11 +1744,11 @@ |
333 | called = [] |
334 | self.cmd.run = lambda: called.append(True) |
335 | d = defer.Deferred() |
336 | + d.addErrback(lambda _: None) |
337 | self.cmd._acquire_pathlock = lambda: d |
338 | |
339 | self.cmd.go() |
340 | self.cmd.cancel() |
341 | - d.callback(None) |
342 | |
343 | self.assertFalse(called) |
344 | |
345 | @@ -1757,15 +1757,15 @@ |
346 | called = [] |
347 | self.cmd.run = lambda: called.append(1) |
348 | d = defer.Deferred() |
349 | + d.addErrback(lambda _: called.append(2)) |
350 | self.cmd._acquire_pathlock = lambda: d |
351 | |
352 | self.cmd.go() |
353 | self.cmd.cancel() |
354 | - d.callback(lambda: called.append(2)) |
355 | |
356 | self.assertEqual(called, [2]) |
357 | self.assertTrue(self.handler.check_debug( |
358 | - 'releasing the pathlock because of cancelled')) |
359 | + 'command not run because of cancelled')) |
360 | |
361 | def test_go_run_ok_release_pathlock(self): |
362 | """If run went ok, release the pathlock.""" |
363 | @@ -2532,18 +2532,6 @@ |
364 | """Init.""" |
365 | yield super(FilterEventsTestCase, self).setUp() |
366 | self.vm = self.main.vm |
367 | - self.old_home = os.environ.get('HOME', None) |
368 | - os.environ['HOME'] = self.home |
369 | - |
370 | - @defer.inlineCallbacks |
371 | - def tearDown(self): |
372 | - """Clean up.""" |
373 | - if self.old_home is None: |
374 | - os.environ.pop('HOME') |
375 | - else: |
376 | - os.environ['HOME'] = self.old_home |
377 | - |
378 | - yield super(FilterEventsTestCase, self).tearDown() |
379 | |
380 | |
381 | class ChangePublicAccessTests(ConnectedBaseTestCase): |
382 | @@ -5409,22 +5397,20 @@ |
383 | self._check_finished_ok() |
384 | |
385 | def test_cancel_while_pathclocked(self): |
386 | - """Cancel the command while running.""" |
387 | + """Cancel the command while pathlocked.""" |
388 | # monkeypatch _run to flag called and test "while running" |
389 | called = [] |
390 | self.cmd.run = lambda: called.append('should not') |
391 | |
392 | # monkeypatch to test "while waiting pathlock" |
393 | d = defer.Deferred() |
394 | + d.addErrback(lambda _: called.append(1)) |
395 | self.cmd._acquire_pathlock = lambda: d |
396 | |
397 | # let the command go, and cancel in the middle |
398 | self.cmd.go() |
399 | self.cmd.cancel() |
400 | |
401 | - # unlock the pathlock |
402 | - d.callback(lambda: called.append(1)) |
403 | - |
404 | # all check |
405 | self.assertEqual(called, [1]) |
406 | self._check_finished_ok() |
407 | |
408 | === modified file 'tests/syncdaemon/test_eq_inotify.py' |
409 | --- tests/syncdaemon/test_eq_inotify.py 2011-11-30 19:54:45 +0000 |
410 | +++ tests/syncdaemon/test_eq_inotify.py 2012-02-01 20:50:24 +0000 |
411 | @@ -34,7 +34,6 @@ |
412 | skip_if_win32_missing_fs_event, |
413 | ) |
414 | from tests.syncdaemon.test_eventqueue import BaseEQTestCase |
415 | -from ubuntuone import platform |
416 | from ubuntuone.platform import ( |
417 | make_link, |
418 | make_dir, |
419 | @@ -646,7 +645,6 @@ |
420 | """Init.""" |
421 | yield super(AncestorsUDFTestCase, self).setUp() |
422 | self._deferred = defer.Deferred() |
423 | - self.home_dir = self.mktemp('ubuntuonehacker') |
424 | self.root_dir = self.mktemp('root_dir') |
425 | self.data_dir = self.mktemp('data_dir') |
426 | self.shares_dir = self.mktemp('shares_dir') |
427 | @@ -661,8 +659,6 @@ |
428 | self.eq.subscribe(self.listener) |
429 | self.addCleanup(self.eq.unsubscribe, self.listener) |
430 | |
431 | - self.patch(platform, 'xdg_home', self.home_dir) |
432 | - |
433 | # create UDF |
434 | suggested_path = u'~/Documents/Reading/Books/PDFs' |
435 | udf_id, node_id = 'udf_id', 'node_id' |
436 | |
437 | === modified file 'tests/syncdaemon/test_eventqueue.py' |
438 | --- tests/syncdaemon/test_eventqueue.py 2011-08-17 13:11:06 +0000 |
439 | +++ tests/syncdaemon/test_eventqueue.py 2012-02-01 20:50:24 +0000 |
440 | @@ -43,7 +43,6 @@ |
441 | self.fsmdir = self.mktemp('fsmdir') |
442 | self.partials_dir = self.mktemp('partials_dir') |
443 | self.root_dir = self.mktemp('root_dir') |
444 | - self.home_dir = self.mktemp('home_dir') |
445 | self.vm = FakeVolumeManager(self.root_dir) |
446 | self.db = tritcask.Tritcask(self.mktemp('tritcask')) |
447 | self.addCleanup(self.db.shutdown) |
448 | |
449 | === modified file 'tests/syncdaemon/test_localrescan.py' |
450 | --- tests/syncdaemon/test_localrescan.py 2011-11-30 19:54:45 +0000 |
451 | +++ tests/syncdaemon/test_localrescan.py 2012-02-01 20:50:24 +0000 |
452 | @@ -33,7 +33,6 @@ |
453 | FakeVolumeManager, |
454 | skip_if_win32_and_uses_readonly, |
455 | ) |
456 | -from ubuntuone import platform |
457 | from ubuntuone.platform import ( |
458 | make_dir, |
459 | make_link, |
460 | @@ -123,16 +122,12 @@ |
461 | def setUp(self): |
462 | """ Setup the test """ |
463 | yield super(BaseTestCase, self).setUp() |
464 | - self.home_dir = self.mktemp('ubuntuonehacker') |
465 | self.shares_dir = self.mktemp('shares') |
466 | usrdir = self.mktemp("usrdir") |
467 | self.fsmdir = self.mktemp("fsmdir") |
468 | self.partials_dir = self.mktemp("partials") |
469 | self.tritcask_dir = self.mktemp("tritcask") |
470 | |
471 | - # set the home for the tests |
472 | - self.patch(platform, 'xdg_home', self.home_dir) |
473 | - |
474 | self.vm = FakeVolumeManager(usrdir) |
475 | self.db = Tritcask(self.tritcask_dir) |
476 | self.addCleanup(self.db.shutdown) |
477 | @@ -371,8 +366,6 @@ |
478 | """Init.""" |
479 | yield super(VolumeTestCase, self).setUp() |
480 | |
481 | - self.patch(platform, 'xdg_home', self.home_dir) |
482 | - |
483 | self.lr = local_rescan.LocalRescan(self.vm, self.fsm, self.eq, self.aq) |
484 | |
485 | self.volumes = [] |
486 | @@ -2016,11 +2009,6 @@ |
487 | """Test what happens with volume roots left in a bad state last time.""" |
488 | |
489 | @defer.inlineCallbacks |
490 | - def setUp(self): |
491 | - yield super(RootBadStateTests, self).setUp() |
492 | - self.patch(platform, 'xdg_home', self.home_dir) |
493 | - |
494 | - @defer.inlineCallbacks |
495 | def _test_it(self, volume): |
496 | """Run the bad state test for a specific volume.""" |
497 | path = volume.path |
498 | @@ -2257,8 +2245,6 @@ |
499 | |
500 | self.lr = local_rescan.LocalRescan(self.vm, self.fsm, self.eq, self.aq) |
501 | |
502 | - self.patch(platform, 'xdg_home', self.home_dir) |
503 | - |
504 | # create UDF |
505 | suggested_path = u'~/Documents/Reading/Books/PDFs' |
506 | udf_id, node_id = 'udf_id', 'node_id' |
507 | |
508 | === modified file 'tests/syncdaemon/test_main.py' |
509 | --- tests/syncdaemon/test_main.py 2012-01-03 12:40:04 +0000 |
510 | +++ tests/syncdaemon/test_main.py 2012-02-01 20:50:24 +0000 |
511 | @@ -264,6 +264,7 @@ |
512 | |
513 | def test_get_homedir(self): |
514 | """The get_homedir returns the root dir.""" |
515 | + self.patch(main_mod, "xdg_home", self.home_dir) |
516 | expected = expand_user('~') |
517 | main = self.build_main() |
518 | self.assertEqual(main.get_homedir(), expected) |
519 | |
520 | === modified file 'tests/syncdaemon/test_pathlockingtree.py' |
521 | --- tests/syncdaemon/test_pathlockingtree.py 2011-10-27 11:39:43 +0000 |
522 | +++ tests/syncdaemon/test_pathlockingtree.py 2012-02-01 20:50:24 +0000 |
523 | @@ -260,6 +260,21 @@ |
524 | releases.pop(0)() |
525 | yield d3 |
526 | |
527 | + def test_deferred_can_be_cancelled(self): |
528 | + """The path locking can be cancelled without harm.""" |
529 | + releases = [] |
530 | + d1 = self.plt.acquire("path") |
531 | + d1.addCallback(lambda _: releases.append(1)) |
532 | + d2 = self.plt.acquire("path") |
533 | + d2.addCallback(lambda _: releases.append(2)) |
534 | + |
535 | + # the first one should not be locked |
536 | + self.assertEqual(releases, [1]) |
537 | + |
538 | + # cancel the second deferred, but it still needs to pass ok |
539 | + d2.cancel() |
540 | + self.assertEqual(releases, [1, 2]) |
541 | + |
542 | @defer.inlineCallbacks |
543 | def test_same_path_having_parent(self): |
544 | """Lock with parent having just the parent.""" |
545 | @@ -560,7 +575,10 @@ |
546 | self.plt = PathLockingTree() |
547 | |
548 | self.handler = MementoHandler() |
549 | + self.plt.logger.setLevel(logging.DEBUG) |
550 | + self.plt.logger.propagate = False |
551 | self.plt.logger.addHandler(self.handler) |
552 | + self.addCleanup(self.plt.logger.removeHandler, self.handler) |
553 | |
554 | @defer.inlineCallbacks |
555 | def test_logger_can_be_given(self): |
556 | @@ -568,6 +586,8 @@ |
557 | logger = logging.getLogger("ubuntuone.SyncDaemon.Test") |
558 | handler = MementoHandler() |
559 | logger.addHandler(handler) |
560 | + logger.setLevel(logging.DEBUG) |
561 | + logger.propagate = False |
562 | |
563 | # acquire and test |
564 | release = yield self.plt.acquire('path', logger=logger) |
565 | |
566 | === modified file 'tests/syncdaemon/test_vm.py' |
567 | --- tests/syncdaemon/test_vm.py 2011-12-12 19:32:25 +0000 |
568 | +++ tests/syncdaemon/test_vm.py 2012-02-01 20:50:24 +0000 |
569 | @@ -91,14 +91,12 @@ |
570 | self.log = logging.getLogger("ubuntuone.SyncDaemon.TEST") |
571 | self.log.info("starting test %s.%s", self.__class__.__name__, |
572 | self._testMethodName) |
573 | - self.home_dir = self.mktemp('ubuntuonehacker') |
574 | self.root_dir = self.mktemp(os.path.join('ubuntuonehacker', 'root_dir')) |
575 | self.data_dir = self.mktemp('data_dir') |
576 | self.shares_dir = self.mktemp('shares_dir') |
577 | self.partials_dir = self.mktemp('partials_dir') |
578 | self.main = FakeMain(self.root_dir, self.shares_dir, |
579 | self.data_dir, self.partials_dir) |
580 | - self.patch(platform, 'xdg_home', self.home_dir) |
581 | |
582 | self.watches = set() # keep track of added watches |
583 | |
584 | @@ -124,10 +122,6 @@ |
585 | self.vm.log.addHandler(self.handler) |
586 | self.addCleanup(self.vm.log.removeHandler, self.handler) |
587 | |
588 | - old_home = os.environ['HOME'] |
589 | - os.environ['HOME'] = self.home_dir |
590 | - self.addCleanup(os.environ.__setitem__, 'HOME', old_home) |
591 | - |
592 | @defer.inlineCallbacks |
593 | def tearDown(self): |
594 | """ cleanup main and remove the temp dir """ |
595 | @@ -3742,7 +3736,6 @@ |
596 | def setUp(self): |
597 | """Create some directories.""" |
598 | yield super(MetadataTestCase, self).setUp() |
599 | - self.home_dir = self.mktemp('ubuntuonehacker') |
600 | self.root_dir = self.mktemp( |
601 | os.path.join('ubuntuonehacker', 'Ubuntu One')) |
602 | self.data_dir = os.path.join(self.tmpdir, 'data_dir') |
603 | |
604 | === modified file 'tests/syncdaemon/test_vm_helper.py' |
605 | --- tests/syncdaemon/test_vm_helper.py 2012-01-04 13:18:50 +0000 |
606 | +++ tests/syncdaemon/test_vm_helper.py 2012-02-01 20:50:24 +0000 |
607 | @@ -66,6 +66,21 @@ |
608 | in_home = os.path.join(self.home_dir, 'foo') |
609 | self.assertEqual(u'~/foo', get_udf_suggested_path(in_home)) |
610 | |
611 | + def test_get_udf_suggested_path_expand_user_decode(self): |
612 | + """Test for get_udf_suggested_path.""" |
613 | + home = os.path.join(self.home_dir.decode('utf-8'), |
614 | + u'雄鳥お人好し ñandú') |
615 | + |
616 | + def fake_expand_user(path): |
617 | + """Fake expand_user.""" |
618 | + return home.encode('utf-8') |
619 | + |
620 | + self.patch(vm_helper, 'expand_user', fake_expand_user) |
621 | + in_home = os.path.join(home, u'ñoño') |
622 | + in_home = in_home.encode('utf-8') |
623 | + suggested_path = get_udf_suggested_path(in_home) |
624 | + self.assertEqual(u'~/ñoño', suggested_path) |
625 | + |
626 | def test_get_udf_suggested_path_long_path(self): |
627 | """Test for get_udf_suggested_path.""" |
628 | deep_in_home = os.path.join(self.home_dir, 'docs', 'foo', 'bar') |
629 | |
630 | === modified file 'ubuntuone/platform/__init__.py' |
631 | --- ubuntuone/platform/__init__.py 2011-12-08 20:56:10 +0000 |
632 | +++ ubuntuone/platform/__init__.py 2012-02-01 20:50:24 +0000 |
633 | @@ -37,7 +37,6 @@ |
634 | |
635 | def expand_user(path): |
636 | """Fix Python expanduser for weird chars in windows.""" |
637 | - # Receives bytes, returns unicode |
638 | assert isinstance(path, str) |
639 | try: |
640 | path.decode('utf-8') |
641 | |
642 | === modified file 'ubuntuone/syncdaemon/action_queue.py' |
643 | --- ubuntuone/syncdaemon/action_queue.py 2011-12-19 17:10:39 +0000 |
644 | +++ ubuntuone/syncdaemon/action_queue.py 2012-02-01 20:50:24 +0000 |
645 | @@ -161,9 +161,18 @@ |
646 | logger.debug("pathlock acquiring on %s (on_parent=%s, on_children=%s);" |
647 | " wait for: %d", elements, on_parent, |
648 | on_children, len(wait_for)) |
649 | + |
650 | + relfunc = partial(self._release, deferred, elements, logger) |
651 | + if not wait_for: |
652 | + return defer.succeed(relfunc) |
653 | + if len(wait_for) == 1: |
654 | + d = defer.Deferred() |
655 | + wait_for[0].chainDeferred(d) |
656 | + d.addBoth(lambda _: relfunc) |
657 | + return d |
658 | + # we need to wait for several |
659 | deferred_list = defer.DeferredList(wait_for) |
660 | - deferred_list.addCallback(lambda _: partial(self._release, deferred, |
661 | - elements, logger)) |
662 | + deferred_list.addBoth(lambda _: relfunc) |
663 | return deferred_list |
664 | |
665 | def _release(self, deferred, elements, logger): |
666 | @@ -357,18 +366,6 @@ |
667 | LoggingStorageClient.connectionLost(self, reason) |
668 | |
669 | |
670 | -class Marker(str): |
671 | - """A uuid4-based marker class.""" |
672 | - |
673 | - implements(IMarker) |
674 | - |
675 | - def __new__(cls): |
676 | - return super(Marker, cls).__new__(cls, uuid.uuid4()) |
677 | - |
678 | - def __repr__(self): |
679 | - return "marker:%s" % self |
680 | - |
681 | - |
682 | class ZipQueue(object): |
683 | """A queue of files to be compressed for upload. |
684 | |
685 | @@ -1175,9 +1172,9 @@ |
686 | is_runnable = True |
687 | uniqueness = None |
688 | |
689 | - __slots__ = ('_queue', 'running', 'pathlock_release', 'log', |
690 | + __slots__ = ('_queue', 'running', 'pathlock_release', 'pathlock_deferred', |
691 | 'markers_resolved_deferred', 'action_queue', 'cancelled', |
692 | - 'running_deferred') |
693 | + 'running_deferred', 'log') |
694 | |
695 | def __init__(self, request_queue): |
696 | """Initialize a command instance.""" |
697 | @@ -1187,6 +1184,7 @@ |
698 | self.log = None |
699 | self.markers_resolved_deferred = defer.Deferred() |
700 | self.pathlock_release = None |
701 | + self.pathlock_deferred = None |
702 | self.cancelled = False |
703 | self.running_deferred = None |
704 | |
705 | @@ -1296,11 +1294,13 @@ |
706 | |
707 | # acquire the pathlock; note that the pathlock_release may be None |
708 | # if the command didn't need to acquire any pathlock |
709 | - self.pathlock_release = yield self._acquire_pathlock() |
710 | + self.pathlock_deferred = self._acquire_pathlock() |
711 | + self.pathlock_release = yield self.pathlock_deferred |
712 | + self.pathlock_deferred = None |
713 | if self.cancelled: |
714 | + self.log.debug('command not run because of cancelled') |
715 | if self.pathlock_release is not None: |
716 | - self.log.debug('releasing the pathlock because of cancelled') |
717 | - self.pathlock_release() |
718 | + self.pathlock_release = self.pathlock_release() |
719 | return |
720 | |
721 | try: |
722 | @@ -1310,7 +1310,7 @@ |
723 | "(traceback follows)", exc) |
724 | finally: |
725 | if self.pathlock_release is not None: |
726 | - self.pathlock_release() |
727 | + self.pathlock_release = self.pathlock_release() |
728 | |
729 | @defer.inlineCallbacks |
730 | def run(self): |
731 | @@ -1394,6 +1394,8 @@ |
732 | self.cancelled = True |
733 | self.log.debug('cancelled') |
734 | self.action_queue.conditions_locker.cancel_command(self) |
735 | + if self.pathlock_deferred is not None: |
736 | + self.pathlock_deferred.cancel() |
737 | self.cleanup() |
738 | self.finish() |
739 | return True |
740 | |
741 | === modified file 'ubuntuone/syncdaemon/vm_helper.py' |
742 | --- ubuntuone/syncdaemon/vm_helper.py 2011-11-17 18:38:41 +0000 |
743 | +++ ubuntuone/syncdaemon/vm_helper.py 2012-02-01 20:50:24 +0000 |
744 | @@ -89,12 +89,11 @@ |
745 | """ |
746 | if not path: |
747 | raise ValueError("no path specified") |
748 | - |
749 | assert isinstance(path, str) |
750 | |
751 | path = path.decode('utf8') |
752 | |
753 | - user_home = expand_user('~') |
754 | + user_home = expand_user('~').decode('utf-8') |
755 | start_list = os.path.abspath(user_home).split(os.path.sep) |
756 | path_list = os.path.abspath(path).split(os.path.sep) |
757 |
Looks good!