Unit tests working, with pkgutil not broken, on Python 3.3!!!

This commit is contained in:
Elf M. Sternberg 2016-06-05 09:15:12 -07:00
parent 2ad2b0e4fa
commit 613db3c2f6
8 changed files with 47 additions and 51 deletions

1
.gitignore vendored
View File

@ -8,3 +8,4 @@ bower_components
*.egg-info
build/*
.cache/*
.tox/*

View File

@ -13,7 +13,7 @@ Report Bugs
~~~~~~~~~~~
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:
@ -37,15 +37,15 @@ Look through the GitHub issues for features. Anything tagged with
Write Documentation
~~~~~~~~~~~~~~~~~~~
py-polymorphic-loader could always use more documentation, whether as
part of the official py-polymorphic-loader docs, in docstrings, or even
polyloader could always use more documentation, whether as
part of the official polyloader docs, in docstrings, or even
on the web in blog posts, articles, and such.
Submit Feedback
~~~~~~~~~~~~~~~
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:
@ -57,15 +57,15 @@ If you are proposing a feature:
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.
1. Fork the py-polymorphic-loader repo on GitHub.
1. Fork the polyloader repo on GitHub.
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
virtualenvwrapper installed, this is how you set up your fork for
@ -73,8 +73,8 @@ local development.
::
$ mkvirtualenv py-polymorphic-loader
$ cd py-polymorphic-loader/
$ mkvirtualenv polyloader
$ cd polyloader/
$ python setup.py develop
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
$ 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.
3. The pull request should work for Python 2.6, 2.7, 3.3, 3.4 and 3.5,
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.
Tips
@ -125,4 +125,4 @@ Tips
To run a subset of tests:
$ py.test tests.test\_py-polymorphic-loader
$ py.test tests.test\_polyloader

View File

@ -174,5 +174,5 @@ def install(compiler, suffixes):
ExtendedSourceFileLoader.get_extended_suffixes_inclusive())
sys.path_hooks[fpos] = ExtendedFileFinder.path_hook(*supported_loaders)
iter_importer_modules.register(ExtendedFileFinder, ExtendedFileFinder.iter_modules)
if sys.path[0] !== "":
if sys.path[0] != "":
sys.path.insert(0, "")

View File

@ -31,7 +31,7 @@ setup(
author_email='elf.sternberg@gmail.com',
url='https://github.com/elfsternberg/polyloader',
packages=[
'py-polymorphic-loader',
'polyloader',
],
package_dir={'polyloader': 'polyloader'},
include_package_data=True,

View File

@ -0,0 +1 @@
Test Two

View File

@ -0,0 +1 @@
Test Three

View File

@ -2,58 +2,51 @@
# -*- coding: utf-8 -*-
"""
test_py-polymorphic-loader
test_polyloader
----------------------------------
Tests for `py-polymorphic-loader` module.
Tests for `polyloader` module.
"""
import pytest
from polyloader import polyloader
from py_polymorphic_loader import polymorph
# Note that these compilers don't actually load anything out of the
# Note that these compilers don't actually load much out of the
# source files. That's not the point. The point is to show that the
# correct compiler has been found for a given extension.
def compiler2(filename):
return compile("result='Success for %s'" % (filename), filename, "exec")
def compiler3(filename):
return compile("result='Success for %s'" % (filename), filename, "exec")
def compiler(pt):
def _compiler(source_path, modulename):
with open(source_path, "r") as file:
return compile("result='Success for %s: %s'" % (pt, file.readline().rstrip()), modulename, "exec")
return _compiler
class Test_Polymorph_1(object):
def test_import1(self):
import polytestmix
polytestmix.install(compiler2, ['.2'])
polytestmix.install(compiler3, ['.3'])
assert(polytestmix.test2.result = "Success for test2")
assert(polytestmix.test3.result = "Success for test3")
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")
polyloader.install(compiler("2"), ['.2'])
polyloader.install(compiler("3"), ['.3'])
from .polytestmix import test2
from .polytestmix import test3
assert(test2.result == "Success for 2: Test Two")
assert(test3.result == "Success for 3: Test Three")
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):
import polytestmix.test3
polytestmix.install(compiler2, ['.2'])
polytestmix.install(compiler3, ['.3'])
target_dir = os.path.join('.', 'polytestmix')
files = set([name for _, name, is_pkg in pkgutil.iter_modules([targetdir])
import os
import pkgutil
import inspect
polyloader.install(compiler("2"), ['.2'])
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('_')])
assert(files == set(['test2.2', 'test3.3', 'test1.py']))
assert(modules == set(['test1', 'test2', 'test3']))

View File

@ -3,7 +3,7 @@ envlist = py26, py27, py33, py34, py35
[testenv]
setenv =
PYTHONPATH = {toxinidir}:{toxinidir}/py-polymorphic-loader
PYTHONPATH = {toxinidir}:{toxinidir}/polyloader
deps =
-r{toxinidir}/requirements_dev.txt
commands =