Skip to content

Commit

Permalink
Add tests for name removed/added in Python versions #9
Browse files Browse the repository at this point in the history
Names are added, names are removed, suggestions are
welcome.
Adding test first because this is already quite
likely to fail.
  • Loading branch information
SylvainDe committed Jul 26, 2015
1 parent 80156f8 commit 7133954
Showing 1 changed file with 72 additions and 0 deletions.
72 changes: 72 additions & 0 deletions didyoumean/didyoumean_sugg_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,11 @@ def test_no_sugg(self):
"""No suggestion."""
self.throws('a = ldkjhfnvdlkjhvgfdhgf', NAMEERROR)

# For added/removed names, following functions with one name
# per functions were added in the early stages of the project.
# In the future, I'd like to have them replaced by something
# a bit more concise using relevant data structure. In the
# meantime, I am keeping both versions because safer is better.
def test_removed_cmp(self):
"""Builtin cmp is removed."""
# NICE_TO_HAVE
Expand Down Expand Up @@ -454,6 +459,73 @@ def test_removed_buffer(self):
self.runs(code, up_to_version(version))
self.throws(code, NAMEERROR, [], from_version(version))

def test_added_2_7(self):
"""Test for names added in 2.7."""
version = (2, 7)
for name in ['memoryview']:
self.runs(name, from_version(version))
self.throws(name, NAMEERROR, [], up_to_version(version))

def test_removed_3_0(self):
"""Test for names removed in 3.0."""
version = (3, 0)
for name, suggs in {
'StandardError': [], # Exception
'apply': [],
'basestring': [],
'buffer': [],
'cmp': [],
'coerce': [],
'execfile': [],
'file': ["'filter' (builtin)"],
'intern': ["'iter' (builtin)", "'sys.intern'"],
'long': [],
'raw_input': ["'input' (builtin)"],
'reduce': ["'reduce' from functools (not imported)"],
'reload': [],
'unichr': [],
'unicode': ["'code' (local)"],
'xrange': ["'range' (builtin)"],
}.items():
self.throws(name, NAMEERROR, suggs, from_version(version))
self.runs(name, up_to_version(version))

def test_added_3_0(self):
"""Test for names added in 3.0."""
version = (3, 0)
for name, suggs in {
'ascii': [],
'ResourceWarning': ["'FutureWarning' (builtin)"],
'__build_class__': [],
}.items():
self.runs(name, from_version(version))
self.throws(name, NAMEERROR, suggs, up_to_version(version))

def test_added_3_3(self):
"""Test for names added in 3.3."""
version = (3, 3)
for name, suggs in {
'BrokenPipeError': [],
'ChildProcessError': [],
'ConnectionAbortedError': [],
'ConnectionError': ["'IndentationError' (builtin)"],
'ConnectionRefusedError': [],
'ConnectionResetError': [],
'FileExistsError': [],
'FileNotFoundError': [],
'InterruptedError': [],
'IsADirectoryError': [],
'NotADirectoryError': [],
'PermissionError': ["'ZeroDivisionError' (builtin)"],
'ProcessLookupError': ["'LookupError' (builtin)"],
'StopAsyncIteration': ["'StopIteration' (builtin)"],
'TimeoutError': [],
'__loader__': [],
'__spec__': [],
}.items():
self.runs(name, from_version(version))
self.throws(name, NAMEERROR, suggs, up_to_version(version))

def test_import_sugg(self):
"""Should import module first."""
module = 'collections'
Expand Down

0 comments on commit 7133954

Please sign in to comment.