Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
591f737
Add typing_extensions subfolder
Michael0x2a Jun 27, 2017
ed2e142
Remove unnecessary gitignore
Michael0x2a Jun 27, 2017
eb1e5d7
Fix flake8 errors; make travis test typing_extensions
Michael0x2a Jun 27, 2017
bded015
Fix tests and lint errors; make run_tests.py Python 3 only
Michael0x2a Jun 27, 2017
449a339
Fix typo in .travis.yml
Michael0x2a Jun 27, 2017
baa6ba7
Try making travis run on each minor version
Michael0x2a Jun 27, 2017
5f55de2
Experiment with removing sys.argv hacks
Michael0x2a Jun 27, 2017
d9d10a5
Correctly use sys.version_info
Michael0x2a Jun 27, 2017
2746fae
Cleanup lingering test changes
Michael0x2a Jun 27, 2017
292deb9
Address parts of code review
Michael0x2a Jul 7, 2017
11e98ee
Fix tests; tweak setup.py text
Michael0x2a Jul 7, 2017
9cc6236
Add missing definitions in Python 2 tests
Michael0x2a Jul 7, 2017
ea77bf9
A little closer
Michael0x2a Jul 7, 2017
5e243ed
Whoops, forgot old-style classes were a thing
Michael0x2a Jul 7, 2017
eac513c
Add check to see if cls.__bases__ is erased
Michael0x2a Jul 7, 2017
ea52ad8
Fix import
Michael0x2a Jul 7, 2017
dd9f31c
Consolidate and document version checks in py3 tests
Michael0x2a Jul 7, 2017
31de561
Test version check pin
Michael0x2a Jul 7, 2017
67a20cb
Special-case quirk with AsyncIterator
Michael0x2a Jul 7, 2017
6987247
Convert readme to RST format; adjust text
Michael0x2a Jul 7, 2017
eab214c
Remove Collections backport
Michael0x2a Jul 8, 2017
11c0fcf
Incorporate speed improvements for typing
Michael0x2a Jul 17, 2017
76cc99d
Respond to 2nd review feedback
Michael0x2a Jul 20, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix tests and lint errors; make run_tests.py Python 3 only
  • Loading branch information
Michael0x2a committed Jul 17, 2017
commit bded0155156d562e44f1b691a606d0d516a8ca5a
2 changes: 2 additions & 0 deletions .flake8-tests
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ ignore =
E701,
E704,
F811,
# Included to allow sys.version_info hack
E402,
# irrelevant plugins
B3,
DW12
Expand Down
9 changes: 7 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@ install:

script:
- export PYTHONPATH=`python -c "import sys; print('python2' if sys.version.startswith('2') else 'src')"`; py.test $PYTHONPATH
- export PYTHONPATH=`python -c "import sys; print('typing_extensions/src_py2' if sys.version.startswith('2') else 'typing_extensions/src_py3')"`; py.test $PYTHONPATH
- if [[ $TRAVIS_PYTHON_VERSION == '3.6' ]]; then cd typing_extensions; python run_tests.py; fi
- if [[ $TRAVIS_PYTHON_VERSION == '3.6' ]]; then
cd typing_extensions
python run_tests.py
fi
- pip setup.py install
export PYTHONPATH=`python -c "import sys; print('typing_extensions/src_py2' if sys.version.startswith('2') else 'typing_extensions/src_py3')"`
py.test $PYTHONPATH
- if [[ $TRAVIS_PYTHON_VERSION == '3.6' ]]; then flake8; fi
- if [[ $TRAVIS_PYTHON_VERSION == '3.6' ]]; then flake8 --config=.flake8-tests src/test_typing.py python2/test_typing.py typing_extensions/src_py2/test_typing_extensions.py typing_extensions/src_py3/test_typing_extensions.py; fi
38 changes: 25 additions & 13 deletions typing_extensions/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,21 +59,33 @@ issues when mixing the differing implementations of modified classes.

## Running tests

There are two different ways to test this module. The first is to simply run
each individual Python interpreter against `test_typing_extensions.py` in the
`src_py2` and `src_py3` folders.
### Python 2 tests

However, because multiple versions of Python for each individual release
can be onerous, you can instead run `run_tests.py` using a single Python
interpreter. The `run_tests.py` file will essentially "modify" the standard
library by changing `PYTHONPATH` to point to individual folders in the
`test_data` repo.
To test Python 2, you should:

1. Install the latest version of typing
2. Navigate into `src_py2` and run `test_typing_extensions.py`

### Python 3 tests

Similarly, to test Python 3, you can:

1. Install the latest version of typing (for Python 3.4 or under)
2. Navigate into `src_py3` and run `test_typing_extensions.py`

However, you would need to repeat this test for each version of Python 3
that has been released since Python 3.5.0 for full coverage.

Since installing 7+ different versions of Python 3 is an onerous requirement,
this module provides a second way of running tests that requires you to only
have the latest version of Python 3 installed on your system:

- Run `py -3 run_tests.py` (for Windows)
- Run `python3 run_tests.py` (for Linux)

The `run_tests.py` file will essentially "modify" the standard library by
changing `PYTHONPATH` to point to individual folders in the `test_data` repo.

