10
10
class MultiplexedPathTest (unittest .TestCase ):
11
11
@classmethod
12
12
def setUpClass (cls ):
13
- path = pathlib .Path (__file__ ).parent / 'namespacedata01'
14
- cls .folder = str (path )
13
+ cls .folder = pathlib .Path (__file__ ).parent / 'namespacedata01'
15
14
16
15
def test_init_no_paths (self ):
17
16
with self .assertRaises (FileNotFoundError ):
18
17
MultiplexedPath ()
19
18
20
19
def test_init_file (self ):
21
20
with self .assertRaises (NotADirectoryError ):
22
- MultiplexedPath (os . path . join ( self .folder , 'binary.file' ) )
21
+ MultiplexedPath (self .folder / 'binary.file' )
23
22
24
23
def test_iterdir (self ):
25
24
contents = {path .name for path in MultiplexedPath (self .folder ).iterdir ()}
26
25
try :
27
26
contents .remove ('__pycache__' )
28
27
except (KeyError , ValueError ):
29
28
pass
30
- self .assertEqual (contents , {'binary.file' , 'utf-16.file' , 'utf-8.file' })
29
+ self .assertEqual (
30
+ contents , {'subdirectory' , 'binary.file' , 'utf-16.file' , 'utf-8.file' }
31
+ )
31
32
32
33
def test_iterdir_duplicate (self ):
33
- data01 = os . path . abspath ( os . path . join ( __file__ , '..' , ' data01') )
34
+ data01 = pathlib . Path ( __file__ ). parent . joinpath ( ' data01' )
34
35
contents = {
35
36
path .name for path in MultiplexedPath (self .folder , data01 ).iterdir ()
36
37
}
@@ -60,17 +61,17 @@ def test_open_file(self):
60
61
path .open ()
61
62
62
63
def test_join_path (self ):
63
- prefix = os . path . abspath ( os . path . join ( __file__ , '..' ) )
64
- data01 = os . path . join ( prefix , ' data01' )
64
+ data01 = pathlib . Path ( __file__ ). parent . joinpath ( 'data01' )
65
+ prefix = str ( data01 . parent )
65
66
path = MultiplexedPath (self .folder , data01 )
66
67
self .assertEqual (
67
68
str (path .joinpath ('binary.file' ))[len (prefix ) + 1 :],
68
69
os .path .join ('namespacedata01' , 'binary.file' ),
69
70
)
70
- self . assertEqual (
71
- str ( path . joinpath ( 'subdirectory' ))[ len ( prefix ) + 1 :],
72
- os . path . join ( 'data01' , 'subdirectory' ),
73
- )
71
+ sub = path . joinpath ( 'subdirectory' )
72
+ assert isinstance ( sub , MultiplexedPath )
73
+ assert 'namespacedata01' in str ( sub )
74
+ assert 'data01' in str ( sub )
74
75
self .assertEqual (
75
76
str (path .joinpath ('imaginary' ))[len (prefix ) + 1 :],
76
77
os .path .join ('namespacedata01' , 'imaginary' ),
@@ -82,9 +83,9 @@ def test_join_path_compound(self):
82
83
assert not path .joinpath ('imaginary/foo.py' ).exists ()
83
84
84
85
def test_join_path_common_subdir (self ):
85
- prefix = os . path . abspath ( os . path . join ( __file__ , '..' ) )
86
- data01 = os . path . join ( prefix , 'data01 ' )
87
- data02 = os . path . join ( prefix , 'data02' )
86
+ data01 = pathlib . Path ( __file__ ). parent . joinpath ( 'data01' )
87
+ data02 = pathlib . Path ( __file__ ). parent . joinpath ( 'data02 ' )
88
+ prefix = str ( data01 . parent )
88
89
path = MultiplexedPath (data01 , data02 )
89
90
self .assertIsInstance (path .joinpath ('subdirectory' ), MultiplexedPath )
90
91
self .assertEqual (
0 commit comments