diff options
| author | Antoine Pitrou <solipsis@pitrou.net> | 2009-01-29 20:19:34 (GMT) |
|---|---|---|
| committer | Antoine Pitrou <solipsis@pitrou.net> | 2009-01-29 20:19:34 (GMT) |
| commit | 707c593761930016d00e7dbeb828e6f8c973622d (patch) | |
| tree | 03960703f6c016656e44ec5bd1bc6a3d02f90a5c /Lib/test/test_shutil.py | |
| parent | 6ed1cb001416d6704a5af0f7d8c00ce3e5413d96 (diff) | |
| download | cpython-707c593761930016d00e7dbeb828e6f8c973622d.zip cpython-707c593761930016d00e7dbeb828e6f8c973622d.tar.gz cpython-707c593761930016d00e7dbeb828e6f8c973622d.tar.bz2 | |
Issue #2047: shutil.move() could believe that its destination path was
inside its source path if it began with the same letters (e.g. "src" vs.
"src.new").
Diffstat (limited to 'Lib/test/test_shutil.py')
| -rw-r--r-- | Lib/test/test_shutil.py | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/Lib/test/test_shutil.py b/Lib/test/test_shutil.py index fa5bbb1..6f65bdf 100644 --- a/Lib/test/test_shutil.py +++ b/Lib/test/test_shutil.py @@ -340,7 +340,29 @@ class TestMove(unittest.TestCase): dst = os.path.join(self.src_dir, "bar") self.assertRaises(shutil.Error, shutil.move, self.src_dir, dst) + def test_destinsrc_false_negative(self): + os.mkdir(TESTFN) + try: + for src, dst in [('srcdir', 'srcdir/dest')]: + src = os.path.join(TESTFN, src) + dst = os.path.join(TESTFN, dst) + self.assert_(shutil.destinsrc(src, dst), + msg='destinsrc() wrongly concluded that ' + 'dst (%s) is not in src (%s)' % (dst, src)) + finally: + shutil.rmtree(TESTFN, ignore_errors=True) + def test_destinsrc_false_positive(self): + os.mkdir(TESTFN) + try: + for src, dst in [('srcdir', 'src/dest'), ('srcdir', 'srcdir.new')]: + src = os.path.join(TESTFN, src) + dst = os.path.join(TESTFN, dst) + self.failIf(shutil.destinsrc(src, dst), + msg='destinsrc() wrongly concluded that ' + 'dst (%s) is in src (%s)' % (dst, src)) + finally: + shutil.rmtree(TESTFN, ignore_errors=True) def test_main(): test_support.run_unittest(TestShutil, TestMove) |
