Rev 2406: Add some tests for get_file_mtime, and clean up others. in http://bzr.arbash-meinel.com/branches/bzr/0.16-dev/get_file_mtime_tests

John Arbash Meinel john at arbash-meinel.com
Wed Apr 11 23:15:15 BST 2007


At http://bzr.arbash-meinel.com/branches/bzr/0.16-dev/get_file_mtime_tests

------------------------------------------------------------
revno: 2406
revision-id: john at arbash-meinel.com-20070411221459-h6l619a85w7nimfc
parent: pqm at pqm.ubuntu.com-20070411044855-b83c4dc6fd093648
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: get_file_mtime_tests
timestamp: Wed 2007-04-11 17:14:59 -0500
message:
  Add some tests for get_file_mtime, and clean up others.
added:
  bzrlib/tests/workingtree_implementations/test_get_file_mtime.py test_get_file_mtime.-20070411212918-dhentj8gk0hsu54z-1
modified:
  bzrlib/tests/tree_implementations/test_get_file_mtime.py test_get_file_mtime.-20070301003805-kjkpwfp4whbm39o1-1
  bzrlib/tests/workingtree_implementations/__init__.py __init__.py-20060203003124-b2aa5aca21a8bfad
-------------- next part --------------
=== added file 'bzrlib/tests/workingtree_implementations/test_get_file_mtime.py'
--- a/bzrlib/tests/workingtree_implementations/test_get_file_mtime.py	1970-01-01 00:00:00 +0000
+++ b/bzrlib/tests/workingtree_implementations/test_get_file_mtime.py	2007-04-11 22:14:59 +0000
@@ -0,0 +1,100 @@
+# Copyright (C) 2007 Canonical Ltd
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+
+"""Test that all WorkingTree's implement get_file_mtime."""
+
+import os
+
+from bzrlib.tests.workingtree_implementations import TestCaseWithWorkingTree
+
+
+class TestGetFileMTime(TestCaseWithWorkingTree):
+    """Test WorkingTree.get_file_mtime.
+
+    These are more involved because we need to handle files which have been
+    renamed, etc.
+    """
+
+    def make_basic_tree(self):
+        tree = self.make_branch_and_tree('tree')
+        self.build_tree(['tree/one'])
+        tree.add(['one'], ['one-id'])
+        return tree
+
+    def test_get_file_mtime(self):
+        tree = self.make_basic_tree()
+
+        st = os.lstat('tree/one')
+        tree.lock_read()
+        try:
+            mtime_file_id = tree.get_file_mtime(file_id='one-id')
+            self.assertIsInstance(mtime_file_id, (float, int))
+            self.assertAlmostEqual(st.st_mtime, mtime_file_id)
+            mtime_path = tree.get_file_mtime(file_id='one-id', path='one')
+            self.assertAlmostEqual(mtime_file_id, mtime_path)
+        finally:
+            tree.unlock()
+
+    def test_after_commit(self):
+        """Committing shouldn't change the mtime."""
+        tree = self.make_basic_tree()
+
+        st = os.lstat('tree/one')
+        tree.commit('one', rev_id='rev-1')
+
+        tree.lock_read()
+        try:
+            mtime = tree.get_file_mtime(file_id='one-id')
+            self.assertAlmostEqual(st.st_mtime, mtime)
+
+            mtime = tree.get_file_mtime(file_id='one-id', path='one')
+            self.assertAlmostEqual(st.st_mtime, mtime)
+        finally:
+            tree.unlock()
+
+    def test_get_renamed_time(self):
+        """We should handle renamed files."""
+        tree = self.make_basic_tree()
+
+        tree.rename_one('one', 'two')
+        st = os.lstat('tree/two')
+
+        tree.lock_read()
+        try:
+            mtime = tree.get_file_mtime(file_id='one-id')
+            self.assertAlmostEqual(st.st_mtime, mtime)
+            mtime = tree.get_file_mtime(file_id='one-id', path='two')
+            self.assertAlmostEqual(st.st_mtime, mtime)
+        finally:
+            tree.unlock()
+
+    def test_get_renamed_in_subdir_time(self):
+        tree = self.make_branch_and_tree('tree')
+        self.build_tree(['tree/d/', 'tree/d/a'])
+        tree.add(['d', 'd/a'], ['d-id', 'a-id'])
+        tree.commit('1', rev_id='rev-1')
+
+        tree.rename_one('e', 'e')
+
+        st = os.lstat('tree/e/a')
+        tree.lock_read()
+        try:
+            mtime = tree.get_file_mtime(file_id='a-id')
+            self.assertAlmostEqual(st.st_mtime, mtime)
+            mtime = tree.get_file_mtime(file_id='a-id', path='e/a')
+            self.assertAlmostEqual(st.st_mtime, mtime)
+        finally:
+            tree.unlock()

=== modified file 'bzrlib/tests/tree_implementations/test_get_file_mtime.py'
--- a/bzrlib/tests/tree_implementations/test_get_file_mtime.py	2007-03-01 00:47:45 +0000
+++ b/bzrlib/tests/tree_implementations/test_get_file_mtime.py	2007-04-11 22:14:59 +0000
@@ -29,7 +29,7 @@
         tree.add(['one'], ['one-id'])
         return self._convert_tree(tree)
 
-    def test_get_symlink_target(self):
+    def test_get_file_mtime(self):
         now = time.time()
         tree = self.get_basic_tree()
         tree.lock_read()

=== modified file 'bzrlib/tests/workingtree_implementations/__init__.py'
--- a/bzrlib/tests/workingtree_implementations/__init__.py	2007-03-11 23:05:49 +0000
+++ b/bzrlib/tests/workingtree_implementations/__init__.py	2007-04-11 22:14:59 +0000
@@ -58,6 +58,7 @@
         'bzrlib.tests.workingtree_implementations.test_commit',
         'bzrlib.tests.workingtree_implementations.test_executable',
         'bzrlib.tests.workingtree_implementations.test_flush',
+        'bzrlib.tests.workingtree_implementations.test_get_file_mtime',
         'bzrlib.tests.workingtree_implementations.test_get_parent_ids',
         'bzrlib.tests.workingtree_implementations.test_inv',
         'bzrlib.tests.workingtree_implementations.test_is_control_filename',



More information about the bazaar-commits mailing list