|
@@ 1675-1694 (lines=20) @@
|
| 1672 |
|
code2 = code + end |
| 1673 |
|
for op in ('-', '+'): |
| 1674 |
|
typo, sugg = 2 * op, op + '=1' |
| 1675 |
|
bad_code, good_code = format_str(code + end, typo, sugg) |
| 1676 |
|
self.throws(bad_code, INVALIDSYNTAX) |
| 1677 |
|
self.runs(good_code) |
| 1678 |
|
|
| 1679 |
|
def test_wrong_bool_operator(self): |
| 1680 |
|
"""Trying to use '&&' or '||'.""" |
| 1681 |
|
code = 'True {0} False' |
| 1682 |
|
for typo, sugg in (('&&', 'and'), ('||', 'or')): |
| 1683 |
|
bad_code, good_code = format_str(code, typo, sugg) |
| 1684 |
|
self.throws(bad_code, INVALIDSYNTAX, "'" + sugg + "'") |
| 1685 |
|
self.runs(good_code) |
| 1686 |
|
|
| 1687 |
|
def test_import_future_not_first(self): |
| 1688 |
|
"""Test what happens when import from __future__ is not first.""" |
| 1689 |
|
code = 'a = 8/7\nfrom __future__ import division' |
| 1690 |
|
self.throws(code, FUTUREFIRST) |
| 1691 |
|
|
| 1692 |
|
def test_import_future_not_def(self): |
| 1693 |
|
"""Should be 'division'.""" |
| 1694 |
|
code = 'from __future__ import {0}' |
| 1695 |
|
typo, sugg = 'divisio', 'division' |
| 1696 |
|
bad_code, good_code = format_str(code, typo, sugg) |
| 1697 |
|
self.throws(bad_code, FUTFEATNOTDEF, "'" + sugg + "'") |
|
@@ 920-939 (lines=20) @@
|
| 917 |
|
# NICE_TO_HAVE |
| 918 |
|
version = (3, 0) |
| 919 |
|
code = 'FoobarClass().some_method.{0}' |
| 920 |
|
attributes = [('im_func', '__func__', []), |
| 921 |
|
('im_self', '__self__', []), |
| 922 |
|
('im_class', '__self__.__class__', ["'__class__'"])] |
| 923 |
|
for (old_att, new_att, sugg) in attributes: |
| 924 |
|
old_code, new_code = format_str(code, old_att, new_att) |
| 925 |
|
self.runs(old_code, up_to_version(version)) |
| 926 |
|
self.throws(old_code, ATTRIBUTEERROR, sugg, from_version(version)) |
| 927 |
|
self.runs(new_code) |
| 928 |
|
|
| 929 |
|
def test_moved_between_str_string(self): |
| 930 |
|
"""Some methods have been moved from string to str.""" |
| 931 |
|
# NICE_TO_HAVE |
| 932 |
|
version1 = (3, 0) |
| 933 |
|
version2 = (3, 5) |
| 934 |
|
code = 'import string\n{0}.maketrans' |
| 935 |
|
code_str, code_string = format_str(code, 'str', 'string') |
| 936 |
|
code_str2 = 'str.maketrans' # No 'string' import |
| 937 |
|
code_str3 = 'import string as my_string\nstr.maketrans' # Named import |
| 938 |
|
self.throws(code_str, ATTRIBUTEERROR, [], up_to_version(version1)) |
| 939 |
|
self.throws(code_str2, ATTRIBUTEERROR, [], up_to_version(version1)) |
| 940 |
|
self.throws(code_str3, ATTRIBUTEERROR, [], up_to_version(version1)) |
| 941 |
|
self.runs(code_string, up_to_version(version1)) |
| 942 |
|
self.throws(code_string, ATTRIBUTEERROR, [], (version1, version2)) |