~crunch.io/ubuntu/precise/codespeak-lib/unstable

« back to all changes in this revision

Viewing changes to testing/path/common.py

  • Committer: Bazaar Package Importer
  • Author(s): Chris Lamb
  • Date: 2010-08-01 16:24:01 UTC
  • mfrom: (1.1.8 upstream)
  • Revision ID: james.westby@ubuntu.com-20100801162401-g37v49d1p148alpm
Tags: 1.3.3-1
* New upstream release.
* Bump Standards-Version to 3.9.1.
* Fix typo in py.test manpage.
* Prefer Breaks: over Conflicts.

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
    def test_join(self, path1):
18
18
        p = path1.join('sampledir')
19
 
        strp = str(p) 
20
 
        assert strp.endswith('sampledir') 
21
 
        assert strp.startswith(str(path1)) 
 
19
        strp = str(p)
 
20
        assert strp.endswith('sampledir')
 
21
        assert strp.startswith(str(path1))
22
22
 
23
23
    def test_join_normalized(self, path1):
24
24
        newpath = path1.join(path1.sep+'sampledir')
25
 
        strp = str(newpath) 
26
 
        assert strp.endswith('sampledir') 
27
 
        assert strp.startswith(str(path1)) 
 
25
        strp = str(newpath)
 
26
        assert strp.endswith('sampledir')
 
27
        assert strp.startswith(str(path1))
28
28
        newpath = path1.join((path1.sep*2) + 'sampledir')
29
 
        strp = str(newpath) 
30
 
        assert strp.endswith('sampledir') 
31
 
        assert strp.startswith(str(path1)) 
 
29
        strp = str(newpath)
 
30
        assert strp.endswith('sampledir')
 
31
        assert strp.startswith(str(path1))
32
32
 
33
33
    def test_join_noargs(self, path1):
34
34
        newpath = path1.join()
117
117
    def test_bestrelpath(self, path1):
118
118
        curdir = path1
119
119
        sep = curdir.sep
 
120
        s = curdir.bestrelpath(curdir)
 
121
        assert s == "."
120
122
        s = curdir.bestrelpath(curdir.join("hello", "world"))
121
123
        assert s == "hello" + sep + "world"
122
124
 
123
125
        s = curdir.bestrelpath(curdir.dirpath().join("sister"))
124
126
        assert s == ".." + sep + "sister"
125
127
        assert curdir.bestrelpath(curdir.dirpath()) == ".."
126
 
        
 
128
 
127
129
        assert curdir.bestrelpath("hello") == "hello"
128
130
 
129
131
    def test_relto_not_relative(self, path1):
224
226
        newpath = path1.join('samplefile.py')
225
227
        dirname, purebasename, basename, ext = newpath._getbyspec(
226
228
            'dirname,purebasename,basename,ext')
227
 
        assert str(path1).endswith(dirname) # be careful with win32 'drive' 
 
229
        assert str(path1).endswith(dirname) # be careful with win32 'drive'
228
230
        assert purebasename == 'samplefile'
229
231
        assert basename == 'samplefile.py'
230
232
        assert ext == '.py'
278
280
        url = path1.join("samplefile")
279
281
        assert url.mtime() > 0
280
282
 
281
 
    def test_relto_wrong_type(self, path1): 
 
283
    def test_relto_wrong_type(self, path1):
282
284
        py.test.raises(TypeError, "path1.relto(42)")
283
285
 
284
286
    def test_visit_filesonly(self, path1):
285
287
        l = []
286
 
        for i in path1.visit(lambda x: x.check(file=1)): 
 
288
        for i in path1.visit(lambda x: x.check(file=1)):
287
289
            l.append(i.relto(path1))
288
290
        assert not "sampledir" in l
289
291
        assert path1.sep.join(["sampledir", "otherfile"]) in l
296
298
 
297
299
    def test_visit_nodotfiles(self, path1):
298
300
        l = []
299
 
        for i in path1.visit(lambda x: x.check(dotfile=0)): 
 
301
        for i in path1.visit(lambda x: x.check(dotfile=0)):
300
302
            l.append(i.relto(path1))
301
303
        assert "sampledir" in l
302
304
        assert path1.sep.join(["sampledir", "otherfile"]) in l
379
381
                assert p.check()
380
382
 
381
383
    def test_move_dir(self, path1):
382
 
        source = path1.join('sampledir') 
383
 
        dest = path1.join('moveddir') 
 
384
        source = path1.join('sampledir')
 
385
        dest = path1.join('moveddir')
384
386
        source.move(dest)
385
387
        assert dest.check(dir=1)
386
 
        assert dest.join('otherfile').check(file=1) 
 
388
        assert dest.join('otherfile').check(file=1)
387
389
        assert not source.join('sampledir').check()
388
390
 
389
391
def setuptestfs(path):
416
418
    module_b = otherdir.ensure('b.py')
417
419
    module_b.write('stuff="got it"\n')
418
420
    module_c = otherdir.ensure('c.py')
419
 
    module_c.write('''import py; 
 
421
    module_c.write('''import py;
420
422
import otherdir.a
421
423
value = otherdir.a.result
422
424
''')
423
425
    module_d = otherdir.ensure('d.py')
424
 
    module_d.write('''import py; 
 
426
    module_d.write('''import py;
425
427
from otherdir import a
426
428
value2 = a.result
427
429
''')