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 |
||
6153.1.1
by Jelmer Vernooij
Raise FileTimestampUnavailable. |
21 |
from bzrlib import errors |
4523.1.4
by Martin Pool
Rename remaining *_implementations tests |
22 |
from bzrlib.tests.per_workingtree import TestCaseWithWorkingTree |
2405.3.1
by John Arbash Meinel
Add some tests for get_file_mtime, and clean up others. |
23 |
|
24 |
||
25 |
class TestGetFileMTime(TestCaseWithWorkingTree): |
|
26 |
"""Test WorkingTree.get_file_mtime.
|
|
27 |
||
28 |
These are more involved because we need to handle files which have been
|
|
29 |
renamed, etc.
|
|
30 |
"""
|
|
31 |
||
32 |
def make_basic_tree(self): |
|
33 |
tree = self.make_branch_and_tree('tree') |
|
34 |
self.build_tree(['tree/one']) |
|
35 |
tree.add(['one'], ['one-id']) |
|
36 |
return tree |
|
37 |
||
38 |
def test_get_file_mtime(self): |
|
39 |
tree = self.make_basic_tree() |
|
40 |
||
41 |
st = os.lstat('tree/one') |
|
42 |
tree.lock_read() |
|
43 |
try: |
|
44 |
mtime_file_id = tree.get_file_mtime(file_id='one-id') |
|
45 |
self.assertIsInstance(mtime_file_id, (float, int)) |
|
46 |
self.assertAlmostEqual(st.st_mtime, mtime_file_id) |
|
47 |
mtime_path = tree.get_file_mtime(file_id='one-id', path='one') |
|
48 |
self.assertAlmostEqual(mtime_file_id, mtime_path) |
|
49 |
finally: |
|
50 |
tree.unlock() |
|
51 |
||
52 |
def test_after_commit(self): |
|
53 |
"""Committing shouldn't change the mtime."""
|
|
54 |
tree = self.make_basic_tree() |
|
55 |
||
56 |
st = os.lstat('tree/one') |
|
57 |
tree.commit('one', rev_id='rev-1') |
|
58 |
||
59 |
tree.lock_read() |
|
60 |
try: |
|
61 |
mtime = tree.get_file_mtime(file_id='one-id') |
|
62 |
self.assertAlmostEqual(st.st_mtime, mtime) |
|
63 |
||
64 |
mtime = tree.get_file_mtime(file_id='one-id', path='one') |
|
65 |
self.assertAlmostEqual(st.st_mtime, mtime) |
|
66 |
finally: |
|
67 |
tree.unlock() |
|
68 |
||
69 |
def test_get_renamed_time(self): |
|
70 |
"""We should handle renamed files."""
|
|
71 |
tree = self.make_basic_tree() |
|
72 |
||
73 |
tree.rename_one('one', 'two') |
|
74 |
st = os.lstat('tree/two') |
|
75 |
||
76 |
tree.lock_read() |
|
77 |
try: |
|
78 |
mtime = tree.get_file_mtime(file_id='one-id') |
|
79 |
self.assertAlmostEqual(st.st_mtime, mtime) |
|
80 |
mtime = tree.get_file_mtime(file_id='one-id', path='two') |
|
81 |
self.assertAlmostEqual(st.st_mtime, mtime) |
|
82 |
finally: |
|
83 |
tree.unlock() |
|
84 |
||
85 |
def test_get_renamed_in_subdir_time(self): |
|
86 |
tree = self.make_branch_and_tree('tree') |
|
87 |
self.build_tree(['tree/d/', 'tree/d/a']) |
|
88 |
tree.add(['d', 'd/a'], ['d-id', 'a-id']) |
|
89 |
tree.commit('1', rev_id='rev-1') |
|
90 |
||
2405.3.2
by John Arbash Meinel
Fix one test. |
91 |
tree.rename_one('d', 'e') |
2405.3.1
by John Arbash Meinel
Add some tests for get_file_mtime, and clean up others. |
92 |
|
93 |
st = os.lstat('tree/e/a') |
|
94 |
tree.lock_read() |
|
95 |
try: |
|
96 |
mtime = tree.get_file_mtime(file_id='a-id') |
|
97 |
self.assertAlmostEqual(st.st_mtime, mtime) |
|
98 |
mtime = tree.get_file_mtime(file_id='a-id', path='e/a') |
|
99 |
self.assertAlmostEqual(st.st_mtime, mtime) |
|
100 |
finally: |
|
101 |
tree.unlock() |
|
6153.1.1
by Jelmer Vernooij
Raise FileTimestampUnavailable. |
102 |
|
6153.1.2
by Jelmer Vernooij
Fix typo. |
103 |
def test_missing(self): |
6153.1.1
by Jelmer Vernooij
Raise FileTimestampUnavailable. |
104 |
tree = self.make_basic_tree() |
105 |
||
106 |
os.remove('tree/one') |
|
107 |
tree.lock_read() |
|
108 |
try: |
|
109 |
self.assertRaises(errors.FileTimestampUnavailable, |
|
110 |
tree.get_file_mtime, file_id='one-id') |
|
111 |
finally: |
|
112 |
tree.unlock() |
|
6153.1.2
by Jelmer Vernooij
Fix typo. |
113 |