diff --git a/Lib/test/test_os.py b/Lib/test/test_os.py --- a/Lib/test/test_os.py +++ b/Lib/test/test_os.py @@ -1243,6 +1243,43 @@ self.assertEqual(os.stat(link), os.stat(target)) self.assertNotEqual(os.lstat(link), os.stat(link)) + @support.skip_unless_symlink + def test_12084(self): + level1 = support.TESTFN + level2 = os.path.join(level1, "level2") + try: + os.mkdir(level1) + os.mkdir(level2) + + file1 = os.path.join(level1, "file1") + file2 = os.path.join(level2, "file2") + + with open(file1, "w") as f: + f.write("file1") + + orig_dir = os.getcwd() + try: + link1 = os.path.join(level1, "link1") + os.symlink(file1, link1) + self.assertIn("link1", os.listdir(level1)) + + # Check os.stat calls from outside (below) the source and link + self.assertEqual(os.stat(file1), os.stat(link1)) + + # Check os.stat calls from the same dir as source and link + os.chdir(level1) + self.assertEqual(os.stat(file1), os.stat(link1)) + + # Check os.stat calls from the same dir as source and link + os.chdir(level2) + self.assertEqual(os.stat(file1), os.stat(link1)) + finally: + os.chdir(orig_dir) + except OSError as err: + self.fail(err) + finally: + shutil.rmtree(level1) + class FSEncodingTests(unittest.TestCase): def test_nop(self):