~ubuntu-branches/ubuntu/karmic/pypy/karmic

« back to all changes in this revision

Viewing changes to py/path/svn/testing/test_wccommand.py

  • Committer: Bazaar Package Importer
  • Author(s): Alexandre Fayolle
  • Date: 2007-04-13 09:33:09 UTC
  • Revision ID: james.westby@ubuntu.com-20070413093309-yoojh4jcoocu2krz
Tags: upstream-1.0.0
ImportĀ upstreamĀ versionĀ 1.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
import py
 
2
from py.__.path.svn.testing.svntestbase import CommonSvnTests, getrepowc
 
3
from py.__.path.svn.wccommand import InfoSvnWCCommand
 
4
from py.__.path.svn.wccommand import parse_wcinfotime
 
5
from py.__.path.svn import svncommon
 
6
 
 
7
 
 
8
if py.path.local.sysfind('svn') is None:
 
9
    py.test.skip("cannot test py.path.svn, 'svn' binary not found")
 
10
 
 
11
 
 
12
class TestWCSvnCommandPath(CommonSvnTests):
 
13
 
 
14
    def setup_class(cls): 
 
15
        repo, cls.root = getrepowc()
 
16
 
 
17
    def test_move_file(self):  # overrides base class
 
18
        try:
 
19
            super(TestWCSvnCommandPath, self).test_move_file()
 
20
        finally:
 
21
            self.root.revert(rec=1)
 
22
 
 
23
    def test_move_directory(self): # overrides base class
 
24
        try:
 
25
            super(TestWCSvnCommandPath, self).test_move_directory()
 
26
        finally:
 
27
            self.root.revert(rec=1)
 
28
 
 
29
    def test_status_attributes_simple(self):
 
30
        def assert_nochange(p):
 
31
            s = p.status()
 
32
            assert not s.modified
 
33
            assert not s.prop_modified
 
34
            assert not s.added
 
35
            assert not s.deleted
 
36
 
 
37
        dpath = self.root.join('sampledir')
 
38
        assert_nochange(self.root.join('sampledir'))
 
39
        assert_nochange(self.root.join('samplefile'))
 
40
 
 
41
    def test_status_added(self):
 
42
        nf = self.root.join('newfile')
 
43
        nf.write('hello')
 
44
        nf.add()
 
45
        try:
 
46
            s = nf.status()
 
47
            assert s.added
 
48
            assert not s.modified
 
49
            assert not s.prop_modified
 
50
        finally:
 
51
            nf.revert()
 
52
 
 
53
    def test_status_change(self):
 
54
        nf = self.root.join('samplefile')
 
55
        try:
 
56
            nf.write(nf.read() + 'change')
 
57
            s = nf.status()
 
58
            assert not s.added
 
59
            assert s.modified
 
60
            assert not s.prop_modified
 
61
        finally:
 
62
            nf.revert()
 
63
 
 
64
    def test_status_added_ondirectory(self):
 
65
        sampledir = self.root.join('sampledir')
 
66
        try:
 
67
            t2 = sampledir.mkdir('t2')
 
68
            t1 = t2.join('t1')
 
69
            t1.write('test')
 
70
            t1.add()
 
71
            s = sampledir.status(rec=1)
 
72
            # Comparing just the file names, because paths are unpredictable
 
73
            # on Windows. (long vs. 8.3 paths)
 
74
            assert t1.basename in [item.basename for item in s.added]
 
75
            assert t2.basename in [item.basename for item in s.added]
 
76
        finally:
 
77
            t2.revert(rec=1)
 
78
            t2.localpath.remove(rec=1)
 
79
 
 
80
    def test_status_unknown(self):
 
81
        t1 = self.root.join('un1')
 
82
        try:
 
83
            t1.write('test')
 
84
            s = self.root.status()
 
85
            # Comparing just the file names, because paths are unpredictable
 
86
            # on Windows. (long vs. 8.3 paths)
 
87
            assert t1.basename in [item.basename for item in s.unknown]
 
88
        finally:
 
89
            t1.localpath.remove()
 
90
 
 
91
    def test_status_unchanged(self):
 
92
        r = self.root
 
93
        s = self.root.status(rec=1)
 
94
        # Comparing just the file names, because paths are unpredictable
 
95
        # on Windows. (long vs. 8.3 paths)
 
96
        assert r.join('samplefile').basename in [item.basename 
 
97
                                                    for item in s.unchanged]
 
98
        assert r.join('sampledir').basename in [item.basename 
 
99
                                                    for item in s.unchanged]
 
100
        assert r.join('sampledir/otherfile').basename in [item.basename 
 
101
                                                    for item in s.unchanged]
 
102
 
 
103
    def test_status_update(self):
 
104
        r = self.root
 
105
        try:
 
106
            r.update(rev=1)
 
107
            s = r.status(updates=1, rec=1)
 
108
            # Comparing just the file names, because paths are unpredictable
 
109
            # on Windows. (long vs. 8.3 paths)
 
110
            assert r.join('anotherfile').basename in [item.basename for 
 
111
                                                    item in s.update_available]
 
112
            #assert len(s.update_available) == 1
 
