Code Duplication    Length = 15-27 lines in 2 locations

didyoumean/didyoumean_sugg_tests.py 2 locations

@@ 1301-1327 (lines=27) @@
1298
            'convert to list to edit the list',
1299
            from_version(version))
1300
1301
    def test_assignment_to_string(self):
1302
        """Trying to assign to string does not work."""
1303
        code = "s = 'abc'\ns[1] = 'd'"
1304
        good_code = "s = 'abc'\nl = list(s)\nl[1] = 'd'\ns = ''.join(l)"
1305
        self.runs(good_code)
1306
        self.throws(
1307
            code,
1308
            OBJECTDOESNOTSUPPORT,
1309
            'convert to list to edit the list and use "join()" on the list')
1310
1311
    def test_deletion_from_string(self):
1312
        """Delete from string does not work."""
1313
        code = "s = 'abc'\ndel s[1]"
1314
        good_code = "s = 'abc'\nl = list(s)\ndel l[1]\ns = ''.join(l)"
1315
        self.runs(good_code)
1316
        self.throws(
1317
            code,
1318
            OBJECTDOESNOTSUPPORT,
1319
            'convert to list to edit the list and use "join()" on the list')
1320
1321
    def test_object_indexing(self):
1322
        """Index from object does not work if __getitem__ is not defined."""
1323
        version = (3, 0)
1324
        code = "{0}[0]"
1325
        good_code, set_code, custom_code = \
1326
            format_str(code, '"a_string"', "set()", "FoobarClass()")
1327
        self.runs(good_code)
1328
        sugg_for_iterable = 'convert to list first or use the iterator ' \
1329
            'protocol to get the different elements'
1330
        self.throws(set_code,
@@ 897-911 (lines=15) @@
894
        code_str, code_string = format_str(code, 'str', 'string')
895
        code_str2 = 'str.maketrans'  # No 'string' import
896
        self.throws(code_str, ATTRIBUTEERROR, [], up_to_version(version))
897
        self.throws(code_str2, ATTRIBUTEERROR, [], up_to_version(version))
898
        self.runs(code_string, up_to_version(version))
899
        self.throws(code_string, ATTRIBUTEERROR, [], from_version(version))
900
        self.runs(code_str, from_version(version))
901
        self.runs(code_str2, from_version(version))
902
903
    def test_join(self):
904
        """Test what happens when join is used incorrectly.
905
906
        This can be frustrating to call join on an iterable instead of a
907
        string.
908
        """
909
        code = "['a', 'b'].join('-')"
910
        self.throws(code, ATTRIBUTEERROR, "'my_string.join(list)'")
911
912
    def test_set_dict_comprehension(self):
913
        """{} creates a dict and not an empty set leading to errors."""
914
        # NICE_TO_HAVE