summaryrefslogtreecommitdiffstats
path: root/Lib/importlib/test
Commit message (Collapse)AuthorAgeFilesLines
* Make sure that no __pycache__ directory is needlessly left behind when testingBrett Cannon2010-08-221-7/+10
| | | | imports with an empty string in sys.path.
* Add importlib benchmarks which try to be "realistic" by importing the decimalBrett Cannon2010-07-221-7/+50
| | | | module which is the largest module in the stdlib.
* Add comma grouping to max result so it's easier to read.Brett Cannon2010-07-161-1/+1
|
* Add benchmarks for importing just source w/o writing bytecode, importing sourceBrett Cannon2010-07-161-14/+57
| | | | | while writing bytecode, and importing bytecode with source existing (don't care about sourceless imports).
* Touch up comments and code along with outputting what the unit of measure is.Brett Cannon2010-07-151-7/+10
|
* Make importlib.abc.SourceLoader the primary mechanism for importlib.Brett Cannon2010-07-031-25/+36
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This required moving the class from importlib/abc.py into importlib/_bootstrap.py and jiggering some code to work better with the class. This included changing how the file finder worked to better meet import semantics. This also led to fixing importlib to handle the empty string from sys.path as import currently does (and making me wish we didn't support that instead just required people to insert '.' instead to represent cwd). It also required making the new set_data abstractmethod create any needed subdirectories implicitly thanks to __pycache__ (it was either this or grow the SourceLoader ABC to gain an 'exists' method and either a mkdir method or have set_data with no data arg mean to create a directory). Lastly, as an optimization the file loaders cache the file path where the finder found something to use for loading (this is thanks to having a sourceless loader separate from the source loader to simplify the code and cut out stat calls). Unfortunately test_runpy assumed a loader would always work for a module, even if you changed from underneath it what it was expected to work with. By simply dropping the previous loader in test_runpy so the proper loader can be returned by the finder fixed the failure. At this point importlib deviates from import on two points: 1. The exception raised when trying to import a file is different (import does an explicit file check to print a special message, importlib just says the path cannot be imported as if it was just some module name). 2. the co_filename on a code object is not being set to where bytecode was actually loaded from instead of where the marshalled code object originally came from (a solution for this has already been agreed upon on python-dev but has not been implemented yet; issue8611).
* Make importlib.abc.SourceLoader the primary mechanism for importlib.Brett Cannon2010-07-033-1/+32
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This required moving the class from importlib/abc.py into importlib/_bootstrap.py and jiggering some code to work better with the class. This included changing how the file finder worked to better meet import semantics. This also led to fixing importlib to handle the empty string from sys.path as import currently does (and making me wish we didn't support that instead just required people to insert '.' instead to represent cwd). It also required making the new set_data abstractmethod create any needed subdirectories implicitly thanks to __pycache__ (it was either this or grow the SourceLoader ABC to gain an 'exists' method and either a mkdir method or have set_data with no data arg mean to create a directory). Lastly, as an optimization the file loaders cache the file path where the finder found something to use for loading (this is thanks to having a sourceless loader separate from the source loader to simplify the code and cut out stat calls). Unfortunately test_runpy assumed a loader would always work for a module, even if you changed from underneath it what it was expected to work with. By simply dropping the previous loader in test_runpy so the proper loader can be returned by the finder fixed the failure. At this point importlib deviates from import on two points: 1. The exception raised when trying to import a file is different (import does an explicit file check to print a special message, importlib just says the path cannot be imported as if it was just some module name). 2. the co_filename on a code object is not being set to where bytecode was actually loaded from instead of where the marshalled code object originally came from (a solution for this has already been agreed upon on python-dev but has not been implemented yet; issue8611).
* Fix a spelling mistake in a comment.Brett Cannon2010-07-031-1/+1
|
* Make importlib.abc.SourceLoader the primary mechanism for importlib.Brett Cannon2010-07-0312-127/+223
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This required moving the class from importlib/abc.py into importlib/_bootstrap.py and jiggering some code to work better with the class. This included changing how the file finder worked to better meet import semantics. This also led to fixing importlib to handle the empty string from sys.path as import currently does (and making me wish we didn't support that instead just required people to insert '.' instead to represent cwd). It also required making the new set_data abstractmethod create any needed subdirectories implicitly thanks to __pycache__ (it was either this or grow the SourceLoader ABC to gain an 'exists' method and either a mkdir method or have set_data with no data arg mean to create a directory). Lastly, as an optimization the file loaders cache the file path where the finder found something to use for loading (this is thanks to having a sourceless loader separate from the source loader to simplify the code and cut out stat calls). Unfortunately test_runpy assumed a loader would always work for a module, even if you changed from underneath it what it was expected to work with. By simply dropping the previous loader in test_runpy so the proper loader can be returned by the finder fixed the failure. At this point importlib deviates from import on two points: 1. The exception raised when trying to import a file is different (import does an explicit file check to print a special message, importlib just says the path cannot be imported as if it was just some module name). 2. the co_filename on a code object is not being set to where bytecode was actually loaded from instead of where the marshalled code object originally came from (a solution for this has already been agreed upon on python-dev but has not been implemented yet; issue8611).
* Add an inheritance test for importlib.abc.SourceLoader.Brett Cannon2010-06-281-0/+5
|
* Move importlib.abc.SourceLoader to _bootstrap.Brett Cannon2010-06-281-4/+3
| | | | | | | | | | | Required updating code relying on other modules to switch to _bootstrap's unique module requirements. This led to the realization that get_code was being too liberal in its exception catching when calling set_data by blindly grabbing IOError. Shifted the responsibility of safely ignoring writes to a read-only path to set_data. Importlib is still not relying on SourceLoader yet; requires creating a SourcelessLoader and updating the source finder.
* fix test with more obviously incorrect bytecodeBenjamin Peterson2010-06-281-1/+1
|
* Implement importlib.abc.SourceLoader and deprecate PyLoader and PyPycLoader.Brett Cannon2010-06-271-6/+394
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | SourceLoader is a simplification of both PyLoader and PyPycLoader. If one only wants to use source, then they need to only implement get_data and get_filename. To also use bytecode -- sourceless loading is not supported -- then two abstract methods -- path_mtime and set_data -- need to be implemented. Compared to PyLoader and PyPycLoader, there are less abstract methods introduced and bytecode files become an optimization controlled by the ABC and hidden from the user (this need came about as PEP 3147 showed that not treating bytecode as an optimization can cause problems for compatibility). PyLoader is deprecated in favor of SourceLoader. To be compatible from Python 3.1 onwards, a subclass need only use simple methods for source_path and is_package. Otherwise conditional subclassing based on whether Python 3.1 or Python 3.2 is being is the only change. The documentation and docstring for PyLoader explain what is exactly needed. PyPycLoader is deprecated also in favor of SourceLoader. Because PEP 3147 shifted bytecode path details so much, there is no foolproof way to provide backwards-compatibility with SourceLoader. Because of this the class is simply deprecated and users should move to SourceLoader (and optionally PyLoader for Python 3.1). This does lead to a loss of support for sourceless loading unfortunately. At some point before Python 3.2 is released, SourceLoader will be moved over to importlib._bootstrap so that the core code of importlib relies on the new code instead of the old PyPycLoader code. This commit is being done now so that there is no issue in having the API in Python 3.1a1.
* Move over to assertIs.Brett Cannon2010-06-211-2/+2
|
* Repair test failure. Bug 8727.Barry Warsaw2010-05-181-0/+3
|
* Remove unnecessary XXXBarry Warsaw2010-04-171-1/+0
|
* PEP 3147Barry Warsaw2010-04-175-15/+35
|
* Importlib was not matching import's handling of .pyc files where it had lessBrett Cannon2010-02-191-24/+99
| | | | | | then 8 bytes total in the file. Fixes issues 7361 & 7875.
* When trying to write new bytecode, importlib was not catching the IOErrorBrett Cannon2009-11-071-0/+26
| | | | | | | thrown if the file happened to be read-only to keep the failure silent. Fixes issue #7187. Thanks, Dave Malcolm for the report and analysis of the problem.
* Use tempfile.mkdtemp() instead of tempfile.tempdir for where importlib placesBrett Cannon2009-11-051-11/+4
| | | | | | | source files for tests. Allows for concurrent execution of the tests by preventing various executions from trampling each other. Closes issue #7248.
* importlib.test.source.util referenced variables in the 'finally' part of aBrett Cannon2009-11-051-2/+6
| | | | try/finally which may not have been set.
* Rework importlib benchmarks so that they measure number of executions within aBrett Cannon2009-09-031-51/+52
| | | | | | | | second instead of some fixed number. Keeps benchmark faster by putting a cap on total execution time. Before a run using importlib took longer by some factor, but now it takes roughly the same amount of time as using the built-in __import__.
* Clarify why test_import is failing under importlib.Brett Cannon2009-08-301-2/+3
|
* Trying to import a submodule from another module and not a package was raisingBrett Cannon2009-08-302-3/+6
| | | | | | AttributeError in importlib when it should be an ImportError. Found when running importlib against test_runpy.
* test_pep3120 is no longer a problem for importlib as the test was tweaked.Brett Cannon2009-08-301-1/+0
|
* When the globals argument to importlib.__import__() contained any value forBrett Cannon2009-08-301-7/+13
| | | | | | | | __package__, it was used. This was incorrect since it could be set to None to represent the fact that a proper value was unknown. Now None will trigger the calculation for __package__. Discovered when running importlib against test_importhooks.
* Turn on verbose2 for importlib.test.regrtest so as to see failures when they ↵Brett Cannon2009-08-301-2/+1
| | | | occur.
* Raise TypeError if the name given to importlib.__import__() lacks an rpartitionBrett Cannon2009-08-302-1/+22
| | | | | | | | attribute. Was throwing AttributeError before. Discovered when running test_builtin against importlib. This exception change is specific to importlib.__import__() and does not apply to import_module() as it is being done for compatibility reasons only.
* Fix the importlib_only test decorator to work again; don't capture the flag ↵Brett Cannon2009-08-301-1/+3
| | | | variable as it might change later.
* Use the public API, not a private one.Brett Cannon2009-08-301-1/+1
|
* Allow importlib.__import__ to accept any iterable for fromlist. Discovered whenBrett Cannon2009-08-301-2/+9
| | | | running importlib against test___all__.
* Provide module docstrings for the two main test drivers in importlib thatBrett Cannon2009-08-302-2/+11
| | | | | explain what they are for and how to use command-line arguments to tweak semantics.
* Tweak importlib.test.regrtest to only specify the implicit tests to excludeBrett Cannon2009-08-301-4/+6
| | | | | when running entire test suite. Allows normal command-line arguments normally given to test.regrtest to work (e.g. specifying a single test).
* Have importlib raise ImportError if None is found in sys.modules. This matchesBrett Cannon2009-08-301-4/+14
| | | | current import semantics.
* Add a test file to importlib that runs regrtest using importlib.__import__.Brett Cannon2009-08-271-0/+33
| | | | | | | | | The file must be run using runpy. Certain tests are currently excluded from being run as they have known failures based on golden value checks that fail for various reasons (typically because __loader__ is not expected to be set on modules). Running the tests with this file does discover some incompatibilites in importlib that will be fixed in the near future (as noted currently in the docstring).
* Add support for a --builtin argument to importlib.test to trigger runningBrett Cannon2009-08-271-0/+5
| | | | import-specific tests with __import__ instead of importlib.
* Move over to using assertRaises as a context manager for importlib tests.Brett Cannon2009-08-279-24/+36
| | | | | Obviously one shouldn't do whole sale conversions like this, but I was already going through the test code and I was bored at the airport.
* Make __package__ setting tests specific to importlib. Also move to ↵Brett Cannon2009-08-271-4/+5
| | | | assertRaises context manager.
* Move a test-skipping decorator over to unittest.skipIf.Brett Cannon2009-08-271-10/+3
|
* Implement the PEP 302 protocol for get_filename() asBrett Cannon2009-07-202-4/+57
| | | | | | importlib.abc.ExecutionLoader. PyLoader now inherits from this ABC instead of InspectLoader directly. Both PyLoader and PyPycLoader provide concrete implementations of get_filename in terms of source_path and bytecode_path.
* Importlib's documentation said that importlib.abc.PyLoader inherited fromBrett Cannon2009-07-201-14/+61
| | | | | | | | | importlib.abc.ResourceLoader, when in fact it did not. Fixed the ABC to inherit as documented. This doesn't introduce an backwards-incompatiblity as the code in PyLoader already required the single method ResourceLoader defined as an abstract method.
* Remove custom test-skipping code in importlib tests for unittest code.Brett Cannon2009-07-201-13/+14
|
* Some tests in importlib.test.source.test_abc_loader were testing what happensBrett Cannon2009-07-201-8/+16
| | | | | | | | when a loader is given missing or bad code object bytecode. Unfortunately an exception related to source paths was masking what the proper exception to test should be. Making the test explicitly set the environment fixed the test. The code being test was not affected.
* Update importlib.test.source.test_abc_loader to new features added in Python ↵Brett Cannon2009-07-191-17/+19
| | | | 3.1.
* Importlib was using custom code to discover all test modules in importlib.test.Brett Cannon2009-07-152-31/+14
| | | | | This has now been removed in favor of using unittest's test discovery code in TestLoader.discover().
* Remove unused import for function that no longer exists.R. David Murray2009-07-011-1/+0
|
* convert old fail* assertions to assert*Benjamin Peterson2009-06-3019-85/+85
|
* Fixup/simplify another nested context manager.Raymond Hettinger2009-06-121-6/+3
|
* Tests for case-senstivity were not being skipped for darwin when installed on aBrett Cannon2009-05-116-45/+37
| | | | | | | case-sensitive filesystems -- which is not the default case. Along the way also fixed the skipping of tests when sys.dont_write_bytecode is true. Closes issue #5442 again.
* fix name againBenjamin Peterson2009-04-041-1/+1
|