113
        finally:
 
114
            r.update()
 
115
 
 
116
    def test_diff(self):
 
117
        p = self.root / 'anotherfile'
 
118
        out = p.diff(rev=2)
 
119
        assert out.find('hello') != -1
 
120
 
 
121
    def test_blame(self):
 
122
        p = self.root.join('samplepickle')
 
123
        lines = p.blame()
 
124
        assert sum([l[0] for l in lines]) == len(lines)
 
125
        for l1, l2 in zip(p.readlines(), [l[2] for l in lines]):
 
126
            assert l1 == l2
 
127
        assert [l[1] for l in lines] == ['hpk'] * len(lines)
 
128
        p = self.root.join('samplefile')
 
129
        lines = p.blame()
 
130
        assert sum([l[0] for l in lines]) == len(lines)
 
131
        for l1, l2 in zip(p.readlines(), [l[2] for l in lines]):
 
132
            assert l1 == l2
 
133
        assert [l[1] for l in lines] == ['hpk'] * len(lines)
 
134
 
 
135
    def test_join_abs(self):
 
136
        s = str(self.root.localpath)
 
137
        n = self.root.join(s, abs=1)
 
138
        assert self.root == n
 
139
 
 
140
    def test_join_abs2(self):
 
141
        assert self.root.join('samplefile', abs=1) == self.root.join('samplefile')
 
142
 
 
143
    def test_str_gives_localpath(self):
 
144
        assert str(self.root) == str(self.root.localpath)
 
145
 
 
146
    def test_versioned(self):
 
147
        assert self.root.check(versioned=1)
 
148
        # TODO: Why does my copy of svn think .svn is versioned?
 
149
        #assert self.root.join('.svn').check(versioned=0) 
 
150
        assert self.root.join('samplefile').check(versioned=1)
 
151
        assert not self.root.join('notexisting').check(versioned=1)
 
152
        notexisting = self.root.join('hello').localpath
 
153
        try:
 
154
            notexisting.write("")
 
155
            assert self.root.join('hello').check(versioned=0)
 
156
        finally:
 
157
            notexisting.remove()
 
158
 
 
159
    def test_properties(self):
 
160
        try:
 
161
            self.root.propset('gaga', 'this')
 
162
            assert self.root.propget('gaga') == 'this'
 
163
            # Comparing just the file names, because paths are unpredictable
 
164
            # on Windows. (long vs. 8.3 paths)
 
165
            assert self.root.basename in [item.basename for item in 
 
166
                                        self.root.status().prop_modified]
 
167
            assert 'gaga' in self.root.proplist()
 
168
            assert self.root.proplist()['gaga'] == 'this'
 
169
 
 
170
        finally:
 
171
            self.root.propdel('gaga')
 
172
 
 
173
    def test_proplist_recursive(self):
 
174
        s = self.root.join('samplefile')
 
175
        s.propset('gugu', 'that')
 
176
        try:
 
177
            p = self.root.proplist(rec=1)
 
178
            # Comparing just the file names, because paths are unpredictable
 
179
            # on Windows. (long vs. 8.3 paths)
 
180
            assert (self.root / 'samplefile').basename in [item.basename 
 
181
                                                                for item in p]
 
182
        finally:
 
183
            s.propdel('gugu')
 
184
 
 
185
    def test_long_properties(self):
 
186
        value = """
 
187
        vadm:posix : root root 0100755
 
188
        Properties on 'chroot/dns/var/bind/db.net.xots':
 
189
                """
 
190
        try:
 
191
            self.root.propset('gaga', value)
 
192
            backvalue = self.root.propget('gaga')
 
193
            assert backvalue == value
 
194
            #assert len(backvalue.split('\n')) == 1
 
195
        finally:
 
196
            self.root.propdel('gaga')
 
197
 
 
198
 
 
199
    def test_ensure(self):
 
200
        newpath = self.root.ensure('a', 'b', 'c')
 
201
        try:
 
202
            assert newpath.check(exists=1, versioned=1)
 
203
            newpath.write("hello")
 
204
            newpath.ensure()
 
205
            assert newpath.read() == "hello"
 
206
        finally:
 
207
            self.root.join('a').remove(force=1)
 
208
 
 
209
    def test_not_versioned(self):
 
210
        p = self.root.localpath.mkdir('whatever')
 
211
        f = self.root.localpath.ensure('testcreatedfile')
 
212
        try:
 
213
            assert self.root.join('whatever').check(versioned=0)
 
214
            assert self.root.join('testcreatedfile').check(versioned=0)
 
215
            assert not self.root.join('testcreatedfile').check(versioned=1)
 
216
        finally:
 
217
            p.remove(rec=1)
 
218
            f.remove()
 
219
 
 
220
    #def test_log(self):
 
221
    #   l = self.root.log()
 
222
    #   assert len(l) == 3  # might need to be upped if more tests are added
 
223
 
 
224
class XTestWCSvnCommandPathSpecial:
 
225
 
 
226
    rooturl = 'http://codespeak.net/svn/py.path/trunk/dist/py.path/test/data'
 
227
    #def test_update_none_rev(self):
 
228
    #    path = tmpdir.join('checkouttest')
 
