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

feat: 436 create a json file that integrates the dictionaries from and #438

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
a42e1cd
Added combine
nvollroth Apr 11, 2022
a50e008
Some changes in the combine methode
lukarade Apr 11, 2022
b2cccf5
Comments + Tests
nvollroth Apr 11, 2022
59dbb35
style: apply automatic fixes of linters
nvollroth Apr 11, 2022
f1b1034
Added JSON test file
nvollroth Apr 11, 2022
85f11a1
Merge branch '436-create-a-json-file-that-integrates-the-dictionaries…
nvollroth Apr 11, 2022
81681cd
style: apply automatic fixes of linters
nvollroth Apr 11, 2022
0b35412
Changed directory in test
nvollroth Apr 11, 2022
de6bd46
Merge branch '436-create-a-json-file-that-integrates-the-dictionaries…
nvollroth Apr 11, 2022
9a6ff3b
Funktionalität extrahiert
nvollroth Apr 12, 2022
cc7a152
style: apply automatic fixes of linters
nvollroth Apr 12, 2022
d4a09fe
output path variable correction in combine file
Apr 15, 2022
1dbab86
Important comment in combine
Apr 15, 2022
3671dd3
style: apply automatic fixes of linters
DavidTen1 Apr 15, 2022
dfca7d3
Documentation in the combine files
Apr 16, 2022
d0d17e4
style: apply automatic fixes of linters
DavidTen1 Apr 16, 2022
73c4ea2
Merge branch 'main' into 436-create-a-json-file-that-integrates-the-d…
GideonKoenig Apr 17, 2022
109905a
Datei gelöscht + Kommentare angepasst
nvollroth Apr 19, 2022
07a658b
style: apply automatic fixes of linters
nvollroth Apr 19, 2022
6b5a74d
Typisierung hinzugefügt
lukarade Apr 20, 2022
662685f
style: apply automatic fixes of linters
lukarade Apr 20, 2022
254fa15
Test import korrigiert
lukarade Apr 20, 2022
6b5a4f2
Merge branch '436-create-a-json-file-that-integrates-the-dictionaries…
lukarade Apr 20, 2022
956ff32
Merge branch 'main' into 436-create-a-json-file-that-integrates-the-d…
GideonKoenig Apr 21, 2022
974923f
style: apply automatic fixes of linters
GideonKoenig Apr 21, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
from ._combine import write_json
from ._generate_annotations import generate_annotations
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
import argparse
import json
import os


def write_json(output_path: str, constant_path: str, unused_path: str) -> None:
"""
Dient zum Mergen von Unused-Dictionary und Constant-Dictionary und anschließende Erzeugen einer JSON - File,
die das erzeugte Dictionary beinhaltet.

:param output_path: Dateipfad für Output-JSON aus beiden Dictionaries(Unused und Constant)
:param constant_path: Dateipfad zur Constant Annotation File, die eine Constant Dictionary enthält
:param unused_path: Dateipfad zur Unused Annotation File, die eine Unused Dictionary enthält
"""
# Platzhalter für echte Funktion
# unused_dict = find_unused(unused_path)

# entfernen, wenn Funktion aus Issue 433 fertig
unused_dict = {
"sklearn/sklearn.__check_build/raise_build_error": {
"target": "sklearn/sklearn.__check_build/raise_build_error"
}
}
# Platzhalter für echte Funktion
# constant_dict = find_constant(constant_path)

# entfernen, wenn Funktion aus Issue 434 fertig
constant_dict = {
"sklearn/sklearn._config/config_context/assume_finite": {
"target": "sklearn/sklearn._config/config_context/assume_finite",
"defaultType": "boolean",
"defaultValue": True,
},
"sklearn/sklearn._config/config_context/working_memory": {
"target": "sklearn/sklearn._config/config_context/working_memory",
"defaultType": "string",
"defaultValue": "bla",
},
"sklearn/sklearn._config/config_context/print_changed_only": {
"target": "sklearn/sklearn._config/config_context/print_changed_only",
"defaultType": "none",
"defaultValue": None,
},
"sklearn/sklearn._config/config_context/display": {
"target": "sklearn/sklearn._config/config_context/display",
"defaultType": "number",
"defaultValue": "3",
},
}
result_dict = __combine_dictionaries(unused_dict, constant_dict)

with open(os.path.join(output_path, "annotations.json"), "w") as file:
json.dump(
result_dict,
file,
indent=2,
)


def __combine_dictionaries(unused_dict: dict, constant_dict: dict) -> dict:
"""
Funktion, die die Dictionaries kombiniert
:param unused_dict : Dictionary der unused annotations
:param constant_dict : Dictionary der constant annotations
:return result_dict : Kombiniertes Dictionary
"""

