1
# Copyright (C) 2007 Canonical Ltd
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.
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.
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
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
"""Test that all WorkingTree's implement get_file_mtime."""
21
from bzrlib.tests.workingtree_implementations import TestCaseWithWorkingTree
24
class TestGetFileMTime(TestCaseWithWorkingTree):
25
"""Test WorkingTree.get_file_mtime.
27
These are more involved because we need to handle files which have been
31
def make_basic_tree(self):
32
tree = self.make_branch_and_tree('tree')
33
self.build_tree(['tree/one'])
34
tree.add(['one'], ['one-id'])
37
def test_get_file_mtime(self):
38
tree = self.make_basic_tree()
40
st = os.lstat('tree/one')
43
mtime_file_id = tree.get_file_mtime(file_id='one-id')
44
self.assertIsInstance(mtime_file_id, (float, int))
45
self.assertAlmostEqual(st.st_mtime, mtime_file_id)
46
mtime_path = tree.get_file_mtime(file_id='one-id', path='one')
47
self.assertAlmostEqual(mtime_file_id, mtime_path)
51
def test_after_commit(self):
52
"""Committing shouldn't change the mtime."""
53
tree = self.make_basic_tree()
55
st = os.lstat('tree/one')
56
tree.commit('one', rev_id='rev-1')
60
mtime = tree.get_file_mtime(file_id='one-id')
61
self.assertAlmostEqual(st.st_mtime, mtime)
63
mtime = tree.get_file_mtime(file_id='one-id', path='one')
64
self.assertAlmostEqual(st.st_mtime, mtime)
68
def test_get_renamed_time(self):
69
"""We should handle renamed files."""
70
tree = self.make_basic_tree()
72
tree.rename_one('one', 'two')
73
st = os.lstat('tree/two')
77
mtime = tree.get_file_mtime(file_id='one-id')
78
self.assertAlmostEqual(st.st_mtime, mtime)
79
mtime = tree.get_file_mtime(file_id='one-id', path='two')
80
self.assertAlmostEqual(st.st_mtime, mtime)
84
def test_get_renamed_in_subdir_time(self):
85
tree = self.make_branch_and_tree('tree')
86
self.build_tree(['tree/d/', 'tree/d/a'])
87
tree.add(['d', 'd/a'], ['d-id', 'a-id'])
88
tree.commit('1', rev_id='rev-1')
90
tree.rename_one('d', 'e')
92
st = os.lstat('tree/e/a')
95
mtime = tree.get_file_mtime(file_id='a-id')
96
self.assertAlmostEqual(st.st_mtime, mtime)
97
mtime = tree.get_file_mtime(file_id='a-id', path='e/a')
98
self.assertAlmostEqual(st.st_mtime, mtime)