229
    #    wcpath = newpath(xsvnwc=str(path), url=self.rooturl)
 
230
    #    try:
 
231
    #        wcpath.checkout(rev=2100)
 
232
    #        wcpath.update()
 
233
    #        assert wcpath.info().rev > 2100
 
234
    #    finally:
 
235
    #        wcpath.localpath.remove(rec=1)
 
236
 
 
237
def test_parse_wcinfotime():
 
238
    assert (parse_wcinfotime('2006-05-30 20:45:26 +0200 (Tue, 30 May 2006)') ==
 
239
            1149021926)
 
240
    assert (parse_wcinfotime('2003-10-27 20:43:14 +0100 (Mon, 27 Oct 2003)') ==
 
241
            1067287394)
 
242
 
 
243
class TestInfoSvnWCCommand:
 
244
 
 
245
    def test_svn_1_2(self):
 
246
        output = """
 
247
        Path: test_wccommand.py
 
248
        Name: test_wccommand.py
 
249
        URL: http://codespeak.net/svn/py/dist/py/path/svn/wccommand.py
 
250
        Repository UUID: fd0d7bf2-dfb6-0310-8d31-b7ecfe96aada
 
251
        Revision: 28137
 
252
        Node Kind: file
 
253
        Schedule: normal
 
254
        Last Changed Author: jan
 
255
        Last Changed Rev: 27939
 
256
        Last Changed Date: 2006-05-30 20:45:26 +0200 (Tue, 30 May 2006)
 
257
        Text Last Updated: 2006-06-01 00:42:53 +0200 (Thu, 01 Jun 2006)
 
258
        Properties Last Updated: 2006-05-23 11:54:59 +0200 (Tue, 23 May 2006)
 
259
        Checksum: 357e44880e5d80157cc5fbc3ce9822e3
 
260
        """
 
261
        path = py.magic.autopath().dirpath().chdir()
 
262
        info = InfoSvnWCCommand(output)
 
263
        path.chdir()
 
264
        assert info.last_author == 'jan'
 
265
        assert info.kind == 'file'
 
266
        assert info.mtime == 1149021926.0
 
267
        assert info.url == 'http://codespeak.net/svn/py/dist/py/path/svn/wccommand.py'
 
268
        assert info.time == 1149021926000000.0
 
269
        assert info.rev == 28137
 
270
 
 
271
 
 
272
    def test_svn_1_3(self):
 
273
        output = """
 
274
        Path: test_wccommand.py
 
275
        Name: test_wccommand.py
 
276
        URL: http://codespeak.net/svn/py/dist/py/path/svn/wccommand.py
 
277
        Repository Root: http://codespeak.net/svn
 
278
        Repository UUID: fd0d7bf2-dfb6-0310-8d31-b7ecfe96aada
 
279
        Revision: 28124
 
280
        Node Kind: file
 
281
        Schedule: normal
 
282
        Last Changed Author: jan
 
283
        Last Changed Rev: 27939
 
284
        Last Changed Date: 2006-05-30 20:45:26 +0200 (Tue, 30 May 2006)
 
285
        Text Last Updated: 2006-06-02 23:46:11 +0200 (Fri, 02 Jun 2006)
 
286
        Properties Last Updated: 2006-06-02 23:45:28 +0200 (Fri, 02 Jun 2006)
 
287
        Checksum: 357e44880e5d80157cc5fbc3ce9822e3
 
288
        """
 
289
        path = py.magic.autopath().dirpath().chdir()
 
290
        info = InfoSvnWCCommand(output)
 
291
        path.chdir()
 
292
        assert info.last_author == 'jan'
 
293
        assert info.kind == 'file'
 
294
        assert info.mtime == 1149021926.0
 
295
        assert info.url == 'http://codespeak.net/svn/py/dist/py/path/svn/wccommand.py'
 
296
        assert info.rev == 28124
 
297
        assert info.time == 1149021926000000.0
 
298
 
 
299
class TestWCSvnCommandPathEmptyRepo(object):
 
300
 
 
301
    def setup_class(cls):
 
302
        repo = py.test.ensuretemp("emptyrepo")
 
303
        wcdir = py.test.ensuretemp("emptywc")
 
304
        py.process.cmdexec('svnadmin create "%s"' %
 
305
                svncommon._escape_helper(repo))
 
306
        wc = py.path.svnwc(wcdir)
 
307
        repopath = repo.strpath
 
308
        if py.std.sys.platform.startswith('win32'):
 
309
            # strange win problem, paths become something like file:///c:\\foo
 
310
            repourl = 'file:///%s' % (repopath.replace('\\', '/'),)
 
311
        else:
 
312
            repourl = 'file://%s' % (repopath,)
 
313
        wc.checkout(url=repourl)
 
314
        cls.wc = wc
 
315
 
 
316
    def test_info(self):
 
317
        self.wc.info().rev = 0
 
318
 
 
319
def test_characters_at():
 
320
    py.test.raises(ValueError, "py.path.svnwc('/tmp/@@@:')")
 
321
 
 
322
def test_characters_tilde():
 
323
    py.path.svnwc('/tmp/test~')