Skip to content
This repository was archived by the owner on Jan 19, 2025. It is now read-only.

Commit 514555d

Browse files
author
GideonKoenig
committed
Prepared the test file for the incoming testdata and cleaned some code in the determine_constant_parameters() function.
1 parent d87bcde commit 514555d

File tree

2 files changed

+28
-5
lines changed

2 files changed

+28
-5
lines changed

package-parser/package_parser/commands/generate_annotations/_generate_annotations.py

-4
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,6 @@ def __determine_constant_parameters(usages: UsageStore) -> dict[str, str]:
121121
if n_total_usage == 0 and len(value_usages[parameter_qname].values()) == 0:
122122
continue
123123

124-
usage_key, usage_count = __n_not_set_to_most_common_value(
125-
parameter_qname, usages.function_usages, usages.value_usages
126-
)
127-
128124
if len(usages.value_usages[parameter_qname].keys()) == 1:
129125
result[parameter_qname] = usages.most_common_value(parameter_qname)
130126

package-parser/tests/commands/generate-annotations/test_generate_annotations.py

+28-1
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,35 @@
44
UsageStore
55
)
66

7+
# @Unused annotations should be created for the following declarations:
8+
#
9+
# test.Unused_Class
10+
# test.unused_global_function
11+
# test.Commonly_Used_Class.unused_method
12+
#
13+
# @Constant annotations should be created for the following parameters:
14+
#
15+
# test.commonly_used_global_function.useless_required_parameter (with value 'blup')
16+
# test.commonly_used_global_function.unused_optional_parameter (with value 'bla', i.e. the default value)
17+
# test.commonly_used_global_function.useless_optional_parameter (with value 'bla')
18+
19+
720
def test_determination_of_constant_parameters():
821

9-
usages = UsageStore()
22+
expected = {
23+
("test.commonly_used_global_function.useless_required_parameter", "blup"),
24+
("test.commonly_used_global_function.unused_optional_parameter", "bla"),
25+
("test.commonly_used_global_function.useless_optional_parameter", "bla")
26+
}
27+
28+
base_path_to_data = "~/."
29+
usages_file = ""
30+
31+
with usages_file:
32+
usages_json = json.load(usages_file)
33+
usages = UsageStore.from_json(usages_json)
34+
1035
constant_parameters = __determine_constant_parameters(usages)
1136

37+
assert constant_parameters == expected
38+

0 commit comments

Comments
 (0)