Each individual folder contains a snapshot of the source code for the
`collections`, `typing,` and `abc` modules for that given release, letting us
test `typing` against those particular implementations.

`run_tests.py` will assume that you have Python 3.6.1 and a reasonably
modern version of Python 2.7 installed on your system, aliased to
`py -2.7` and `py -3.6` on Windows, and `python` and `python3` on Linux and
Mac.
27 changes: 9 additions & 18 deletions typing_extensions/run_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,12 @@
import sys
import textwrap

CORE_FILES_2 = [
"./src_py2/typing_extensions.py",
"./src_py2/test_typing_extensions.py"
]
CORE_FILES_3 = [
CORE_FILES = [
"./src_py3/typing_extensions.py",
"./src_py3/test_typing_extensions.py"
]
TEST_DIR = "test_data"

if sys.platform.startswith('win32'):
PYTHON2 = "py -2.7"
PYTHON3 = "py -3.6"
else:
PYTHON2 = "python"
PYTHON3 = "python3"


def get_test_dirs() -> List[str]:
"""Get all folders to test inside TEST_DIR."""
Expand Down Expand Up @@ -86,15 +75,17 @@ def main() -> int:
exit_code = 0
for test_dir in test_dirs:
_, version_number = test_dir.split('-')
py2 = version_number.startswith("2")
print("Testing Python {}".format(version_number))
test_version = tuple(map(int, version_number.split('.')))

core_files = CORE_FILES_2 if py2 else CORE_FILES_3
python_exe = PYTHON2 if py2 else PYTHON3
if sys.version_info[0] != test_version[0]:
print("Skipping Python {}".format(version_number))
continue
else:
print("Testing Python {}".format(version_number))

with temp_copy(core_files, test_dir), change_directory(test_dir):
with temp_copy(CORE_FILES, test_dir), change_directory(test_dir):
success, output = run_shell("{} {} {}".format(
python_exe,
sys.executable,
"test_typing_extensions.py",
"PYVERSION.{}".format(version_number)))
if success:
Expand Down
26 changes: 0 additions & 26 deletions typing_extensions/src_py2/test_typing_extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,6 @@
import typing
import typing_extensions

# Override version info
ORIGINAL_VERSION = sys.version_info
if len(sys.argv) >= 2 and sys.argv[-1].startswith("PYVERSION"):
PYTHON_VERSION = tuple(map(int, sys.argv[-1].split('.')[1:]))
sys.version_info = PYTHON_VERSION
OVERRIDING_VERSION = True
else:
PYTHON_VERSION = ORIGINAL_VERSION
OVERRIDING_VERSION = False


class BaseTestCase(TestCase):
def assertIsSubclass(self, cls, class_or_tuple, msg=None):
Expand All @@ -40,22 +30,6 @@ def clear_caches(self):
f()


class EnvironmentTest(BaseTestCase):
@skipUnless(OVERRIDING_VERSION, "Environment tests apply only when overriding")
def test_environment_is_ok(self):
cwd = os.path.abspath(os.getcwd())
def correct_dir(module):
return os.path.abspath(module.__file__).startswith(cwd)

self.assertTrue(correct_dir(abc))
self.assertTrue(correct_dir(collections))
self.assertTrue(correct_dir(typing_extensions))

def test_python_version_is_ok(self):
self.assertTrue(sys.version_info == PYTHON_VERSION)
self.assertTrue(ORIGINAL_VERSION[0] == 2)


class Employee:
pass

Expand Down
24 changes: 12 additions & 12 deletions typing_extensions/src_py3/test_typing_extensions.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
import os
import sys

# Override version info
ORIGINAL_VERSION = sys.version_info
if len(sys.argv) >= 2 and sys.argv[-1].startswith("PYVERSION"):
PYTHON_VERSION = tuple(map(int, sys.argv[-1].split('.')[1:]))
sys.version_info = PYTHON_VERSION
OVERRIDING_VERSION = True
else:
PYTHON_VERSION = ORIGINAL_VERSION
OVERRIDING_VERSION = False

import os
import abc
import contextlib
import collections

from unittest import TestCase, main, skipUnless
from typing import TypeVar, Optional
from typing import T, KT, VT # Not in __all__.
Expand All @@ -21,16 +31,6 @@
TYPING_V3 = sys.version_info >= (3, 5, 3)
TYPING_V4 = sys.version_info >= (3, 6, 1)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We will have TYPING_V5 very soon (but I think it is OK to not include it in this PR, just don't forget to add it later).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do.


# Override version info
ORIGINAL_VERSION = sys.version_info
if len(sys.argv) >= 2 and sys.argv[-1].startswith("PYVERSION"):
PYTHON_VERSION = tuple(map(int, sys.argv[-1].split('.')[1:]))
sys.version_info = PYTHON_VERSION
OVERRIDING_VERSION = True
else:
PYTHON_VERSION = ORIGINAL_VERSION
OVERRIDING_VERSION = False


class BaseTestCase(TestCase):
def assertIsSubclass(self, cls, class_or_tuple, msg=None):
Expand Down
Loading