예제 #1
0
  def test_encoding(self):
    encoded = ['a%20a', '/%7haypepps/']
    unencoded = ['a+a', '/~haypepps/']

    for path in encoded:
      assert str(furl.Path(path)) == urllib.unquote(path)

    for path in unencoded:
      assert str(furl.Path(path)) == path
예제 #2
0
  def test_remove(self):
    p = furl.Path('a/b/s%20s/')
    assert p == p.remove(True)
    assert str(p) == ''

    p = furl.Path('a/b/s%20s/')
    assert p == p.remove(['b', 's s'])
    assert str(p) == 'a/'

    p = furl.Path('a/b/s%20s/')
    assert p == p.remove(['', 'b', 's s'])
    assert str(p) == 'a'
예제 #3
0
  def test_isdir_isfile(self):
    for path in ['', '/']:
      p = furl.Path(path)
      assert p.isdir
      assert not p.isfile
    
    for path in ['dir1/', 'd1/d2/', 'd/d/d/d/d/', '/', '/dir1/', '/d1/d2/d3/']:
      p = furl.Path(path)
      assert p.isdir
      assert not p.isfile

    for path in ['dir1', 'd1/d2', 'd/d/d/d/d', '/dir1', '/d1/d2/d3']:
      p = furl.Path(path)
      assert p.isfile
      assert not p.isdir
예제 #4
0
 def test_add(self):
   p = furl.Path('a/b/c/')
   assert p == p.add('d')
   assert str(p) == 'a/b/c/d'
   assert p == p.add('/')
   assert str(p) == 'a/b/c/d/'
   assert p == p.add(['e', 'f', 'e e', ''])
   assert str(p) == 'a/b/c/d/e/f/e e/'
예제 #5
0
  def test_leading_slash(self):
    p = furl.Path('')
    assert not p.isabsolute
    assert not p.segments
    assert p.isdir and p.isdir != p.isfile
    assert str(p) == ''

    p = furl.Path('/')
    assert p.isabsolute
    assert p.segments == ['']
    assert p.isdir and p.isdir != p.isfile
    assert str(p) == '/'

    p = furl.Path('sup')
    assert not p.isabsolute
    assert p.segments == ['sup']
    assert p.isfile and p.isdir != p.isfile
    assert str(p) == 'sup'

    p = furl.Path('/sup')
    assert p.isabsolute
    assert p.segments == ['sup']
    assert p.isfile and p.isdir != p.isfile
    assert str(p) == '/sup'
    
    p = furl.Path('a/b/c')
    assert not p.isabsolute
    assert p.segments == ['a', 'b', 'c']
    assert p.isfile and p.isdir != p.isfile
    assert str(p) == 'a/b/c'

    p = furl.Path('/a/b/c')
    assert p.isabsolute
    assert p.segments == ['a', 'b', 'c']
    assert p.isfile and p.isdir != p.isfile
    assert str(p) == '/a/b/c'

    p = furl.Path('a/b/c/')
    assert not p.isabsolute
    assert p.segments == ['a', 'b', 'c', '']
    assert p.isdir and p.isdir != p.isfile
    assert str(p) == 'a/b/c/'

    p.isabsolute = True
    assert p.isabsolute
    assert str(p) == '/a/b/c/'
예제 #6
0
 def test_set(self):
   p = furl.Path('a/b/c/')
   assert p == p.set('asdf/asdf/')
   assert str(p) == 'asdf/asdf/'
   assert p == p.set(['a', 'b', 'c', ''])
   assert str(p) == 'a/b/c/'