(case_setup_dap)
| 2045 | |
| 2046 | |
| 2047 | def test_variables_with_same_name(case_setup_dap): |
| 2048 | with case_setup_dap.test_file("_debugger_case_variables_with_same_name.py") as writer: |
| 2049 | json_facade = JsonFacade(writer) |
| 2050 | |
| 2051 | writer.write_add_breakpoint(writer.get_line_index_with_content("Break here")) |
| 2052 | json_facade.write_make_initial_run() |
| 2053 | |
| 2054 | json_hit = json_facade.wait_for_thread_stopped() |
| 2055 | json_hit = json_facade.get_stack_as_json_hit(json_hit.thread_id) |
| 2056 | |
| 2057 | variables_response = json_facade.get_variables_response(json_hit.frame_id) |
| 2058 | |
| 2059 | variables_references = json_facade.pop_variables_reference(variables_response.body.variables) |
| 2060 | dict_variable_reference = variables_references[0] |
| 2061 | assert isinstance(dict_variable_reference, int_types) |
| 2062 | # : :type variables_response: VariablesResponse |
| 2063 | |
| 2064 | assert variables_response.body.variables == [ |
| 2065 | {"name": "td", "value": "{foo: 'bar', gad: 'zooks', foo: 'bur'}", "type": "dict", "evaluateName": "td"} |
| 2066 | ] |
| 2067 | |
| 2068 | dict_variables_response = json_facade.get_variables_response(dict_variable_reference) |
| 2069 | # Note that we don't have the evaluateName because it's not possible to create a key |
| 2070 | # from the user object to actually get its value from the dict in this case. |
| 2071 | variables = dict_variables_response.body.variables[:] |
| 2072 | |
| 2073 | found_foo = False |
| 2074 | found_foo_with_id = False |
| 2075 | for v in variables: |
| 2076 | if v["name"].startswith("foo"): |
| 2077 | if not found_foo: |
| 2078 | assert v["name"] == "foo" |
| 2079 | found_foo = True |
| 2080 | else: |
| 2081 | assert v["name"].startswith("foo (id: ") |
| 2082 | v["name"] = "foo" |
| 2083 | found_foo_with_id = True |
| 2084 | |
| 2085 | assert found_foo |
| 2086 | assert found_foo_with_id |
| 2087 | |
| 2088 | def compute_key(entry): |
| 2089 | return (entry["name"], entry["value"]) |
| 2090 | |
| 2091 | # Sort because the order may be different on Py2/Py3. |
| 2092 | assert sorted(variables, key=compute_key) == sorted( |
| 2093 | [ |
| 2094 | { |
| 2095 | "name": "foo", |
| 2096 | "value": "'bar'", |
| 2097 | "type": "str", |
| 2098 | "variablesReference": 0, |
| 2099 | "presentationHint": {"attributes": ["rawString"]}, |
| 2100 | }, |
| 2101 | { |
| 2102 | # 'name': 'foo (id: 2699272929584)', In the code above we changed this |
| 2103 | # to 'name': 'foo' for the comparisson. |
| 2104 | "name": "foo", |
nothing calls this directly
no test coverage detected