/brz/remove-bazaar

To get this branch, use:
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()
6793.5.1 by Jelmer Vernooij
Hardcode fileids in fewer places.
41
        one_id = tree.path2id('one')
2405.3.1 by John Arbash Meinel
Add some tests for get_file_mtime, and clean up others.
42
43
        st = os.lstat('tree/one')
44
        tree.lock_read()
45
        try:
6809.4.5 by Jelmer Vernooij
Swap arguments for get_file_*.
46
            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.
47
            self.assertIsInstance(mtime_file_id, (float, int))
48
            self.assertAlmostEqual(st.st_mtime, mtime_file_id)
6809.4.5 by Jelmer Vernooij
Swap arguments for get_file_*.
49
            mtime_path = tree.get_file_mtime('one', file_id=one_id)
2405.3.1 by John Arbash Meinel
Add some tests for get_file_mtime, and clean up others.
50
            self.assertAlmostEqual(mtime_file_id, mtime_path)
51
        finally:
52
            tree.unlock()
53
54
    def test_after_commit(self):
55
        """Committing shouldn't change the mtime."""
56
        tree = self.make_basic_tree()
6793.5.1 by Jelmer Vernooij
Hardcode fileids in fewer places.
57
        one_id = tree.path2id('one')
2405.3.1 by John Arbash Meinel
Add some tests for get_file_mtime, and clean up others.
58
59
        st = os.lstat('tree/one')
60
        tree.commit('one', rev_id='rev-1')
61
62
        tree.lock_read()
63
        try:
6809.4.5 by Jelmer Vernooij
Swap arguments for get_file_*.
64
            mtime = tree.get_file_mtime('one')
2405.3.1 by John Arbash Meinel
Add some tests for get_file_mtime, and clean up others.
65
            self.assertAlmostEqual(st.st_mtime, mtime)
66
6809.4.5 by Jelmer Vernooij
Swap arguments for get_file_*.
67
            mtime = tree.get_file_mtime('one', one_id)
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
        finally:
70
            tree.unlock()
71
72
    def test_get_renamed_time(self):
73
        """We should handle renamed files."""
74
        tree = self.make_basic_tree()
6793.5.1 by Jelmer Vernooij
Hardcode fileids in fewer places.
75
        one_id = tree.path2id('one')
2405.3.1 by John Arbash Meinel
Add some tests for get_file_mtime, and clean up others.
76
77
        tree.rename_one('one', 'two')
78
        st = os.lstat('tree/two')
79
80
        tree.lock_read()
81
        try:
6809.4.7 by Jelmer Vernooij
Swap arguments for get_symlink_target and kind/stored_kind.
82
            mtime = tree.get_file_mtime('two')
2405.3.1 by John Arbash Meinel
Add some tests for get_file_mtime, and clean up others.
83
            self.assertAlmostEqual(st.st_mtime, mtime)
6809.4.5 by Jelmer Vernooij
Swap arguments for get_file_*.
84
            mtime = tree.get_file_mtime('two', one_id)
2405.3.1 by John Arbash Meinel
Add some tests for get_file_mtime, and clean up others.
85
            self.assertAlmostEqual(st.st_mtime, mtime)
86
        finally:
87
            tree.unlock()
88
89
    def test_get_renamed_in_subdir_time(self):
90
        tree = self.make_branch_and_tree('tree')
6793.5.1 by Jelmer Vernooij
Hardcode fileids in fewer places.
91
        one_id = tree.path2id('one')
2405.3.1 by John Arbash Meinel
Add some tests for get_file_mtime, and clean up others.
92
        self.build_tree(['tree/d/', 'tree/d/a'])
93
        tree.add(['d', 'd/a'], ['d-id', 'a-id'])
94
        tree.commit('1', rev_id='rev-1')
95
2405.3.2 by John Arbash Meinel
Fix one test.
96
        tree.rename_one('d', 'e')
2405.3.1 by John Arbash Meinel
Add some tests for get_file_mtime, and clean up others.
97
98
        st = os.lstat('tree/e/a')
99
        tree.lock_read()
100
        try:
6809.4.5 by Jelmer Vernooij
Swap arguments for get_file_*.
101
            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.
102
            self.assertAlmostEqual(st.st_mtime, mtime)
6809.4.5 by Jelmer Vernooij
Swap arguments for get_file_*.
103
            mtime = tree.get_file_mtime('e/a', 'a-id')
2405.3.1 by John Arbash Meinel
Add some tests for get_file_mtime, and clean up others.
104
            self.assertAlmostEqual(st.st_mtime, mtime)
105
        finally:
106
            tree.unlock()
6153.1.1 by Jelmer Vernooij
Raise FileTimestampUnavailable.
107
6153.1.2 by Jelmer Vernooij
Fix typo.
108
    def test_missing(self):
6153.1.1 by Jelmer Vernooij
Raise FileTimestampUnavailable.
109
        tree = self.make_basic_tree()
6793.5.1 by Jelmer Vernooij
Hardcode fileids in fewer places.
110
        one_id = tree.path2id('one')
6153.1.1 by Jelmer Vernooij
Raise FileTimestampUnavailable.
111
112
        os.remove('tree/one')
113
        tree.lock_read()
114
        try:
6809.4.8 by Jelmer Vernooij
Fix some test failures.
115
            self.assertRaises(errors.NoSuchFile, tree.get_file_mtime, 'one')
6153.1.1 by Jelmer Vernooij
Raise FileTimestampUnavailable.
116
        finally:
117
            tree.unlock()
6153.1.2 by Jelmer Vernooij
Fix typo.
118