~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_export.py

  • Committer: John Arbash Meinel
  • Date: 2010-08-13 19:08:57 UTC
  • mto: (5050.17.7 2.2)
  • mto: This revision was merged to the branch mainline in revision 5379.
  • Revision ID: john@arbash-meinel.com-20100813190857-mvzwnimrxvm0zimp
Lots of documentation updates.

We had a lot of http links pointing to the old domain. They should
all now be properly updated to the new domain. (only bazaar-vcs.org
entry left is for pqm, which seems to still reside at the old url.)

Also removed one 'TODO' doc entry about switching to binary xdelta, since
we basically did just that with groupcompress.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2009 Canonical Ltd
 
1
# Copyright (C) 2009, 2010 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
15
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
17
import os
18
 
 
 
18
import time
19
19
 
20
20
from bzrlib import (
 
21
    errors,
21
22
    export,
22
 
    osutils,
23
23
    tests,
24
24
    )
25
25
 
42
42
        wt.add(['link'])
43
43
        export.export(wt, 'target', format="dir")
44
44
        self.failUnlessExists('target/link')
 
45
 
 
46
    def test_dir_export_to_existing_empty_dir_success(self):
 
47
        self.build_tree(['source/', 'source/a', 'source/b/', 'source/b/c'])
 
48
        wt = self.make_branch_and_tree('source')
 
49
        wt.add(['a', 'b', 'b/c'])
 
50
        wt.commit('1')
 
51
        self.build_tree(['target/'])
 
52
        export.export(wt, 'target', format="dir")
 
53
        self.failUnlessExists('target/a')
 
54
        self.failUnlessExists('target/b')
 
55
        self.failUnlessExists('target/b/c')
 
56
 
 
57
    def test_dir_export_to_existing_nonempty_dir_fail(self):
 
58
        self.build_tree(['source/', 'source/a', 'source/b/', 'source/b/c'])
 
59
        wt = self.make_branch_and_tree('source')
 
60
        wt.add(['a', 'b', 'b/c'])
 
61
        wt.commit('1')
 
62
        self.build_tree(['target/', 'target/foo'])
 
63
        self.assertRaises(errors.BzrError, export.export, wt, 'target', format="dir")
 
64
 
 
65
    def test_dir_export_existing_single_file(self):
 
66
        self.build_tree(['dir1/', 'dir1/dir2/', 'dir1/first', 'dir1/dir2/second'])
 
67
        wtree = self.make_branch_and_tree('dir1')
 
68
        wtree.add(['dir2', 'first', 'dir2/second'])
 
69
        wtree.commit('1')
 
70
        export.export(wtree, 'target1', format='dir', subdir='first')
 
71
        self.failUnlessExists('target1/first')
 
72
        export.export(wtree, 'target2', format='dir', subdir='dir2/second')
 
73
        self.failUnlessExists('target2/second')
 
74
        
 
75
    def test_dir_export_files_same_timestamp(self):
 
76
        builder = self.make_branch_builder('source')
 
77
        builder.start_series()
 
78
        builder.build_snapshot(None, None, [
 
79
            ('add', ('', 'root-id', 'directory', '')),
 
80
            ('add', ('a', 'a-id', 'file', 'content\n'))])
 
81
        builder.build_snapshot(None, None, [
 
82
            ('add', ('b', 'b-id', 'file', 'content\n'))])
 
83
        builder.finish_series()
 
84
        b = builder.get_branch()
 
85
        b.lock_read()
 
86
        self.addCleanup(b.unlock)
 
87
        tree = b.basis_tree()
 
88
        orig_iter_files_bytes = tree.iter_files_bytes
 
89
        # Make iter_files_bytes slower, so we provoke mtime skew
 
90
        def iter_files_bytes(to_fetch):
 
91
            for thing in orig_iter_files_bytes(to_fetch):
 
92
                yield thing
 
93
                time.sleep(1)
 
94
        tree.iter_files_bytes = iter_files_bytes
 
95
        export.export(tree, 'target', format='dir')
 
96
        t = self.get_transport('target')
 
97
        st_a = t.stat('a')
 
98
        st_b = t.stat('b')
 
99
        # All files must be given the same mtime.
 
100
        self.assertEqual(st_a.st_mtime, st_b.st_mtime)
 
101
 
 
102
    def test_dir_export_files_per_file_timestamps(self):
 
103
        builder = self.make_branch_builder('source')
 
104
        builder.start_series()
 
105
        # Earliest allowable date on FAT32 filesystems is 1980-01-01
 
106
        a_time = time.mktime((1999, 12, 12, 0, 0, 0, 0, 0, 0))
 
107
        b_time = time.mktime((1980, 01, 01, 0, 0, 0, 0, 0, 0))
 
108
        builder.build_snapshot(None, None, [
 
109
            ('add', ('', 'root-id', 'directory', '')),
 
110
            ('add', ('a', 'a-id', 'file', 'content\n'))],
 
111
            timestamp=a_time)
 
112
        builder.build_snapshot(None, None, [
 
113
            ('add', ('b', 'b-id', 'file', 'content\n'))],
 
114
            timestamp=b_time)
 
115
        builder.finish_series()
 
116
        b = builder.get_branch()
 
117
        b.lock_read()
 
118
        self.addCleanup(b.unlock)
 
119
        tree = b.basis_tree()
 
120
        export.export(tree, 'target', format='dir', per_file_timestamps=True)
 
121
        t = self.get_transport('target')
 
122
        self.assertEqual(a_time, t.stat('a').st_mtime)
 
123
        self.assertEqual(b_time, t.stat('b').st_mtime)