2 Tests for dict duplicate keys Pyflakes behavior.
5 from pyflakes
import messages
as m
6 from pyflakes
.test
.harness
import TestCase
11 def test_duplicate_keys(self
):
13 "{'yes': 1, 'yes': 2}",
14 m
.MultiValueRepeatedKeyLiteral
,
15 m
.MultiValueRepeatedKeyLiteral
,
18 def test_duplicate_keys_bytes_vs_unicode_py3(self
):
19 self
.flakes("{b'a': 1, u'a': 2}")
21 def test_duplicate_values_bytes_vs_unicode_py3(self
):
24 m
.MultiValueRepeatedKeyLiteral
,
25 m
.MultiValueRepeatedKeyLiteral
,
28 def test_multiple_duplicate_keys(self
):
30 "{'yes': 1, 'yes': 2, 'no': 2, 'no': 3}",
31 m
.MultiValueRepeatedKeyLiteral
,
32 m
.MultiValueRepeatedKeyLiteral
,
33 m
.MultiValueRepeatedKeyLiteral
,
34 m
.MultiValueRepeatedKeyLiteral
,
37 def test_duplicate_keys_in_function(self
):
42 f({'yes': 1, 'yes': 2})
44 m
.MultiValueRepeatedKeyLiteral
,
45 m
.MultiValueRepeatedKeyLiteral
,
48 def test_duplicate_keys_in_lambda(self
):
50 "lambda x: {(0,1): 1, (0,1): 2}",
51 m
.MultiValueRepeatedKeyLiteral
,
52 m
.MultiValueRepeatedKeyLiteral
,
55 def test_duplicate_keys_tuples(self
):
57 "{(0,1): 1, (0,1): 2}",
58 m
.MultiValueRepeatedKeyLiteral
,
59 m
.MultiValueRepeatedKeyLiteral
,
62 def test_duplicate_keys_tuples_int_and_float(self
):
64 "{(0,1): 1, (0,1.0): 2}",
65 m
.MultiValueRepeatedKeyLiteral
,
66 m
.MultiValueRepeatedKeyLiteral
,
69 def test_duplicate_keys_ints(self
):
72 m
.MultiValueRepeatedKeyLiteral
,
73 m
.MultiValueRepeatedKeyLiteral
,
76 def test_duplicate_keys_bools(self
):
79 m
.MultiValueRepeatedKeyLiteral
,
80 m
.MultiValueRepeatedKeyLiteral
,
83 def test_duplicate_keys_bools_false(self
):
84 # Needed to ensure 2.x correctly coerces these from variables
86 "{False: 1, False: 2}",
87 m
.MultiValueRepeatedKeyLiteral
,
88 m
.MultiValueRepeatedKeyLiteral
,
91 def test_duplicate_keys_none(self
):
94 m
.MultiValueRepeatedKeyLiteral
,
95 m
.MultiValueRepeatedKeyLiteral
,
98 def test_duplicate_variable_keys(self
):
104 m
.MultiValueRepeatedKeyVariable
,
105 m
.MultiValueRepeatedKeyVariable
,
108 def test_duplicate_variable_values(self
):
115 m
.MultiValueRepeatedKeyLiteral
,
116 m
.MultiValueRepeatedKeyLiteral
,
119 def test_duplicate_variable_values_same_value(self
):
120 # Current behaviour is not to look up variable values. This is to
128 m
.MultiValueRepeatedKeyLiteral
,
129 m
.MultiValueRepeatedKeyLiteral
,
132 def test_duplicate_key_float_and_int(self
):
134 These do look like different values, but when it comes to their use as
135 keys, they compare as equal and so are actually duplicates.
136 The literal dict {1: 1, 1.0: 1} actually becomes {1.0: 1}.
142 m
.MultiValueRepeatedKeyLiteral
,
143 m
.MultiValueRepeatedKeyLiteral
,
146 def test_no_duplicate_key_error_same_value(self
):
151 def test_no_duplicate_key_errors(self
):
156 def test_no_duplicate_keys_tuples_same_first_element(self
):
157 self
.flakes("{(0,1): 1, (0,2): 1}")
159 def test_no_duplicate_key_errors_func_call(self
):
163 test({True: 1, None: 2, False: 1})
166 def test_no_duplicate_key_errors_bool_or_none(self
):
167 self
.flakes("{True: 1, None: 2, False: 1}")
169 def test_no_duplicate_key_errors_ints(self
):
174 def test_no_duplicate_key_errors_vars(self
):
181 def test_no_duplicate_key_errors_tuples(self
):
186 def test_no_duplicate_key_errors_instance_attributes(self
):