예제 #1
0
def test_mkdir_bad_exists():
    tmp = maketemp()
    p = filesystem.copyonwrite.path(filesystem.path(tmp)).child("foo")
    with p.open("w") as f:
        f.write("bar")
    e = assert_raises(OSError, p.mkdir)
    eq(e.errno, errno.EEXIST)
예제 #2
0
def test_join_with_leading_slash():
    """
    join should raise an exception if one tries to escape from the
    path by giving an absolute path
    """
    e = assert_raises(filesystem.InsecurePathError, filesystem.path(u'/tmp').join, u'/usr')
    eq(str(e), 'path name to join must be relative')
예제 #3
0
def test_rename_bad_string():
    tmp = maketemp()
    parent = filesystem.path(tmp)
    old = parent.join(u'foo')
    assert_raises(
        filesystem.CrossDeviceRenameError,
        old.rename, 'foo')
    eq(filesystem.root, filesystem.root.parent())
예제 #4
0
def test_not_directory():
    temp_dir = maketemp()
    # prepare a file on which to call the iterator
    f = open(os.path.join(temp_dir, "some_file"), "w")
    f.close()
    # check reaction on getting the iterator
    p = filesystem.copyonwrite.path(filesystem.path(temp_dir).join("some_file"))
    # note: the exception is only raised after calling ``next``
    assert_raises(OSError, list, p)
예제 #5
0
def test_bind():
    """
    Testing the multiplexing file system (TODO: split up into multiple tests, clean up)
    """
    mp_root = filesystem.multiplexing.path()
    mountpoint = mp_root.join('mnt/tmp/')
    real_pathname = maketemp()
    mountpoint.bind(filesystem.path(real_pathname))
    real_path = filesystem.path(real_pathname)
    
    ## TODO: RFC: I'm not sure whether it should pass or not since the
    ## parent differs.
    #eq(real_path, mountpoint)
    #eq(mountpoint, real_path)
    ne(real_path, mountpoint)
    ne(mountpoint, real_path)

    ## mountpoint.parent should give the parent node in the multiplexing fs
    ## real_path.parent should give the real parent directory
    ne(mountpoint.parent(), real_path.parent())
    assert mountpoint.isdir()
    assert real_path.isdir()

    ## Let's make a subdirectory under our "mounted" directory
    foo = mp_root.join('mnt/tmp/foo')
    foo2 = mountpoint.child('foo')
    real_foo = real_path.child('foo')
    ## same directory, same parent
    eq(foo, foo2)
    ## same directory, different parents
    #eq(foo, real_foo)
    ne(foo, real_foo)
    assert not foo.exists()
    assert not foo2.exists()
    assert not real_foo.exists()
    foo.mkdir()
    assert foo.isdir()
    assert foo2.isdir()
    assert real_foo.isdir()
    ## same directory, different parent
    #eq(real_foo, foo2)
    ne(real_foo, foo2)
예제 #6
0
def test_open_for_reading():
    tmp = maketemp()
    foo = os.path.join(tmp, u"foo")
    # write file with Python's standard API ...
    with open(foo, "w") as f:
        f.write("bar")
    # ... and read it back with our fs code
    p = filesystem.copyonwrite.path(filesystem.path(foo))
    with p.open() as f:
        got = f.read()
    eq(got, "bar")
예제 #7
0
파일: mpqutil.py 프로젝트: h82258652/YDWE
def add_directory(mpq, from_path, from_name = fs.path('')):
    src_path = from_path / from_name
    for name in os.listdir(str(src_path)):
        file_path = src_path / name
        if fs.is_directory(file_path):
            add_directory(mpq, from_path, from_name / name)
        else:
            try:
                mpq.AddFileEx(str(file_path).encode('ascii'), str(from_name / name).encode('ascii'))
            except:
                pass
예제 #8
0
def add_directory(mpq, from_path, from_name = fs.path('')):
    src_path = from_path / from_name
    for name in os.listdir(str(src_path)):
        file_path = src_path / name
        if fs.is_directory(file_path):
            add_directory(mpq, from_path, from_name / name)
        else:
            try:
                mpq.AddFileEx(str(file_path).encode('ascii'), str(from_name / name).encode('ascii'))
            except:
                pass
예제 #9
0
def test_open_for_reading():
    tmp = maketemp()
    foo = os.path.join(tmp, u'foo')
    # write file with Python's standard API ...
    with open(foo, 'w') as f:
        f.write('bar')
    # ... and read it back with our fs code
    p = filesystem.path(foo)
    with p.open() as f:
        got = f.read()
    eq(got, 'bar')