result_dict = {
"unused": unused_dict,
"constant": constant_dict,
}
return result_dict


# sollte, sobald final eingebunden wird entfernt werden, da es nicht weiter benötigt wird, dient zZ. nur zur Anschauung
if __name__ == "__main__":
parser = argparse.ArgumentParser(prog="combine")

# Argument 1: outputPath
parser.add_argument(
"outputPath",
metavar="output-filepath",
type=str,
help="paste the location of the output file in here ",
)
# Argument 2: inputPath(Pfad einer Constant-Datei)
parser.add_argument(
"constantPath",
metavar="input-filepath",
type=str,
help='paste the location of the "constant" file in here ',
)
# Argument 3: inputPath(Pfad einer Unused-Datei)
parser.add_argument(
"unusedPath",
metavar="input-filepath",
type=str,
help='paste the location of the "unused" file in here ',
)
# Erzeuge kombinierte JSON-Datei jeweils aus der Constant- und der Unused-Dictionary
args = parser.parse_args() # Argumente werden auf Nutzen als Parameter vorbereitet
write_json(args.outputPath, args.constantPath, args.unusedPath)
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"unused": {
"sklearn/sklearn.__check_build/raise_build_error": {
"target": "sklearn/sklearn.__check_build/raise_build_error"
}
},
"constant": {
"sklearn/sklearn._config/config_context/assume_finite": {
"target": "sklearn/sklearn._config/config_context/assume_finite",
"defaultType": "boolean",
"defaultValue": true
},
"sklearn/sklearn._config/config_context/working_memory": {
"target": "sklearn/sklearn._config/config_context/working_memory",
"defaultType": "string",
"defaultValue": "bla"
},
"sklearn/sklearn._config/config_context/print_changed_only": {
"target": "sklearn/sklearn._config/config_context/print_changed_only",
"defaultType": "none",
"defaultValue": null
},
"sklearn/sklearn._config/config_context/display": {
"target": "sklearn/sklearn._config/config_context/display",
"defaultType": "number",
"defaultValue": "3"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import json
import os

import package_parser.commands.generate_annotations._combine as comb
import pytest

test_unused_dict = {
"sklearn/sklearn.__check_build/raise_build_error": {
"target": "sklearn/sklearn.__check_build/raise_build_error"
}
}

test_constant_dict = {
"sklearn/sklearn._config/config_context/assume_finite": {
"target": "sklearn/sklearn._config/config_context/assume_finite",
"defaultType": "boolean",
"defaultValue": True,
},
"sklearn/sklearn._config/config_context/working_memory": {
"target": "sklearn/sklearn._config/config_context/working_memory",
"defaultType": "string",
"defaultValue": "bla",
},
"sklearn/sklearn._config/config_context/print_changed_only": {
"target": "sklearn/sklearn._config/config_context/print_changed_only",
"defaultType": "none",
"defaultValue": None,
},
"sklearn/sklearn._config/config_context/display": {
"target": "sklearn/sklearn._config/config_context/display",
"defaultType": "number",
"defaultValue": "3",
},
}

test_combined_dict = {
"unused": {
"sklearn/sklearn.__check_build/raise_build_error": {
"target": "sklearn/sklearn.__check_build/raise_build_error"
}
},
"constant": {
"sklearn/sklearn._config/config_context/assume_finite": {
"target": "sklearn/sklearn._config/config_context/assume_finite",
"defaultType": "boolean",
"defaultValue": True,
},
"sklearn/sklearn._config/config_context/working_memory": {
"target": "sklearn/sklearn._config/config_context/working_memory",
"defaultType": "string",
"defaultValue": "bla",
},
"sklearn/sklearn._config/config_context/print_changed_only": {
"target": "sklearn/sklearn._config/config_context/print_changed_only",
"defaultType": "none",
"defaultValue": None,
},
"sklearn/sklearn._config/config_context/display": {
"target": "sklearn/sklearn._config/config_context/display",
"defaultType": "number",
"defaultValue": "3",
},
},
}


@pytest.mark.parametrize(
"test_unused, test_constant, expected",
[
(test_unused_dict, test_constant_dict, test_combined_dict),
],
)
def test_combine_dictionaries(test_unused, test_constant, expected):
"""
Funktion, die feststellt ob die kombinierte JSON-Datei gleich der gefragten JSON-Datei ist oder nicht
:param test_unused: Unused Dictionary als Parameter
:param test_constant: Constant Dictionary als Parameter
:param expected: gemergte JSON-Datei aus den 2 Dictionaries, die entsteht
"""

eval_dict = comb.__combine_dictionaries(test_unused, test_constant)
assert eval_dict == expected