Skip to content

Commit 36e239d

Browse files
committed
Fixed bug with names displayed in "usage" entries in locust output
In Python parser.
1 parent 1d0e58a commit 36e239d

7 files changed

Lines changed: 20 additions & 9 deletions

File tree

locust/cli.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,7 @@
22
The Locust CLI
33
"""
44
import argparse
5-
import json
6-
import os
75
import sys
8-
from typing import Any, Dict, Optional
96

107
from . import git
118
from . import parse
@@ -18,6 +15,13 @@ def generate_argument_parser() -> argparse.ArgumentParser:
1815
description="Locust: Analyze Python code across git references",
1916
epilog=f"Version {version.LOCUST_VERSION}",
2017
)
18+
parser.add_argument(
19+
"-v",
20+
"--version",
21+
action="version",
22+
version=f"locust {version.LOCUST_VERSION}",
23+
help="Print the locust version",
24+
)
2125
git.populate_argument_parser(parser)
2226
parse.populate_argument_parser(parser)
2327
render.populate_argument_parser(parser)

locust/parse.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,12 +205,17 @@ def visit_Attribute(self, node: ast.Attribute) -> None:
205205
]
206206
symbols = self._current_symbols()
207207
parent = self._current_scope_parent()
208+
final_component = cumulative_components[-1]
208209
for cumulative_component in cumulative_components:
209210
qualifications = symbols.get(cumulative_component)
210211
if qualifications:
211212
for qualification in qualifications:
213+
# Replace prefix with qualification in final_component
214+
name = final_component.replace(
215+
cumulative_component, qualification, 1
216+
)
212217
definition = RawDefinition(
213-
name=qualification,
218+
name=name,
214219
change_type=self.context_type.value,
215220
line=node.lineno,
216221
offset=node.col_offset,

locust/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
LOCUST_VERSION = "0.3.1"
1+
LOCUST_VERSION = "0.3.2"
22

33

44
def main():

test.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,6 @@ then
1515
exit 1
1616
fi
1717

18-
python -m unittest discover -v
18+
TEST_COMMAND=${@:-"discover -v"}
19+
20+
python -m unittest $TEST_COMMAND

tests/fixtures/test_parse.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@
127127
"parent": {}
128128
},
129129
{
130-
"name": "argparse",
130+
"name": "argparse.ArgumentParser",
131131
"change_type": "usage",
132132
"filepath": "sample.py",
133133
"revision": "0838585",

tests/fixtures/test_parse_dependencies.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@
312312
"parent": {}
313313
},
314314
{
315-
"name": "json",
315+
"name": "json.dumps",
316316
"change_type": "usage",
317317
"filepath": "mod/submod/print.py",
318318
"revision": "04cec01",

tests/fixtures/test_render.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"children": []
2121
},
2222
{
23-
"name": "argparse",
23+
"name": "argparse.ArgumentParser",
2424
"type": "usage",
2525
"line": 7,
2626
"changed_lines": 1,

0 commit comments

Comments
 (0)