Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add tests for symlinks limit feature
  • Loading branch information
frenzymadness committed Sep 24, 2019
commit 6ecce95aa2c00a3603e80953f67986fd92c26949
50 changes: 50 additions & 0 deletions Lib/test/test_compileall.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,31 @@ def test_multiple_optimization_levels(self):
except Exception:
pass

@support.skip_unless_symlink
def test_ignore_symlink_destination(self):
# Create folders for allowed files, symlinks and prohibited area
allowed_path = os.path.join(self.directory, "test", "dir", "allowed")
symlinks_path = os.path.join(self.directory, "test", "dir", "symlinks")
prohibited_path = os.path.join(self.directory, "test", "dir", "prohibited")
os.makedirs(allowed_path)
os.makedirs(symlinks_path)
os.makedirs(prohibited_path)

# Create scripts and symlinks and remember their byte-compiled versions
allowed_script = script_helper.make_script(allowed_path, "test_allowed", "a = 0")
prohibited_script = script_helper.make_script(prohibited_path, "test_prohibited", "a = 0")
allowed_symlink = os.path.join(symlinks_path, "test_allowed.py")
prohibited_symlink = os.path.join(symlinks_path, "test_prohibited.py")
os.symlink(allowed_script, allowed_symlink)
os.symlink(prohibited_script, prohibited_symlink)
allowed_bc = importlib.util.cache_from_source(allowed_symlink)
prohibited_bc = importlib.util.cache_from_source(prohibited_symlink)

compileall.compile_dir(symlinks_path, quiet=True, limit_sl_dest=allowed_path)

self.assertTrue(os.path.isfile(allowed_bc))
self.assertFalse(os.path.isfile(prohibited_bc))


class CompileallTestsWithSourceEpoch(CompileallTestsBase,
unittest.TestCase,
Expand Down Expand Up @@ -722,6 +747,31 @@ def test_multiple_optimization_levels(self):
except Exception:
pass

@support.skip_unless_symlink
def test_ignore_symlink_destination(self):
# Create folders for allowed files, symlinks and prohibited area
allowed_path = os.path.join(self.directory, "test", "dir", "allowed")
symlinks_path = os.path.join(self.directory, "test", "dir", "symlinks")
prohibited_path = os.path.join(self.directory, "test", "dir", "prohibited")
os.makedirs(allowed_path)
os.makedirs(symlinks_path)
os.makedirs(prohibited_path)

# Create scripts and symlinks and remember their byte-compiled versions
allowed_script = script_helper.make_script(allowed_path, "test_allowed", "a = 0")
prohibited_script = script_helper.make_script(prohibited_path, "test_prohibited", "a = 0")
allowed_symlink = os.path.join(symlinks_path, "test_allowed.py")
prohibited_symlink = os.path.join(symlinks_path, "test_prohibited.py")
os.symlink(allowed_script, allowed_symlink)
os.symlink(prohibited_script, prohibited_symlink)
allowed_bc = importlib.util.cache_from_source(allowed_symlink)
prohibited_bc = importlib.util.cache_from_source(prohibited_symlink)

self.assertRunOK(symlinks_path, "-e", allowed_path)

self.assertTrue(os.path.isfile(allowed_bc))
self.assertFalse(os.path.isfile(prohibited_bc))


class CommandLineTestsWithSourceEpoch(CommandLineTestsBase,
unittest.TestCase,
Expand Down