Unit tests working, with pkgutil not broken, on Python 3.3!!!
This commit is contained in:
parent
2ad2b0e4fa
commit
613db3c2f6
|
@ -8,3 +8,4 @@ bower_components
|
||||||
*.egg-info
|
*.egg-info
|
||||||
build/*
|
build/*
|
||||||
.cache/*
|
.cache/*
|
||||||
|
.tox/*
|
||||||
|
|
|
@ -13,7 +13,7 @@ Report Bugs
|
||||||
~~~~~~~~~~~
|
~~~~~~~~~~~
|
||||||
|
|
||||||
Report bugs at
|
Report bugs at
|
||||||
https://github.com/elfsternberg/py-polymorphic-loader/issues.
|
https://github.com/elfsternberg/polyloader/issues.
|
||||||
|
|
||||||
If you are reporting a bug, please include:
|
If you are reporting a bug, please include:
|
||||||
|
|
||||||
|
@ -37,15 +37,15 @@ Look through the GitHub issues for features. Anything tagged with
|
||||||
Write Documentation
|
Write Documentation
|
||||||
~~~~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
py-polymorphic-loader could always use more documentation, whether as
|
polyloader could always use more documentation, whether as
|
||||||
part of the official py-polymorphic-loader docs, in docstrings, or even
|
part of the official polyloader docs, in docstrings, or even
|
||||||
on the web in blog posts, articles, and such.
|
on the web in blog posts, articles, and such.
|
||||||
|
|
||||||
Submit Feedback
|
Submit Feedback
|
||||||
~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
The best way to send feedback is to file an issue at
|
The best way to send feedback is to file an issue at
|
||||||
https://github.com/elfsternberg/py-polymorphic-loader/issues.
|
https://github.com/elfsternberg/polyloader/issues.
|
||||||
|
|
||||||
If you are proposing a feature:
|
If you are proposing a feature:
|
||||||
|
|
||||||
|
@ -57,15 +57,15 @@ If you are proposing a feature:
|
||||||
Get Started!
|
Get Started!
|
||||||
------------
|
------------
|
||||||
|
|
||||||
Ready to contribute? Here's how to set up py-polymorphic-loader for
|
Ready to contribute? Here's how to set up polyloader for
|
||||||
local development.
|
local development.
|
||||||
|
|
||||||
1. Fork the py-polymorphic-loader repo on GitHub.
|
1. Fork the polyloader repo on GitHub.
|
||||||
2. Clone your fork locally:
|
2. Clone your fork locally:
|
||||||
|
|
||||||
::
|
::
|
||||||
|
|
||||||
$ git clone git@github.com:your_name_here/py-polymorphic-loader.git
|
$ git clone git@github.com:your_name_here/polyloader.git
|
||||||
|
|
||||||
3. Install your local copy into a virtualenv. Assuming you have
|
3. Install your local copy into a virtualenv. Assuming you have
|
||||||
virtualenvwrapper installed, this is how you set up your fork for
|
virtualenvwrapper installed, this is how you set up your fork for
|
||||||
|
@ -73,8 +73,8 @@ local development.
|
||||||
|
|
||||||
::
|
::
|
||||||
|
|
||||||
$ mkvirtualenv py-polymorphic-loader
|
$ mkvirtualenv polyloader
|
||||||
$ cd py-polymorphic-loader/
|
$ cd polyloader/
|
||||||
$ python setup.py develop
|
$ python setup.py develop
|
||||||
|
|
||||||
4. Create a branch for local development:
|
4. Create a branch for local development:
|
||||||
|
@ -90,7 +90,7 @@ local development.
|
||||||
|
|
||||||
::
|
::
|
||||||
|
|
||||||
$ flake8 py-polymorphic-loader tests
|
$ flake8 polyloader tests
|
||||||
$ python setup.py test or py.test
|
$ python setup.py test or py.test
|
||||||
$ tox
|
$ tox
|
||||||
|
|
||||||
|
@ -117,7 +117,7 @@ Before you submit a pull request, check that it meets these guidelines:
|
||||||
the feature to the list in README.rst.
|
the feature to the list in README.rst.
|
||||||
3. The pull request should work for Python 2.6, 2.7, 3.3, 3.4 and 3.5,
|
3. The pull request should work for Python 2.6, 2.7, 3.3, 3.4 and 3.5,
|
||||||
and for PyPy. Check
|
and for PyPy. Check
|
||||||
https://travis-ci.org/elfsternberg/py-polymorphic-loader/pull_requests
|
https://travis-ci.org/elfsternberg/polyloader/pull_requests
|
||||||
and make sure that the tests pass for all supported Python versions.
|
and make sure that the tests pass for all supported Python versions.
|
||||||
|
|
||||||
Tips
|
Tips
|
||||||
|
@ -125,4 +125,4 @@ Tips
|
||||||
|
|
||||||
To run a subset of tests:
|
To run a subset of tests:
|
||||||
|
|
||||||
$ py.test tests.test\_py-polymorphic-loader
|
$ py.test tests.test\_polyloader
|
||||||
|
|
|
@ -174,5 +174,5 @@ def install(compiler, suffixes):
|
||||||
ExtendedSourceFileLoader.get_extended_suffixes_inclusive())
|
ExtendedSourceFileLoader.get_extended_suffixes_inclusive())
|
||||||
sys.path_hooks[fpos] = ExtendedFileFinder.path_hook(*supported_loaders)
|
sys.path_hooks[fpos] = ExtendedFileFinder.path_hook(*supported_loaders)
|
||||||
iter_importer_modules.register(ExtendedFileFinder, ExtendedFileFinder.iter_modules)
|
iter_importer_modules.register(ExtendedFileFinder, ExtendedFileFinder.iter_modules)
|
||||||
if sys.path[0] !== "":
|
if sys.path[0] != "":
|
||||||
sys.path.insert(0, "")
|
sys.path.insert(0, "")
|
||||||
|
|
2
setup.py
2
setup.py
|
@ -31,7 +31,7 @@ setup(
|
||||||
author_email='elf.sternberg@gmail.com',
|
author_email='elf.sternberg@gmail.com',
|
||||||
url='https://github.com/elfsternberg/polyloader',
|
url='https://github.com/elfsternberg/polyloader',
|
||||||
packages=[
|
packages=[
|
||||||
'py-polymorphic-loader',
|
'polyloader',
|
||||||
],
|
],
|
||||||
package_dir={'polyloader': 'polyloader'},
|
package_dir={'polyloader': 'polyloader'},
|
||||||
include_package_data=True,
|
include_package_data=True,
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
Test Two
|
|
@ -0,0 +1 @@
|
||||||
|
Test Three
|
|
@ -2,58 +2,51 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
"""
|
"""
|
||||||
test_py-polymorphic-loader
|
test_polyloader
|
||||||
----------------------------------
|
----------------------------------
|
||||||
|
|
||||||
Tests for `py-polymorphic-loader` module.
|
Tests for `polyloader` module.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
|
from polyloader import polyloader
|
||||||
|
|
||||||
from py_polymorphic_loader import polymorph
|
# Note that these compilers don't actually load much out of the
|
||||||
|
|
||||||
# Note that these compilers don't actually load anything out of the
|
|
||||||
# source files. That's not the point. The point is to show that the
|
# source files. That's not the point. The point is to show that the
|
||||||
# correct compiler has been found for a given extension.
|
# correct compiler has been found for a given extension.
|
||||||
|
|
||||||
def compiler2(filename):
|
def compiler(pt):
|
||||||
return compile("result='Success for %s'" % (filename), filename, "exec")
|
def _compiler(source_path, modulename):
|
||||||
|
with open(source_path, "r") as file:
|
||||||
def compiler3(filename):
|
return compile("result='Success for %s: %s'" % (pt, file.readline().rstrip()), modulename, "exec")
|
||||||
return compile("result='Success for %s'" % (filename), filename, "exec")
|
return _compiler
|
||||||
|
|
||||||
class Test_Polymorph_1(object):
|
class Test_Polymorph_1(object):
|
||||||
def test_import1(self):
|
def test_import1(self):
|
||||||
import polytestmix
|
polyloader.install(compiler("2"), ['.2'])
|
||||||
polytestmix.install(compiler2, ['.2'])
|
polyloader.install(compiler("3"), ['.3'])
|
||||||
polytestmix.install(compiler3, ['.3'])
|
from .polytestmix import test2
|
||||||
assert(polytestmix.test2.result = "Success for test2")
|
from .polytestmix import test3
|
||||||
assert(polytestmix.test3.result = "Success for test3")
|
assert(test2.result == "Success for 2: Test Two")
|
||||||
|
assert(test3.result == "Success for 3: Test Three")
|
||||||
class Test_Polymorph_2(object):
|
|
||||||
def test_import2(self):
|
|
||||||
import polytestmix
|
|
||||||
polytestmix.install(compiler2, ['.2'])
|
|
||||||
polytestmix.install(compiler3, ['.3'])
|
|
||||||
assert(polytestmix.test2.result = "Success for test2")
|
|
||||||
|
|
||||||
class Test_Polymorph_2(object):
|
|
||||||
def test_import2(self):
|
|
||||||
import polytestmix.test3
|
|
||||||
polytestmix.install(compiler2, ['.2'])
|
|
||||||
polytestmix.install(compiler3, ['.3'])
|
|
||||||
assert(polytestmix.test3.result = "Success for test3")
|
|
||||||
|
|
||||||
class Test_Polymorph_Iterator(object):
|
class Test_Polymorph_Iterator(object):
|
||||||
''' The Django Compatibility test. '''
|
''' The Django Compatibility test: Can we load arbitrary modules from a package? '''
|
||||||
def test_iterator(self):
|
def test_iterator(self):
|
||||||
import polytestmix.test3
|
import os
|
||||||
polytestmix.install(compiler2, ['.2'])
|
import pkgutil
|
||||||
polytestmix.install(compiler3, ['.3'])
|
import inspect
|
||||||
target_dir = os.path.join('.', 'polytestmix')
|
polyloader.install(compiler("2"), ['.2'])
|
||||||
files = set([name for _, name, is_pkg in pkgutil.iter_modules([targetdir])
|
polyloader.install(compiler("3"), ['.3'])
|
||||||
|
from .polytestmix import test2
|
||||||
|
from .polytestmix import test3
|
||||||
|
target_dir = os.path.join(
|
||||||
|
os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe()))),
|
||||||
|
'polytestmix')
|
||||||
|
modules = set([name for _, name, is_pkg in pkgutil.iter_modules([target_dir])
|
||||||
if not is_pkg and not name.startswith('_')])
|
if not is_pkg and not name.startswith('_')])
|
||||||
assert(files == set(['test2.2', 'test3.3', 'test1.py']))
|
assert(modules == set(['test1', 'test2', 'test3']))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
2
tox.ini
2
tox.ini
|
@ -3,7 +3,7 @@ envlist = py26, py27, py33, py34, py35
|
||||||
|
|
||||||
[testenv]
|
[testenv]
|
||||||
setenv =
|
setenv =
|
||||||
PYTHONPATH = {toxinidir}:{toxinidir}/py-polymorphic-loader
|
PYTHONPATH = {toxinidir}:{toxinidir}/polyloader
|
||||||
deps =
|
deps =
|
||||||
-r{toxinidir}/requirements_dev.txt
|
-r{toxinidir}/requirements_dev.txt
|
||||||
commands =
|
commands =
|
||||||
|
|
Loading…
Reference in New Issue