Alternative Path Module TestsΒΆ

Legacy Wiki Page

This page was migrated from the old MoinMoin-based wiki. Information may be outdated or no longer applicable. For current documentation, see python.org.

   1 ======================================
   2 doctest for path.py
   3 
   4 Uncomplete, and tests POSIX paths only
   5 ======================================
   6 
   7 >>> from mypath import path
   8 
   9 # Test root
  10 
  11 >>> path.ROOT
  12 path.ROOT
  13 
  14 >>> path.ROOT == path.ROOT
  15 True
  16 >>> path.ROOT < path.ROOT
  17 False
  18 >>> path.ROOT > path.ROOT
  19 False
  20 
  21 >>> path.ROOT == 'e'
  22 False
  23 >>> path.ROOT < 'h'
  24 True
  25 >>> path.ROOT > 'b'
  26 False
  27 >>> path.ROOT > 3
  28 Traceback (most recent call last):
  29 ...
  30 TypeError: Comparison not defined
  31 
  32 >>> 'a' == path.ROOT
  33 False
  34 >>> 'a' < path.ROOT
  35 False
  36 >>> 'a' > path.ROOT
  37 True
  38 >>> 3 > path.ROOT
  39 Traceback (most recent call last):
  40 ...
  41 TypeError: Comparison not defined
  42 
  43 
  44 # Basic path creation
  45 
  46 >>> path('/bin/arch')
  47 path('/bin/arch')
  48 >>> p = _
  49 >>> p[0]
  50 path.ROOT
  51 >>> p[1]
  52 'bin'
  53 >>> p[2]
  54 'arch'
  55 >>> len(p)
  56 3
  57 >>> path('hello/what')
  58 path('hello/what')
  59 >>> p = _
  60 >>> p[0]
  61 'hello'
  62 >>> p[1]
  63 'what'
  64 >>> len(p)
  65 2
  66 >>> path('.')
  67 path('.')
  68 >>> len(_)
  69 0
  70 >>> path('')
  71 path('.')
  72 >>> path()
  73 path('.')
  74 >>> path('/')
  75 path('/')
  76 
  77 # Constructing from a string
  78 
  79 >>> path('hello//what')
  80 path('hello/what')
  81 >>> path('hello//what/')
  82 path('hello/what')
  83 >>> path('/hello//what/')
  84 path('/hello/what')
  85 >>> path('//hello//what/')
  86 Traceback (most recent call last):
  87 ...
  88 NotImplementedError: Paths with two leading slashes aren't supported.
  89 >>> path('///hello//what/')
  90 path('/hello/what')
  91 
  92 # Constructing from an iterable
  93 
  94 >>> path(['hello', 'how'])
  95 path('hello/how')
  96 >>> path([path.ROOT, 'hello', 'how'])
  97 path('/hello/how')
  98 >>> path(['hello', path.ROOT, 'how'])
  99 Traceback (most recent call last):
 100 ...
 101 TypeError: Element path.ROOT is of a wrong type
 102 
 103 # Concatenation
 104 
 105 >>> path('hello/a') + path('b')
 106 path('hello/a/b')
 107 >>> path('hello/a') + 'b'