Code Duplication    Length = 20-20 lines in 2 locations

didyoumean/didyoumean_sugg_tests.py 2 locations

@@ 1675-1694 (lines=20) @@
1672
        self.throws(custom_bad,
1673
                    OBJECTDOESNOTSUPPORT,
1674
                    sugg_imp,
1675
                    from_version(version), 'cython')
1676
        self.runs(custom_good)
1677
1678
    def test_not_callable(self):
1679
        """Sometimes, one uses parenthesis instead of brackets."""
1680
        typo, getitem = '(0)', '[0]'
1681
        for ex, sugg in {
1682
            '[0]': "'list[value]'",
1683
            '{0: 0}': "'dict[value]'",
1684
            '"a"': "'str[value]'",
1685
        }.items():
1686
            self.throws(ex + typo, NOTCALLABLE, sugg)
1687
            self.runs(ex + getitem)
1688
        for ex in ['1', 'set()']:
1689
            self.throws(ex + typo, NOTCALLABLE)
1690
1691
    def test_not_callable_custom(self):
1692
        """One must define __call__ to call custom objects."""
1693
        v3 = (3, 0)
1694
        code = 'o = {0}()\no()'
1695
        bad, good = format_str(code, 'CustomClass', 'CallClass')
1696
        sugg = 'implement "__call__" on CustomClass'
1697
        self.throws(bad, INSTHASNOMETH, [], up_to_version(v3), 'cython')
@@ 920-939 (lines=20) @@
917
            ["'{0}' (but it is supposed to be private)".format(sugg),
918
             "'{0}'".format(sugg2)])
919
        self.runs(bad_sugg)
920
        self.runs(good_sugg)
921
922
    def test_get_on_nondict_cont(self):
923
        """Method get does not exist on all containers."""
924
        code = '{0}().get(0, None)'
925
        dictcode, tuplecode, listcode, setcode = \
926
            format_str(code, 'dict', 'tuple', 'list', 'set')
927
        self.runs(dictcode)
928
        self.throws(setcode, ATTRIBUTEERROR)
929
        for bad_code in tuplecode, listcode:
930
            self.throws(bad_code, ATTRIBUTEERROR,
931
                        "'obj[key]' with a len() check or "
932
                        "try: except: KeyError or IndexError")
933
934
    def test_removed_has_key(self):
935
        """Method has_key is removed from dict."""
936
        code = 'dict().has_key(1)'
937
        new_code = '1 in dict()'
938
        version = (3, 0)
939
        self.runs(code, up_to_version(version))
940
        self.throws(
941
            code,
942
            ATTRIBUTEERROR,