예제 #10
0
def test_open_for_writing():
    tmp = maketemp()
    foo = os.path.join(tmp, u'foo')
    # write test content
    p = filesystem.path(foo)
    with p.open('w') as f:
        f.write('bar')
    # read back in and compare
    with open(foo) as f:
        got = f.read()
    eq(got, 'bar')
예제 #11
0
def test_open_for_writing():
    tmp = maketemp()
    foo = os.path.join(tmp, u"foo")
    # write test content
    p = filesystem.copyonwrite.path(filesystem.path(foo))
    assert_raises(IOError, open, foo)
    with p.open("w") as f:
        f.write("bar")

    # since this is the copy_on_write, the write should not be written
    # to the actual file system
    assert_raises(IOError, open, foo)
예제 #12
0
def test_iter():
    temp_dir = maketemp()
    temp_files = ["file1", "file2"]
    # put some files in the temporary directory
    for i in temp_files:
        f = open(os.path.join(temp_dir, i), "w")
        f.close()
    p = filesystem.copyonwrite.path(filesystem.path(temp_dir))
    ## add one more file
    with p.child("file3").open("w") as f:
        f.write("ubba")
    temp_files.append("file3")
    # see whether we actually get the file names with the iterator
    eq(sorted(str(x) for x in p), sorted(str(p.child(x)) for x in temp_files))
예제 #13
0
def test_new_object():
    p = filesystem.path(u"/")
    c = p.child(u"segment1", u"segment2")
    assert p is not c
    eq(unicode(p), u"/")
    eq(unicode(c), u"/segment1/segment2")
예제 #14
0
def test_mkdir():
    tmp = maketemp()
    filesystem.copyonwrite.path(filesystem.path(tmp)).child("foo").mkdir()
    foo = os.path.join(tmp, "foo")
    assert not os.path.isdir(foo)
예제 #15
0
def test_open_nonexisting():
    p = filesystem.path(u'/does-not-exist')
    e = assert_raises(IOError, p.open)
    eq(e.errno, errno.ENOENT)
예제 #16
0
def test_relative_target():
    source_name, target_name = set_up(absolute=False)
    p = filesystem.path(source_name)
    eq(p.readlink(), target_name)
 def setUp(self):
     real_path = filesystem.path(maketemp())
     self.path = filesystem.multiplexing.path()
     self.path.bind(real_path)
     assert self.path.exists()
예제 #18
0
def test_repr():
    p = filesystem.path(u"/test\xe4")
    assert isinstance(repr(p), str)
예제 #19
0
def test_parent_of_curdir():
    p = filesystem.path('.')
    eq(p.parent(), p)
예제 #20
0
def test_open_nonexisting():
    p = filesystem.copyonwrite.path(filesystem.path(u"/does-not-exist"))
    e = assert_raises(IOError, p.open)
    eq(e.errno, errno.ENOENT)
예제 #21
0
def test_str_simple():
    p = filesystem.path(u'/foo')
    got = str(p)
    eq(got, u'/foo')
예제 #22
0
def test_readlink_on_nonexistent_file():
    p = filesystem.path(u"non-existent-file")
    assert_raises(OSError, p.readlink)
예제 #23
0
def test_readlink_on_regular_file():
    source_name, target_name = set_up(absolute=False)
    p = filesystem.path(target_name)
    assert_raises(OSError, p.readlink)
 def setUp(self):
     real_path = filesystem.path(maketemp())
     self.path = filesystem.copyonwrite.path(real_path)
     assert self.path.exists()
예제 #25
0
def test_path_unicode_argument():
    p = filesystem.path(u"/")
    assert isinstance(str(p), str)
    assert isinstance(unicode(p), unicode)
예제 #26
0
def test_parent_of_relative():
    p = filesystem.path('foo')
    eq(p.parent(), filesystem.path('.'))
예제 #27
0
 def setUp(self):
     self.path = filesystem.path(maketemp())
예제 #28
0
def test_parent_of_relative_subdir():
    p = filesystem.path('foo/bar')
    eq(p.parent(), filesystem.path('foo'))
예제 #29
0
def test_name_simple():
    eq(filesystem.path("foo/bar").name(), "bar")
예제 #30
0
def test_absolute_target():
    source_name, target_name = set_up(absolute=True)
    p = filesystem.path(source_name)
    eq(p.readlink(), target_name)