bzr branch
http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
|
2405.3.1
by John Arbash Meinel
Add some tests for get_file_mtime, and clean up others. |
1 |
# Copyright (C) 2007 Canonical Ltd
|
2 |
#
|
|
3 |
# This program is free software; you can redistribute it and/or modify
|
|
4 |
# it under the terms of the GNU General Public License as published by
|
|
5 |
# the Free Software Foundation; either version 2 of the License, or
|
|
6 |
# (at your option) any later version.
|
|
7 |
#
|
|
8 |
# This program is distributed in the hope that it will be useful,
|
|
9 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
10 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
11 |
# GNU General Public License for more details.
|
|
12 |
#
|
|
13 |
# You should have received a copy of the GNU General Public License
|
|
14 |
# along with this program; if not, write to the Free Software
|
|
|
4183.7.1
by Sabin Iacob
update FSF mailing address |
15 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
2405.3.1
by John Arbash Meinel
Add some tests for get_file_mtime, and clean up others. |
16 |
|
17 |
"""Test that all WorkingTree's implement get_file_mtime."""
|
|
18 |
||
19 |
import os |
|
20 |
||
|
6622.1.34
by Jelmer Vernooij
Rename brzlib => breezy. |
21 |
from breezy import errors |
|
6731.1.1
by Jelmer Vernooij
Move FileTimestampUnavailable to breezy.tree. |
22 |
from breezy.tree import FileTimestampUnavailable |
|
6622.1.34
by Jelmer Vernooij
Rename brzlib => breezy. |
23 |
from breezy.tests.per_workingtree import TestCaseWithWorkingTree |
|
2405.3.1
by John Arbash Meinel
Add some tests for get_file_mtime, and clean up others. |
24 |
|
25 |
||
26 |
class TestGetFileMTime(TestCaseWithWorkingTree): |
|
27 |
"""Test WorkingTree.get_file_mtime. |
|
28 |
||
29 |
These are more involved because we need to handle files which have been
|
|
30 |
renamed, etc.
|
|
31 |
"""
|
|
32 |
||
33 |
def make_basic_tree(self): |
|
34 |
tree = self.make_branch_and_tree('tree') |
|
35 |
self.build_tree(['tree/one']) |
|
|
6793.5.1
by Jelmer Vernooij
Hardcode fileids in fewer places. |
36 |
tree.add(['one']) |
|
2405.3.1
by John Arbash Meinel
Add some tests for get_file_mtime, and clean up others. |
37 |
return tree |
38 |
||
39 |
def test_get_file_mtime(self): |
|
40 |
tree = self.make_basic_tree() |
|
41 |
||
42 |
st = os.lstat('tree/one') |
|
|
7141.7.1
by Jelmer Vernooij
Get rid of file_ids in most of Tree. |
43 |
with tree.lock_read(): |
|
6809.4.5
by Jelmer Vernooij
Swap arguments for get_file_*. |
44 |
mtime_file_id = tree.get_file_mtime('one') |
|
2405.3.1
by John Arbash Meinel
Add some tests for get_file_mtime, and clean up others. |
45 |
self.assertIsInstance(mtime_file_id, (float, int)) |
46 |
self.assertAlmostEqual(st.st_mtime, mtime_file_id) |
|
47 |
||
48 |
def test_after_commit(self): |
|
49 |
"""Committing shouldn't change the mtime.""" |
|
50 |
tree = self.make_basic_tree() |
|
51 |
||
52 |
st = os.lstat('tree/one') |
|
|
6829.2.1
by Jelmer Vernooij
Avoid passing in file_ids/revision_ids in a few more places. |
53 |
tree.commit('one') |
|
2405.3.1
by John Arbash Meinel
Add some tests for get_file_mtime, and clean up others. |
54 |
|
|
7141.7.1
by Jelmer Vernooij
Get rid of file_ids in most of Tree. |
55 |
with tree.lock_read(): |
|
6809.4.5
by Jelmer Vernooij
Swap arguments for get_file_*. |
56 |
mtime = tree.get_file_mtime('one') |
|
2405.3.1
by John Arbash Meinel
Add some tests for get_file_mtime, and clean up others. |
57 |
self.assertAlmostEqual(st.st_mtime, mtime) |
58 |
||
59 |
def test_get_renamed_time(self): |
|
60 |
"""We should handle renamed files.""" |
|
61 |
tree = self.make_basic_tree() |
|
62 |
||
63 |
tree.rename_one('one', 'two') |
|
64 |
st = os.lstat('tree/two') |
|
65 |
||
|
7141.7.1
by Jelmer Vernooij
Get rid of file_ids in most of Tree. |
66 |
with tree.lock_read(): |
|
6809.4.7
by Jelmer Vernooij
Swap arguments for get_symlink_target and kind/stored_kind. |
67 |
mtime = tree.get_file_mtime('two') |
|
2405.3.1
by John Arbash Meinel
Add some tests for get_file_mtime, and clean up others. |
68 |
self.assertAlmostEqual(st.st_mtime, mtime) |
69 |
||
70 |
def test_get_renamed_in_subdir_time(self): |
|
71 |
tree = self.make_branch_and_tree('tree') |
|
72 |
self.build_tree(['tree/d/', 'tree/d/a']) |
|
|
6844.1.1
by Jelmer Vernooij
Many more foreign branch fixes. |
73 |
tree.add(['d', 'd/a']) |
74 |
a_id = tree.path2id('d/a') |
|
|
6852.2.1
by Jelmer Vernooij
Allow formats to not support custom revision properties. |
75 |
rev_1 = tree.commit('1') |
|
2405.3.1
by John Arbash Meinel
Add some tests for get_file_mtime, and clean up others. |
76 |
|
|
2405.3.2
by John Arbash Meinel
Fix one test. |
77 |
tree.rename_one('d', 'e') |
|
2405.3.1
by John Arbash Meinel
Add some tests for get_file_mtime, and clean up others. |
78 |
|
79 |
st = os.lstat('tree/e/a') |
|
|
7141.7.1
by Jelmer Vernooij
Get rid of file_ids in most of Tree. |
80 |
with tree.lock_read(): |
|
6809.4.5
by Jelmer Vernooij
Swap arguments for get_file_*. |
81 |
mtime = tree.get_file_mtime('e/a') |
|
2405.3.1
by John Arbash Meinel
Add some tests for get_file_mtime, and clean up others. |
82 |
self.assertAlmostEqual(st.st_mtime, mtime) |
|
6153.1.1
by Jelmer Vernooij
Raise FileTimestampUnavailable. |
83 |
|
|
6153.1.2
by Jelmer Vernooij
Fix typo. |
84 |
def test_missing(self): |
|
6153.1.1
by Jelmer Vernooij
Raise FileTimestampUnavailable. |
85 |
tree = self.make_basic_tree() |
86 |
||
87 |
os.remove('tree/one') |
|
|
6852.3.1
by Jelmer Vernooij
add Tree.is_versioned. |
88 |
with tree.lock_read(): |
|
6809.4.8
by Jelmer Vernooij
Fix some test failures. |
89 |
self.assertRaises(errors.NoSuchFile, tree.get_file_mtime, 'one') |