File tree Expand file tree Collapse file tree 2 files changed +32
-1
lines changed
com.oracle.graal.python.test/src/tests
com.oracle.graal.python/src/com/oracle/graal/python/runtime Expand file tree Collapse file tree 2 files changed +32
-1
lines changed Original file line number Diff line number Diff line change @@ -388,9 +388,11 @@ class ChdirTests(unittest.TestCase):
388
388
389
389
def setUp (self ):
390
390
self .old_wd = os .getcwd ()
391
+ os .mkdir (TEST_FULL_PATH1 )
391
392
392
393
def tearDown (self ):
393
394
os .chdir (self .old_wd )
395
+ os .rmdir (TEST_FULL_PATH1 )
394
396
395
397
def test_chdir (self ):
396
398
os .chdir (TEMP_DIR )
@@ -399,6 +401,27 @@ def test_chdir(self):
399
401
os .chdir (os .fsencode (self .old_wd ))
400
402
self .assertEqual (self .old_wd , os .getcwd ())
401
403
404
+ def test_chdir_relative (self ):
405
+ os .chdir (TEMP_DIR )
406
+ tmp_dir = os .getcwd ()
407
+ os .chdir (TEST_FILENAME1 )
408
+ self .assertEqual (os .path .join (tmp_dir , TEST_FILENAME1 ), os .getcwd ())
409
+
410
+ def test_chdir_relative_symlink (self ):
411
+ os .symlink (TEST_FULL_PATH1 , TEST_FULL_PATH2 , target_is_directory = True )
412
+ try :
413
+ os .chdir (TEMP_DIR )
414
+ os .chdir (TEST_FILENAME2 )
415
+ finally :
416
+ os .remove (TEST_FULL_PATH2 )
417
+
418
+ def test_chdir_not_a_dir (self ):
419
+ os .close (os .open (TEST_FULL_PATH2 , os .O_WRONLY | os .O_CREAT ))
420
+ try :
421
+ self .assertRaises (NotADirectoryError , os .chdir , TEST_FULL_PATH2 )
422
+ finally :
423
+ os .unlink (TEST_FULL_PATH2 )
424
+
402
425
def test_chdir_fd (self ):
403
426
os .chdir (TEMP_DIR )
404
427
with open (self .old_wd , 0 ) as fd :
Original file line number Diff line number Diff line change @@ -1013,7 +1013,15 @@ public void fchdir(int fd,
1013
1013
}
1014
1014
1015
1015
private void chdirStr (String pathStr , BranchProfile errorBranch ) throws PosixException {
1016
- TruffleFile truffleFile = getTruffleFile (pathStr );
1016
+ TruffleFile truffleFile = getTruffleFile (pathStr ).getAbsoluteFile ();
1017
+ if (!truffleFile .exists ()) {
1018
+ errorBranch .enter ();
1019
+ throw posixException (OSErrorEnum .ENOENT );
1020
+ }
1021
+ if (!truffleFile .isDirectory ()) {
1022
+ errorBranch .enter ();
1023
+ throw posixException (OSErrorEnum .ENOTDIR );
1024
+ }
1017
1025
try {
1018
1026
context .getEnv ().setCurrentWorkingDirectory (truffleFile );
1019
1027
} catch (IllegalArgumentException ignored ) {
You can’t perform that action at this time.
0 commit comments