예제 #1
0
def test_fileobject_tmppath_two_files_with_same_name(tmpdir):

    path1 = tmpdir.join('fileobject-tmppath-twofiles')
    fo1 = FileObject(str(path1))
    fo1.write('fileobject-tmppath-twofiles-1')
    assert fo1.read() == 'fileobject-tmppath-twofiles-1'

    path2 = tmpdir.join('fileobject-tmppath-twofiles')
    fo2 = FileObject(str(path2))
    fo2.write('fileobject-tmppath-twofiles-2')
    assert fo2.read() == 'fileobject-tmppath-twofiles-2'
예제 #2
0
def test_fileobject_write_read_str(tmpdir):

    path = str(tmpdir.join('fileobject-write-read-str'))
    fo = FileObject(path)
    fo.write('fileobject-write-read-str')
    assert fo.path == path
    assert fo.read() == 'fileobject-write-read-str'
예제 #3
0
def test_fileobject_rename(tmpdir):

    path = tmpdir.join('fileobject-rename')
    fo = FileObject(str(path))
    fo.write('fileobject-rename')
    assert fo.path == path

    new_path = os.path.join(path.dirname, 'fileobject-rename-new')
    fo.rename(new_path)
    assert fo.read() == 'fileobject-rename'
예제 #4
0
def test_fileobject_tmppath_with_file(tmpdir):

    path = tmpdir.join('fileobject-tmppath-with-file')
    fo = FileObject(str(path))
    assert fo.path == path

    fo.write('fileobject-tmppath-with-file')
    assert fo.read() == 'fileobject-tmppath-with-file'

    fo.mktemp()
    assert fo.path.endswith('fileobject-tmppath-with-file.part')
    assert os.path.exists(fo.path)

    fo.rmtemp()
    assert fo.path.endswith('fileobject-tmppath-with-file')
    assert os.path.exists(fo.path)