Skip to content

Commit 583af54

Browse files
authored
Merge pull request #79 from bugout-dev/fix-usage-full-path
Fixed bug with names displayed in "usage" entries in locust output
2 parents 1d0e58a + 66cbdc3 commit 583af54

7 files changed

Lines changed: 56 additions & 7 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: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,11 +205,12 @@ 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:
212-
definition = RawDefinition(
213+
origin_definition = RawDefinition(
213214
name=qualification,
214215
change_type=self.context_type.value,
215216
line=node.lineno,
@@ -218,7 +219,21 @@ def visit_Attribute(self, node: ast.Attribute) -> None:
218219
end_offset=node.end_col_offset,
219220
parent=parent,
220221
)
221-
self.definitions.append(definition)
222+
# Replace prefix with qualification in final_component
223+
name = final_component.replace(
224+
cumulative_component, qualification, 1
225+
)
226+
definition = RawDefinition(
227+
name=name,
228+
change_type=self.context_type.value,
229+
line=node.lineno,
230+
offset=node.col_offset,
231+
end_line=node.end_lineno,
232+
end_offset=node.end_col_offset,
233+
parent=parent,
234+
)
235+
236+
self.definitions.extend([origin_definition, definition])
222237

223238
def reset(self):
224239
self.scope = []

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: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,16 @@
135135
"changed_lines": 1,
136136
"total_lines": 1,
137137
"parent": {}
138+
},
139+
{
140+
"name": "argparse.ArgumentParser",
141+
"change_type": "usage",
142+
"filepath": "sample.py",
143+
"revision": "0838585",
144+
"line": 7,
145+
"changed_lines": 1,
146+
"total_lines": 1,
147+
"parent": {}
138148
}
139149
]
140150
}

tests/fixtures/test_parse_dependencies.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,16 @@
321321
"total_lines": 1,
322322
"parent": {}
323323
},
324+
{
325+
"name": "json.dumps",
326+
"change_type": "usage",
327+
"filepath": "mod/submod/print.py",
328+
"revision": "04cec01",
329+
"line": 5,
330+
"changed_lines": 1,
331+
"total_lines": 1,
332+
"parent": {}
333+
},
324334
{
325335
"name": "..value.VALUE",
326336
"change_type": "usage",

tests/fixtures/test_render.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,14 @@
2626
"changed_lines": 1,
2727
"total_lines": 1,
2828
"children": []
29+
},
30+
{
31+
"name": "argparse.ArgumentParser",
32+
"type": "usage",
33+
"line": 7,
34+
"changed_lines": 1,
35+
"total_lines": 1,
36+
"children": []
2937
}
3038
]
3139
}

0 commit comments

Comments
 (0)