~ubuntu-branches/ubuntu/gutsy/bzr/gutsy

« back to all changes in this revision

Viewing changes to bzrlib/tests/workingtree_implementations/test_get_file_mtime.py

  • Committer: Bazaar Package Importer
  • Author(s): Etienne Goyer
  • Date: 2007-04-27 17:53:49 UTC
  • mfrom: (1.1.23 upstream)
  • Revision ID: james.westby@ubuntu.com-20070427175349-rvowqx994rfuikuu
Tags: 0.16~rc1-0ubuntu1
New upstream development release 

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
16
 
 
17
"""Test that all WorkingTree's implement get_file_mtime."""
 
18
 
 
19
import os
 
20
 
 
21
from bzrlib.tests.workingtree_implementations import TestCaseWithWorkingTree
 
22
 
 
23
 
 
24
class TestGetFileMTime(TestCaseWithWorkingTree):
 
25
    """Test WorkingTree.get_file_mtime.
 
26
 
 
27
    These are more involved because we need to handle files which have been
 
28
    renamed, etc.
 
29
    """
 
30
 
 
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'])
 
35
        return tree
 
36
 
 
37
    def test_get_file_mtime(self):
 
38
        tree = self.make_basic_tree()
 
39
 
 
40
        st = os.lstat('tree/one')
 
41
        tree.lock_read()
 
42
        try:
 
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)
 
48
        finally:
 
49
            tree.unlock()
 
50
 
 
51
    def test_after_commit(self):
 
52
        """Committing shouldn't change the mtime."""
 
53
        tree = self.make_basic_tree()
 
54
 
 
55
        st = os.lstat('tree/one')
 
56
        tree.commit('one', rev_id='rev-1')
 
57
 
 
58
        tree.lock_read()
 
59
        try:
 
60
            mtime = tree.get_file_mtime(file_id='one-id')
 
61
            self.assertAlmostEqual(st.st_mtime, mtime)
 
62
 
 
63
            mtime = tree.get_file_mtime(file_id='one-id', path='one')
 
64
            self.assertAlmostEqual(st.st_mtime, mtime)
 
65
        finally:
 
66
            tree.unlock()
 
67
 
 
68
    def test_get_renamed_time(self):
 
69
        """We should handle renamed files."""
 
70
        tree = self.make_basic_tree()
 
71
 
 
72
        tree.rename_one('one', 'two')
 
73
        st = os.lstat('tree/two')
 
74
 
 
75
        tree.lock_read()
 
76
        try:
 
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)
 
81
        finally:
 
82
            tree.unlock()
 
83
 
 
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')
 
89
 
 
90
        tree.rename_one('d', 'e')
 
91
 
 
92
        st = os.lstat('tree/e/a')
 
93
        tree.lock_read()
 
94
        try:
 
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)
 
99
        finally:
 
100
            tree.unlock()