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)
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())
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)
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')
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')
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")
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)
def set_up(absolute): temp_dir = maketemp() os.chdir(temp_dir) source_name = os.path.join(temp_dir, u"link_source") if absolute: target_name = os.path.join(temp_dir, u"link_target") else: target_name = u"link_target" # create the file the link will point to f = open(target_name, "w") f.close() # create link os.symlink(target_name, source_name) return source_name, target_name
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))
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)
def setUp(self): real_path = filesystem.path(maketemp()) self.path = filesystem.multiplexing.path() self.path.bind(real_path) assert self.path.exists()
def setUp(self): self.path = filesystem.path(maketemp())
def setUp(self): real_path = filesystem.path(maketemp()) self.path = filesystem.copyonwrite.path(real_path) assert self.path.exists()
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)