Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
allow specifying import paths, fixes #1 (use -p .)
- Loading branch information
1 parent
c16baf9
commit 1a76a06
Showing
3 changed files
with
48 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
from test.test_helper import run, temp_cwd | ||
from unittest import TestCase | ||
import subprocess | ||
|
||
|
||
class TestModuleImporting(TestCase): | ||
def test_modules_are_not_importable_from_cwd_by_default(self): | ||
# for the same reason $PATH does not include | ||
# "." - it could be an attack vector | ||
with temp_cwd(): | ||
with open("mymod.py", 'w') as f: | ||
f.write("def up(s): return s.upper()") | ||
self.assertRaises(ImportError, | ||
lambda: run('-m', 'mymod', 'mymod.up(p)', ['a'])) | ||
|
||
def test_modules_can_be_imported_from_cwd(self): | ||
with temp_cwd(): | ||
with open("mymod.py", 'w') as f: | ||
f.write("def up(s): return s.upper()") | ||
self.assertEqual( | ||
run('-p', '.', '-m', 'mymod', 'mymod.up(p)', ['a']), ['A']) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters