Code Duplication    Length = 13-17 lines in 3 locations

didyoumean/didyoumean_sugg_tests.py 3 locations

@@ 1574-1590 (lines=17) @@
1571
        good_code, bad_code1, bad_code2 = format_str(code2, '', '2', 'foo=2')
1572
        self.runs(good_code)
1573
        self.throws(bad_code1, NBARGERROR)
1574
        self.throws(bad_code2, NBARGERROR, interpreters='pypy')
1575
        self.throws(bad_code2, NOKWARGS, sugg, interpreters='cpython')
1576
        # The explanation is only relevant for C functions
1577
        code3 = 'def func_no_arg(n):\n\tpass\nfunc_no_arg({0}2)'
1578
        good_code, good_code2, bad_code = format_str(code3, '', 'n=', 'foo=')
1579
        self.runs(good_code)
1580
        self.runs(good_code2)
1581
        self.throws(bad_code, UNEXPECTEDKWARG)
1582
1583
    def test_iter_cannot_be_interpreted_as_int(self):
1584
        """Trying to call `range(len(iterable))` (bad) and forget the len."""
1585
        before, after = before_and_after((3, 0))
1586
        bad_code = 'range([0, 1, 2])'
1587
        good_code = 'range(len([0, 1, 2]))'
1588
        sugg = "'len(list)'"
1589
        self.runs(good_code)
1590
        self.throws(bad_code, INTEXPECTED, sugg, before)
1591
        self.throws(bad_code, CANNOTBEINTERPRETED, sugg, after)
1592
1593
    RANGE_CODE_TEMPLATES = [
@@ 1504-1518 (lines=15) @@
1501
        """Mix of previous tests but with more objects defined.
1502
1503
        Non-function object with same same as the function tested are defined
1504
        to ensure that things do work fine.
1505
        """
1506
        code = 'func = "not_a_func"\nclass MyClass:\n\tdef func(self, a):' \
1507
               '\n\t\tpass\nMyClass().func({0}=1)'
1508
        bad_code, good_code = format_str(code, 'babar', 'a')
1509
        self.throws(bad_code, UNEXPECTEDKWARG)
1510
        self.runs(good_code)
1511
1512
    def test_keyword_builtin(self):
1513
        """A few builtins (like int()) have a different error message."""
1514
        # NICE_TO_HAVE
1515
        # 'max', 'input', 'len', 'abs', 'all', etc have a specific error
1516
        # message and are not relevant here
1517
        before, after = before_and_after((3, 7))
1518
        for builtin, kwarg in [
1519
                ('float', False), ('bool', False),
1520
                ('int', True), ('complex', True)]:
1521
            code = builtin + '(this_doesnt_exist=2)'
@@ 2240-2252 (lines=13) @@
2237
        self.throws(code, UNEXPECTED_OEF, [], before)
2238
        self.throws(code, INVALIDSYNTAX, [], mid)
2239
        self.throws(code, NONLOCALMODULE, [], after)
2240
2241
    def test_octal_literal(self):
2242
        """Syntax for octal liberals has changed."""
2243
        # NICE_TO_HAVE
2244
        before, after = before_and_after((3, 0))
2245
        bad, good = '0720', '0o720'
2246
        self.runs(good)
2247
        self.runs(bad, before)
2248
        self.throws(bad, INVALIDTOKEN, [], after, 'cpython')
2249
        self.throws(bad, INVALIDSYNTAX, [], after, 'pypy')
2250
2251
    def test_extended_unpacking(self):
2252
        """Extended iterable unpacking is added with Python 3."""
2253
        before, after = before_and_after((3, 0))
2254
        code = '(a, *rest, b) = range(5)'
2255
        self.throws(code, INVALIDSYNTAX, [], before)