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 @@ -357,9 +357,11 @@ class ChdirTests(unittest.TestCase):
357
357
358
358
def setUp (self ):
359
359
self .old_wd = os .getcwd ()
360
+ os .mkdir (TEST_FULL_PATH1 )
360
361
361
362
def tearDown (self ):
362
363
os .chdir (self .old_wd )
364
+ os .rmdir (TEST_FULL_PATH1 )
363
365
364
366
def test_chdir (self ):
365
367
os .chdir (TEMP_DIR )
@@ -368,6 +370,27 @@ def test_chdir(self):
368
370
os .chdir (os .fsencode (self .old_wd ))
369
371
self .assertEqual (self .old_wd , os .getcwd ())
370
372
373
+ def test_chdir_relative (self ):
374
+ os .chdir (TEMP_DIR )
375
+ tmp_dir = os .getcwd ()
376
+ os .chdir (TEST_FILENAME1 )
377
+ self .assertEqual (os .path .join (tmp_dir , TEST_FILENAME1 ), os .getcwd ())
378
+
379
+ def test_chdir_relative_symlink (self ):
380
+ os .symlink (TEST_FULL_PATH1 , TEST_FULL_PATH2 , target_is_directory = True )
381
+ try :
382
+ os .chdir (TEMP_DIR )
383
+ os .chdir (TEST_FILENAME2 )
384
+ finally :
385
+ os .remove (TEST_FULL_PATH2 )
386
+
387
+ def test_chdir_not_a_dir (self ):
388
+ os .close (os .open (TEST_FULL_PATH2 , os .O_WRONLY | os .O_CREAT ))
389
+ try :
390
+ self .assertRaises (NotADirectoryError , os .chdir , TEST_FULL_PATH2 )
391
+ finally :
392
+ os .unlink (TEST_FULL_PATH2 )
393
+
371
394
def test_chdir_fd (self ):
372
395
os .chdir (TEMP_DIR )
373
396
with open (self .old_wd , 0 ) as fd :
Original file line number Diff line number Diff line change @@ -960,7 +960,15 @@ public void fchdir(int fd,
960
960
}
961
961
962
962
private void chdirStr (String pathStr , BranchProfile errorBranch ) throws PosixException {
963
- TruffleFile truffleFile = getTruffleFile (pathStr );
963
+ TruffleFile truffleFile = getTruffleFile (pathStr ).getAbsoluteFile ();
964
+ if (!truffleFile .exists ()) {
965
+ errorBranch .enter ();
966
+ throw posixException (OSErrorEnum .ENOENT );
967
+ }
968
+ if (!truffleFile .isDirectory ()) {
969
+ errorBranch .enter ();
970
+ throw posixException (OSErrorEnum .ENOTDIR );
971
+ }
964
972
try {
965
973
context .getEnv ().setCurrentWorkingDirectory (truffleFile );
966
974
} catch (IllegalArgumentException ignored ) {
You can’t perform that action at this time.
0 commit comments