Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
cd482fec
Commit
cd482fec
authored
Nov 08, 2013
by
Brett Cannon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #16803: test.test_importlib.source now tests frozen and source code
parent
e9ad3599
Changes
5
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
91 additions
and
74 deletions
+91
-74
Lib/test/test_importlib/source/test_case_sensitivity.py
Lib/test/test_importlib/source/test_case_sensitivity.py
+14
-14
Lib/test/test_importlib/source/test_file_loader.py
Lib/test/test_importlib/source/test_file_loader.py
+43
-27
Lib/test/test_importlib/source/test_finder.py
Lib/test/test_importlib/source/test_finder.py
+15
-15
Lib/test/test_importlib/source/test_path_hook.py
Lib/test/test_importlib/source/test_path_hook.py
+8
-9
Lib/test/test_importlib/source/test_source_encoding.py
Lib/test/test_importlib/source/test_source_encoding.py
+11
-9
No files found.
Lib/test/test_importlib/source/test_case_sensitivity.py
View file @
cd482fec
...
...
@@ -2,8 +2,9 @@
from
..
import
util
from
.
import
util
as
source_util
from
importlib
import
_bootstrap
from
importlib
import
machinery
importlib
=
util
.
import_importlib
(
'importlib'
)
machinery
=
util
.
import_importlib
(
'importlib.machinery'
)
import
os
import
sys
from
test
import
support
as
test_support
...
...
@@ -11,7 +12,7 @@ import unittest
@
util
.
case_insensitive_tests
class
CaseSensitivityTest
(
unittest
.
TestCase
)
:
class
CaseSensitivityTest
:
"""PEP 235 dictates that on case-preserving, case-insensitive file systems
that imports are case-sensitive unless the PYTHONCASEOK environment
...
...
@@ -21,11 +22,11 @@ class CaseSensitivityTest(unittest.TestCase):
assert
name
!=
name
.
lower
()
def
find
(
self
,
path
):
finder
=
machinery
.
FileFinder
(
path
,
(
machinery
.
SourceFileLoader
,
machinery
.
SOURCE_SUFFIXES
),
(
machinery
.
SourcelessFileLoader
,
machinery
.
BYTECODE_SUFFIXES
))
finder
=
self
.
machinery
.
FileFinder
(
path
,
(
self
.
machinery
.
SourceFileLoader
,
self
.
machinery
.
SOURCE_SUFFIXES
),
(
self
.
machinery
.
SourcelessFileLoader
,
self
.
machinery
.
BYTECODE_SUFFIXES
))
return
finder
.
find_module
(
self
.
name
)
def
sensitivity_test
(
self
):
...
...
@@ -41,7 +42,7 @@ class CaseSensitivityTest(unittest.TestCase):
def
test_sensitive
(
self
):
with
test_support
.
EnvironmentVarGuard
()
as
env
:
env
.
unset
(
'PYTHONCASEOK'
)
if
b'PYTHONCASEOK'
in
_bootstrap
.
_os
.
environ
:
if
b'PYTHONCASEOK'
in
self
.
importlib
.
_bootstrap
.
_os
.
environ
:
self
.
skipTest
(
'os.environ changes not reflected in '
'_os.environ'
)
sensitive
,
insensitive
=
self
.
sensitivity_test
()
...
...
@@ -52,7 +53,7 @@ class CaseSensitivityTest(unittest.TestCase):
def
test_insensitive
(
self
):
with
test_support
.
EnvironmentVarGuard
()
as
env
:
env
.
set
(
'PYTHONCASEOK'
,
'1'
)
if
b'PYTHONCASEOK'
not
in
_bootstrap
.
_os
.
environ
:
if
b'PYTHONCASEOK'
not
in
self
.
importlib
.
_bootstrap
.
_os
.
environ
:
self
.
skipTest
(
'os.environ changes not reflected in '
'_os.environ'
)
sensitive
,
insensitive
=
self
.
sensitivity_test
()
...
...
@@ -61,10 +62,9 @@ class CaseSensitivityTest(unittest.TestCase):
self
.
assertTrue
(
hasattr
(
insensitive
,
'load_module'
))
self
.
assertIn
(
self
.
name
,
insensitive
.
get_filename
(
self
.
name
))
def
test_main
():
test_support
.
run_unittest
(
CaseSensitivityTest
)
Frozen_CaseSensitivityTest
,
Source_CaseSensitivityTest
=
util
.
test_both
(
CaseSensitivityTest
,
importlib
=
importlib
,
machinery
=
machinery
)
if
__name__
==
'__main__'
:
test_
main
()
unittest
.
main
()
Lib/test/test_importlib/source/test_file_loader.py
View file @
cd482fec
This diff is collapsed.
Click to expand it.
Lib/test/test_importlib/source/test_finder.py
View file @
cd482fec
from
..
import
abc
from
..
import
util
from
.
import
util
as
source_util
from
importlib
import
machinery
machinery
=
util
.
import_importlib
(
'importlib.machinery'
)
import
errno
import
os
import
py_compile
...
...
@@ -13,7 +15,7 @@ import unittest
import
warnings
class
FinderTests
(
unittest
.
TestCase
,
abc
.
FinderTests
):
class
FinderTests
(
abc
.
FinderTests
):
"""For a top-level module, it should just be found directly in the
directory being searched. This is true for a directory with source
...
...
@@ -38,11 +40,11 @@ class FinderTests(unittest.TestCase, abc.FinderTests):
"""
def
get_finder
(
self
,
root
):
loader_details
=
[(
machinery
.
SourceFileLoader
,
machinery
.
SOURCE_SUFFIXES
),
(
machinery
.
SourcelessFileLoader
,
machinery
.
BYTECODE_SUFFIXES
)]
return
machinery
.
FileFinder
(
root
,
*
loader_details
)
loader_details
=
[(
self
.
machinery
.
SourceFileLoader
,
self
.
machinery
.
SOURCE_SUFFIXES
),
(
self
.
machinery
.
SourcelessFileLoader
,
self
.
machinery
.
BYTECODE_SUFFIXES
)]
return
self
.
machinery
.
FileFinder
(
root
,
*
loader_details
)
def
import_
(
self
,
root
,
module
):
return
self
.
get_finder
(
root
).
find_module
(
module
)
...
...
@@ -123,8 +125,8 @@ class FinderTests(unittest.TestCase, abc.FinderTests):
def
test_empty_string_for_dir
(
self
):
# The empty string from sys.path means to search in the cwd.
finder
=
machinery
.
FileFinder
(
''
,
(
machinery
.
SourceFileLoader
,
machinery
.
SOURCE_SUFFIXES
))
finder
=
self
.
machinery
.
FileFinder
(
''
,
(
self
.
machinery
.
SourceFileLoader
,
self
.
machinery
.
SOURCE_SUFFIXES
))
with
open
(
'mod.py'
,
'w'
)
as
file
:
file
.
write
(
"# test file for importlib"
)
try
:
...
...
@@ -135,8 +137,8 @@ class FinderTests(unittest.TestCase, abc.FinderTests):
def
test_invalidate_caches
(
self
):
# invalidate_caches() should reset the mtime.
finder
=
machinery
.
FileFinder
(
''
,
(
machinery
.
SourceFileLoader
,
machinery
.
SOURCE_SUFFIXES
))
finder
=
self
.
machinery
.
FileFinder
(
''
,
(
self
.
machinery
.
SourceFileLoader
,
self
.
machinery
.
SOURCE_SUFFIXES
))
finder
.
_path_mtime
=
42
finder
.
invalidate_caches
()
self
.
assertEqual
(
finder
.
_path_mtime
,
-
1
)
...
...
@@ -180,11 +182,9 @@ class FinderTests(unittest.TestCase, abc.FinderTests):
finder
=
self
.
get_finder
(
file_obj
.
name
)
self
.
assertEqual
((
None
,
[]),
finder
.
find_loader
(
'doesnotexist'
))
Frozen_FinderTests
,
Source_FinderTests
=
util
.
test_both
(
FinderTests
,
machinery
=
machinery
)
def
test_main
():
from
test.support
import
run_unittest
run_unittest
(
FinderTests
)
if
__name__
==
'__main__'
:
test_
main
()
unittest
.
main
()
Lib/test/test_importlib/source/test_path_hook.py
View file @
cd482fec
from
..
import
util
from
.
import
util
as
source_util
from
importlib
import
machinery
machinery
=
util
.
import_importlib
(
'importlib.machinery'
)
import
unittest
class
PathHookTest
(
unittest
.
TestCase
)
:
class
PathHookTest
:
"""Test the path hook for source."""
def
path_hook
(
self
):
return
machinery
.
FileFinder
.
path_hook
((
machinery
.
SourceFileLoader
,
machinery
.
SOURCE_SUFFIXES
))
return
self
.
machinery
.
FileFinder
.
path_hook
((
self
.
machinery
.
SourceFileLoader
,
self
.
machinery
.
SOURCE_SUFFIXES
))
def
test_success
(
self
):
with
source_util
.
create_modules
(
'dummy'
)
as
mapping
:
...
...
@@ -21,11 +23,8 @@ class PathHookTest(unittest.TestCase):
# The empty string represents the cwd.
self
.
assertTrue
(
hasattr
(
self
.
path_hook
()(
''
),
'find_module'
))
def
test_main
():
from
test.support
import
run_unittest
run_unittest
(
PathHookTest
)
Frozen_PathHookTest
,
Source_PathHooktest
=
util
.
test_both
(
PathHookTest
,
machinery
=
machinery
)
if
__name__
==
'__main__'
:
test_
main
()
unittest
.
main
()
Lib/test/test_importlib/source/test_source_encoding.py
View file @
cd482fec
from
..
import
util
from
.
import
util
as
source_util
from
importlib
import
_bootstrap
machinery
=
util
.
import_importlib
(
'importlib.machinery'
)
import
codecs
import
re
import
sys
...
...
@@ -13,7 +15,7 @@ import unittest
CODING_RE
=
re
.
compile
(
r'^[ \t\f]*#.*coding[:=][ \t]*([-\
w.]+)
', re.ASCII)
class EncodingTest
(unittest.TestCase)
:
class EncodingTest:
"""PEP 3120 makes UTF-8 the default encoding for source code
[default encoding].
...
...
@@ -35,7 +37,7 @@ class EncodingTest(unittest.TestCase):
with source_util.create_modules(self.module_name) as mapping:
with open(mapping[self.module_name], '
wb
') as file:
file.write(source)
loader =
_bootstrap
.SourceFileLoader(self.module_name,
loader =
self.machinery
.SourceFileLoader(self.module_name,
mapping[self.module_name])
return loader.load_module(self.module_name)
...
...
@@ -84,8 +86,10 @@ class EncodingTest(unittest.TestCase):
with self.assertRaises(SyntaxError):
self.run_test(source)
Frozen_EncodingTest, Source_EncodingTest = util.test_both(EncodingTest, machinery=machinery)
class LineEndingTest
(unittest.TestCase)
:
class LineEndingTest:
r"""Source written with the three types of line endings (
\
n
,
\
r
\
n
,
\
r
)
need to be readable [cr][crlf][lf]."""
...
...
@@ -97,7 +101,7 @@ class LineEndingTest(unittest.TestCase):
with source_util.create_modules(module_name) as mapping:
with open(mapping[module_name], '
wb
') as file:
file.write(source)
loader =
_bootstrap
.SourceFileLoader(module_name,
loader =
self.machinery
.SourceFileLoader(module_name,
mapping[module_name])
return loader.load_module(module_name)
...
...
@@ -113,11 +117,9 @@ class LineEndingTest(unittest.TestCase):
def test_lf(self):
self.run_test(b'
\
n
')
Frozen_LineEndings, Source_LineEndings = util.test_both(LineEndingTest, machinery=machinery)
def test_main():
from test.support import run_unittest
run_unittest(EncodingTest, LineEndingTest)
if __name__ == '
__main__
':
test_
main()
unittest.
main()
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment