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

Commit 1284bff

Browse files
nvollrothlukaradeDavid TentserDavidTen1GideonKoenig
authored
feat: 436 create a json file that integrates the dictionaries from and (#438)
* Added combine Added functionality to merge dictionaries and output to a JSON file * Some changes in the combine methode added test for create_file methode * Comments + Tests Added comments to the code and tested the test * style: apply automatic fixes of linters * Added JSON test file Erzeugte Test JSON File * style: apply automatic fixes of linters * Changed directory in test * Funktionalität extrahiert Funktionalität extrahiert + Test angepasst * style: apply automatic fixes of linters * output path variable correction in combine file * Important comment in combine * style: apply automatic fixes of linters * Documentation in the combine files * style: apply automatic fixes of linters * Datei gelöscht + Kommentare angepasst Die Datei annotations.json wurde gelöscht und Kommentare in combine.py wurden angepasst * style: apply automatic fixes of linters * Typisierung hinzugefügt Typisierung hinzugefügt, Schnittstelle über __init__ definiert, Kommentare bearbeitet Co-Authored-By: nvollroth <[email protected]> * style: apply automatic fixes of linters * Test import korrigiert Test import korrigiert Co-Authored-By: nvollroth <[email protected]> * style: apply automatic fixes of linters Co-authored-by: lukarade <[email protected]> Co-authored-by: nvollroth <[email protected]> Co-authored-by: David Tentser <[email protected]> Co-authored-by: DavidTen1 <[email protected]> Co-authored-by: GideonKoenig <[email protected]> Co-authored-by: lukarade <[email protected]> Co-authored-by: GideonKoenig <[email protected]>
1 parent 95fb2ec commit 1284bff

File tree

4 files changed

+214
-0
lines changed

4 files changed

+214
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
from ._combine import write_json
12
from ._generate_annotations import generate_annotations
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
import argparse
2+
import json
3+
import os
4+
5+
6+
def write_json(output_path: str, constant_path: str, unused_path: str) -> None:
7+
"""
8+
Dient zum Mergen von Unused-Dictionary und Constant-Dictionary und anschließende Erzeugen einer JSON - File,
9+
die das erzeugte Dictionary beinhaltet.
10+
11+
:param output_path: Dateipfad für Output-JSON aus beiden Dictionaries(Unused und Constant)
12+
:param constant_path: Dateipfad zur Constant Annotation File, die eine Constant Dictionary enthält
13+
:param unused_path: Dateipfad zur Unused Annotation File, die eine Unused Dictionary enthält
14+
"""
15+
# Platzhalter für echte Funktion
16+
# unused_dict = find_unused(unused_path)
17+
18+
# entfernen, wenn Funktion aus Issue 433 fertig
19+
unused_dict = {
20+
"sklearn/sklearn.__check_build/raise_build_error": {
21+
"target": "sklearn/sklearn.__check_build/raise_build_error"
22+
}
23+
}
24+
# Platzhalter für echte Funktion
25+
# constant_dict = find_constant(constant_path)
26+
27+
# entfernen, wenn Funktion aus Issue 434 fertig
28+
constant_dict = {
29+
"sklearn/sklearn._config/config_context/assume_finite": {
30+
"target": "sklearn/sklearn._config/config_context/assume_finite",
31+
"defaultType": "boolean",
32+
"defaultValue": True,
33+
},
34+
"sklearn/sklearn._config/config_context/working_memory": {
35+
"target": "sklearn/sklearn._config/config_context/working_memory",
36+
"defaultType": "string",
37+
"defaultValue": "bla",
38+
},
39+
"sklearn/sklearn._config/config_context/print_changed_only": {
40+
"target": "sklearn/sklearn._config/config_context/print_changed_only",
41+
"defaultType": "none",
42+
"defaultValue": None,
43+
},
44+
"sklearn/sklearn._config/config_context/display": {
45+
"target": "sklearn/sklearn._config/config_context/display",
46+
"defaultType": "number",
47+
"defaultValue": "3",
48+
},
49+
}
50+
result_dict = __combine_dictionaries(unused_dict, constant_dict)
51+
52+
with open(os.path.join(output_path, "annotations.json"), "w") as file:
53+
json.dump(
54+
result_dict,
55+
file,
56+
indent=2,
57+
)
58+
59+
60+
def __combine_dictionaries(unused_dict: dict, constant_dict: dict) -> dict:
61+
"""
62+
Funktion, die die Dictionaries kombiniert
63+
:param unused_dict : Dictionary der unused annotations
64+
:param constant_dict : Dictionary der constant annotations
65+
:return result_dict : Kombiniertes Dictionary
66+
"""
67+
68+
result_dict = {
69+
"unused": unused_dict,
70+
"constant": constant_dict,
71+
}
72+
return result_dict
73+
74+
75+
# sollte, sobald final eingebunden wird entfernt werden, da es nicht weiter benötigt wird, dient zZ. nur zur Anschauung
76+
if __name__ == "__main__":
77+
parser = argparse.ArgumentParser(prog="combine")
78+
79+
# Argument 1: outputPath
80+
parser.add_argument(
81+
"outputPath",
82+
metavar="output-filepath",
83+
type=str,
84+
help="paste the location of the output file in here ",
85+
)
86+
# Argument 2: inputPath(Pfad einer Constant-Datei)
87+
parser.add_argument(
88+
"constantPath",
89+
metavar="input-filepath",
90+
type=str,
91+
help='paste the location of the "constant" file in here ',
92+
)
93+
# Argument 3: inputPath(Pfad einer Unused-Datei)
94+
parser.add_argument(
95+
"unusedPath",
96+
metavar="input-filepath",
97+
type=str,
98+
help='paste the location of the "unused" file in here ',
99+
)
100+
# Erzeuge kombinierte JSON-Datei jeweils aus der Constant- und der Unused-Dictionary
101+
args = parser.parse_args() # Argumente werden auf Nutzen als Parameter vorbereitet
102+
write_json(args.outputPath, args.constantPath, args.unusedPath)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"unused": {
3+
"sklearn/sklearn.__check_build/raise_build_error": {
4+
"target": "sklearn/sklearn.__check_build/raise_build_error"
5+
}
6+
},
7+
"constant": {
8+
"sklearn/sklearn._config/config_context/assume_finite": {
9+
"target": "sklearn/sklearn._config/config_context/assume_finite",
10+
"defaultType": "boolean",
11+
"defaultValue": true
12+
},
13+
"sklearn/sklearn._config/config_context/working_memory": {
14+
"target": "sklearn/sklearn._config/config_context/working_memory",
15+
"defaultType": "string",
16+
"defaultValue": "bla"
17+
},
18+
"sklearn/sklearn._config/config_context/print_changed_only": {
19+
"target": "sklearn/sklearn._config/config_context/print_changed_only",
20+
"defaultType": "none",
21+
"defaultValue": null
22+
},
23+
"sklearn/sklearn._config/config_context/display": {
24+
"target": "sklearn/sklearn._config/config_context/display",
25+
"defaultType": "number",
26+
"defaultValue": "3"
27+
}
28+
}
29+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
import json
2+
import os
3+
4+
import package_parser.commands.generate_annotations._combine as comb
5+
import pytest
6+
7+
test_unused_dict = {
8+
"sklearn/sklearn.__check_build/raise_build_error": {
9+
"target": "sklearn/sklearn.__check_build/raise_build_error"
10+
}
11+
}
12+
13+
test_constant_dict = {
14+
"sklearn/sklearn._config/config_context/assume_finite": {
15+
"target": "sklearn/sklearn._config/config_context/assume_finite",
16+
"defaultType": "boolean",
17+
"defaultValue": True,
18+
},
19+
"sklearn/sklearn._config/config_context/working_memory": {
20+
"target": "sklearn/sklearn._config/config_context/working_memory",
21+
"defaultType": "string",
22+
"defaultValue": "bla",
23+
},
24+
"sklearn/sklearn._config/config_context/print_changed_only": {
25+
"target": "sklearn/sklearn._config/config_context/print_changed_only",
26+
"defaultType": "none",
27+
"defaultValue": None,
28+
},
29+
"sklearn/sklearn._config/config_context/display": {
30+
"target": "sklearn/sklearn._config/config_context/display",
31+
"defaultType": "number",
32+
"defaultValue": "3",
33+
},
34+
}
35+
36+
test_combined_dict = {
37+
"unused": {
38+
"sklearn/sklearn.__check_build/raise_build_error": {
39+
"target": "sklearn/sklearn.__check_build/raise_build_error"
40+
}
41+
},
42+
"constant": {
43+
"sklearn/sklearn._config/config_context/assume_finite": {
44+
"target": "sklearn/sklearn._config/config_context/assume_finite",
45+
"defaultType": "boolean",
46+
"defaultValue": True,
47+
},
48+
"sklearn/sklearn._config/config_context/working_memory": {
49+
"target": "sklearn/sklearn._config/config_context/working_memory",
50+
"defaultType": "string",
51+
"defaultValue": "bla",
52+
},
53+
"sklearn/sklearn._config/config_context/print_changed_only": {
54+
"target": "sklearn/sklearn._config/config_context/print_changed_only",
55+
"defaultType": "none",
56+
"defaultValue": None,
57+
},
58+
"sklearn/sklearn._config/config_context/display": {
59+
"target": "sklearn/sklearn._config/config_context/display",
60+
"defaultType": "number",
61+
"defaultValue": "3",
62+
},
63+
},
64+
}
65+
66+
67+
@pytest.mark.parametrize(
68+
"test_unused, test_constant, expected",
69+
[
70+
(test_unused_dict, test_constant_dict, test_combined_dict),
71+
],
72+
)
73+
def test_combine_dictionaries(test_unused, test_constant, expected):
74+
"""
75+
Funktion, die feststellt ob die kombinierte JSON-Datei gleich der gefragten JSON-Datei ist oder nicht
76+
:param test_unused: Unused Dictionary als Parameter
77+
:param test_constant: Constant Dictionary als Parameter
78+
:param expected: gemergte JSON-Datei aus den 2 Dictionaries, die entsteht
79+
"""
80+
81+
eval_dict = comb.__combine_dictionaries(test_unused, test_constant)
82+
assert eval_dict == expected

0 commit comments

Comments
 (0)