1
+ """
2
+ Testing Copy Method of DropboxDriveFileSystem
3
+
4
+ Test case reference from https://filesystem-spec.readthedocs.io/en/latest/copying.html
5
+ """
6
+ import pytest
7
+ from dropboxdrivefs import DropboxDriveFileSystem
8
+
9
+ @pytest .fixture
10
+ def dropbox_fs ():
11
+ fs = DropboxDriveFileSystem ('123' )
12
+ if not fs .exists ('/source' ):
13
+ fs .mkdir ('/source' )
14
+ if not fs .exists ('/source/subdir' ):
15
+ fs .mkdir ('/source/subdir' )
16
+ if not fs .exists ('/target' ):
17
+ fs .mkdir ('/target' )
18
+ with fs .open ('/source/subdir/subfile1' , 'w' ) as f :
19
+ f .write ('hello' )
20
+ with fs .open ('/source/file1' , 'w' ) as f :
21
+ f .write ('hello' )
22
+ with fs .open ('/source/file2' , 'w' ) as f :
23
+ f .write ('hello' )
24
+ return fs
25
+
26
+ def test_db_cp (dropbox_fs ):
27
+ try :
28
+ # 1f. Directory to new directory
29
+ dropbox_fs .cp ("/source/subdir/" , "/target/newdir/" , recursive = True )
30
+ assert dropbox_fs .exists ('/target/newdir/subfile1' )
31
+ dropbox_fs .rm ('/target/newdir' , recursive = True )
32
+ # 1e. Directory to existing directory
33
+ dropbox_fs .cp ("/source/subdir/" , "/target/" , recursive = True )
34
+ assert dropbox_fs .exists ('/target/subfile1' )
35
+ dropbox_fs .rm ('/target/subfile1' )
36
+ # 1a. File to existing directory
37
+ dropbox_fs .cp ('/source/subdir/subfile1' , '/target/' )
38
+ assert dropbox_fs .exists ('/target/subfile1' )
39
+ dropbox_fs .rm ('/target/subfile1' )
40
+ # 1b. File to new directory
41
+ dropbox_fs .cp ('/source/subdir/subfile1' , '/target/newdir/' )
42
+ assert dropbox_fs .exists ('/target/newdir/subfile1' )
43
+ dropbox_fs .rm ('/target/newdir' , recursive = True )
44
+ # 1c. File to File in existing directory
45
+ dropbox_fs .cp ("/source/subdir/subfile1" , "/target/newfile" )
46
+ assert dropbox_fs .exists ('/target/newfile' )
47
+ dropbox_fs .rm ('/target/newfile' )
48
+ # 1d. File to File in new directory
49
+ dropbox_fs .cp ("/source/subdir/subfile1" , "/target/newdir/newfile" )
50
+ assert dropbox_fs .exists ('/target/newdir/newfile' )
51
+ dropbox_fs .rm ('/target/newdir' , recursive = True )
52
+ # 2a. List of Files to existing directory
53
+ dropbox_fs .cp (["/source/file1" , "/source/file2" , "/source/subdir/subfile1" ], "/target/" )
54
+ assert dropbox_fs .exists ('/target/file1' )
55
+ assert dropbox_fs .exists ('/target/file2' )
56
+ assert dropbox_fs .exists ('/target/subfile1' )
57
+ dropbox_fs .rm ('/target/file1' )
58
+ dropbox_fs .rm ('/target/file2' )
59
+ dropbox_fs .rm ('/target/subfile1' )
60
+ # 2b. List of Files to new directory
61
+ dropbox_fs .cp (["/source/file1" , "/source/file2" , "/source/subdir/subfile1" ], "/target/newdir/" )
62
+ assert dropbox_fs .exists ('/target/newdir/file1' )
63
+ assert dropbox_fs .exists ('/target/newdir/file2' )
64
+ assert dropbox_fs .exists ('/target/newdir/subfile1' )
65
+ dropbox_fs .rm ('/target/newdir/' , recursive = True )
66
+ finally :
67
+ # Final Delete
68
+ dropbox_fs .rm ('/source/' , recursive = True )
69
+ dropbox_fs .rm ('/target/' , recursive = True )
0 commit comments