From b29b0fb5dcc24998598d4cb437810d68da9bed78 Mon Sep 17 00:00:00 2001 From: Lars Reimann Date: Sat, 16 Apr 2022 15:12:04 +0200 Subject: [PATCH 1/5] test: api data for unused annotations --- package-parser/tests/data/unused/api.json | 129 ++++++++++++++++++++++ 1 file changed, 129 insertions(+) create mode 100644 package-parser/tests/data/unused/api.json diff --git a/package-parser/tests/data/unused/api.json b/package-parser/tests/data/unused/api.json new file mode 100644 index 000000000..3164ee5fb --- /dev/null +++ b/package-parser/tests/data/unused/api.json @@ -0,0 +1,129 @@ +{ + "distribution": "test", + "package": "test", + "version": "0.0.1", + "modules": [ + { + "name": "test", + "imports": [], + "from_imports": [], + "classes": [ + "test.Unused_Class", + "test.Rarely_Used_Class", + "test.Commonly_Used_Class" + ], + "functions": [ + "test.unused_global_function", + "test.rarely_used_global_function", + "test.commonly_used_global_function" + ] + } + ], + "classes": [ + { + "name": "Unused_Class", + "qname": "test.Unused_Class", + "decorators": [], + "superclasses": [], + "methods": [] + }, + { + "name": "Rarely_Used_Class", + "qname": "test.Rarely_Used_Class", + "decorators": [], + "superclasses": [], + "methods": [] + }, + { + "name": "Commonly_Used_Class", + "qname": "test.Commonly_Used_Class", + "decorators": [], + "superclasses": [], + "methods": [ + "test.Commonly_Used_Class.unused_method", + "test.Commonly_Used_Class.rarely_used_method", + "test.Commonly_Used_Class.commonly_used_method" + ] + } + ], + "functions": [ + { + "name": "unused_global_function", + "unique_name": "unused_global_function", + "qname": "test.unused_global_function", + "unique_qname": "test.unused_global_function", + "decorators": [], + "parameters": [], + "results": [], + "is_public": true, + "description": "", + "docstring": "", + "source_code": "" + }, + { + "name": "rarely_used_global_function", + "unique_name": "rarely_used_global_function", + "qname": "test.rarely_used_global_function", + "unique_qname": "test.rarely_used_global_function", + "decorators": [], + "parameters": [], + "results": [], + "is_public": true, + "description": "", + "docstring": "", + "source_code": "" + }, + { + "name": "commonly_used_global_function", + "unique_name": "commonly_used_global_function", + "qname": "test.commonly_used_global_function", + "unique_qname": "test.commonly_used_global_function", + "decorators": [], + "parameters": [], + "results": [], + "is_public": true, + "description": "", + "docstring": "", + "source_code": "" + }, + { + "name": "unused_method", + "unique_name": "unused_method", + "qname": "test.Commonly_Used_Class.unused_method", + "unique_qname": "test.Commonly_Used_Class.unused_method", + "decorators": [], + "parameters": [], + "results": [], + "is_public": true, + "description": "", + "docstring": "", + "source_code": "" + }, + { + "name": "rarely_used_method", + "unique_name": "rarely_used_method", + "qname": "test.Commonly_Used_Class.rarely_used_method", + "unique_qname": "test.Commonly_Used_Class.rarely_used_method", + "decorators": [], + "parameters": [], + "results": [], + "is_public": true, + "description": "", + "docstring": "", + "source_code": "" + }, + { + "name": "commonly_used_method", + "unique_name": "commonly_used_method", + "qname": "test.Commonly_Used_Class.commonly_used_method", + "unique_qname": "test.Commonly_Used_Class.commonly_used_method", + "decorators": [], + "parameters": [], + "results": [], + "is_public": true, + "description": "", + "docstring": "", + "source_code": "" + } + ] +} From 70fb9dc45aa546310052431040e706dc0f0e0a3a Mon Sep 17 00:00:00 2001 From: Lars Reimann Date: Sat, 16 Apr 2022 15:28:11 +0200 Subject: [PATCH 2/5] test: usage data for unused annotations --- package-parser/tests/data/unused/usages.json | 113 +++++++++++++++++++ 1 file changed, 113 insertions(+) create mode 100644 package-parser/tests/data/unused/usages.json diff --git a/package-parser/tests/data/unused/usages.json b/package-parser/tests/data/unused/usages.json new file mode 100644 index 000000000..39a6d40c6 --- /dev/null +++ b/package-parser/tests/data/unused/usages.json @@ -0,0 +1,113 @@ +{ + "class_usages": { + "test.Unused_Class": [], + "test.Rarely_Used_Class": [ + { + "file": "test.py", + "line": 1, + "column": 1 + } + ], + "test.Commonly_Used_Class": [ + { + "file": "test.py", + "line": 1, + "column": 1 + }, + { + "file": "test.py", + "line": 1, + "column": 1 + }, + { + "file": "test.py", + "line": 1, + "column": 1 + }, + { + "file": "test.py", + "line": 1, + "column": 1 + }, + { + "file": "test.py", + "line": 1, + "column": 1 + } + ] + }, + "function_usages": { + "test.unused_global_function": [], + "test.rarely_used_global_function": [ + { + "file": "test.py", + "line": 1, + "column": 1 + } + ], + "test.commonly_used_global_function": [ + { + "file": "test.py", + "line": 1, + "column": 1 + }, + { + "file": "test.py", + "line": 1, + "column": 1 + }, + { + "file": "test.py", + "line": 1, + "column": 1 + }, + { + "file": "test.py", + "line": 1, + "column": 1 + }, + { + "file": "test.py", + "line": 1, + "column": 1 + } + ], + "test.Commonly_Used_Class.unused_method": [], + "test.Commonly_Used_Class.rarely_used_method": [ + { + "file": "test.py", + "line": 1, + "column": 1 + } + ], + "test.Commonly_Used_Class.commonly_used_method": [ + { + "file": "test.py", + "line": 1, + "column": 1 + }, + { + "file": "test.py", + "line": 1, + "column": 1 + }, + { + "file": "test.py", + "line": 1, + "column": 1 + }, + { + "file": "test.py", + "line": 1, + "column": 1 + }, + { + "file": "test.py", + "line": 1, + "column": 1 + } + ] + }, + "parameter_usages": {}, + "value_usages": {} +} From b0d7046e64dda2c64c29136efb7418e4345a9c96 Mon Sep 17 00:00:00 2001 From: Lars Reimann Date: Sat, 16 Apr 2022 15:47:25 +0200 Subject: [PATCH 3/5] test: api data for constant annotations --- package-parser/tests/data/constant/api.json | 119 ++++++++++++++++++++ 1 file changed, 119 insertions(+) create mode 100644 package-parser/tests/data/constant/api.json diff --git a/package-parser/tests/data/constant/api.json b/package-parser/tests/data/constant/api.json new file mode 100644 index 000000000..8b15efb86 --- /dev/null +++ b/package-parser/tests/data/constant/api.json @@ -0,0 +1,119 @@ +{ + "distribution": "test", + "package": "test", + "version": "0.0.1", + "modules": [ + { + "name": "test", + "imports": [], + "from_imports": [], + "classes": [], + "functions": [ + "test.unused_global_function", + "test.rarely_used_global_function", + "test.commonly_used_global_function" + ] + } + ], + "classes": [], + "functions": [ + { + "name": "unused_global_function", + "unique_name": "unused_global_function", + "qname": "test.unused_global_function", + "unique_qname": "test.unused_global_function", + "decorators": [], + "parameters": [ + { + "name": "unused_required_parameter", + "default_value": null, + "is_public": true, + "assigned_by": "POSITION_OR_NAME", + "docstring": { + "type": "str", + "description": "" + } + }, + { + "name": "unused_optional_parameter", + "default_value": "bla", + "is_public": true, + "assigned_by": "POSITION_OR_NAME", + "docstring": { + "type": "str", + "description": "" + } + } + ], + "results": [], + "is_public": true, + "description": "", + "docstring": "", + "source_code": "" + }, + { + "name": "commonly_used_global_function", + "unique_name": "commonly_used_global_function", + "qname": "test.commonly_used_global_function", + "unique_qname": "test.commonly_used_global_function", + "decorators": [], + "parameters": [ + { + "name": "useless_required_parameter", + "default_value": null, + "is_public": true, + "assigned_by": "POSITION_OR_NAME", + "docstring": { + "type": "str", + "description": "" + } + }, + { + "name": "useful_required_parameter", + "default_value": null, + "is_public": true, + "assigned_by": "POSITION_OR_NAME", + "docstring": { + "type": "str", + "description": "" + } + }, + { + "name": "unused_optional_parameter", + "default_value": "bla", + "is_public": true, + "assigned_by": "POSITION_OR_NAME", + "docstring": { + "type": "str", + "description": "" + } + }, + { + "name": "useless_optional_parameter", + "default_value": "bla", + "is_public": true, + "assigned_by": "POSITION_OR_NAME", + "docstring": { + "type": "str", + "description": "" + } + }, + { + "name": "useful_optional_parameter", + "default_value": "bla", + "is_public": true, + "assigned_by": "POSITION_OR_NAME", + "docstring": { + "type": "str", + "description": "" + } + } + ], + "results": [], + "is_public": true, + "description": "", + "docstring": "", + "source_code": "" + } + ] +} From e7c44c6cdedd546040529e35ed95d22b653a277f Mon Sep 17 00:00:00 2001 From: Lars Reimann Date: Sat, 16 Apr 2022 15:59:10 +0200 Subject: [PATCH 4/5] test: usage data for constant annotations --- package-parser/tests/data/constant/api.json | 9 +- .../tests/data/constant/usages.json | 209 ++++++++++++++++++ 2 files changed, 213 insertions(+), 5 deletions(-) create mode 100644 package-parser/tests/data/constant/usages.json diff --git a/package-parser/tests/data/constant/api.json b/package-parser/tests/data/constant/api.json index 8b15efb86..d4bca8ec1 100644 --- a/package-parser/tests/data/constant/api.json +++ b/package-parser/tests/data/constant/api.json @@ -10,7 +10,6 @@ "classes": [], "functions": [ "test.unused_global_function", - "test.rarely_used_global_function", "test.commonly_used_global_function" ] } @@ -36,7 +35,7 @@ }, { "name": "unused_optional_parameter", - "default_value": "bla", + "default_value": "'bla'", "is_public": true, "assigned_by": "POSITION_OR_NAME", "docstring": { @@ -80,7 +79,7 @@ }, { "name": "unused_optional_parameter", - "default_value": "bla", + "default_value": "'bla'", "is_public": true, "assigned_by": "POSITION_OR_NAME", "docstring": { @@ -90,7 +89,7 @@ }, { "name": "useless_optional_parameter", - "default_value": "bla", + "default_value": "'bla'", "is_public": true, "assigned_by": "POSITION_OR_NAME", "docstring": { @@ -100,7 +99,7 @@ }, { "name": "useful_optional_parameter", - "default_value": "bla", + "default_value": "'bla'", "is_public": true, "assigned_by": "POSITION_OR_NAME", "docstring": { diff --git a/package-parser/tests/data/constant/usages.json b/package-parser/tests/data/constant/usages.json new file mode 100644 index 000000000..eeea81af8 --- /dev/null +++ b/package-parser/tests/data/constant/usages.json @@ -0,0 +1,209 @@ +{ + "class_usages": {}, + "function_usages": { + "test.unused_global_function": [], + "test.commonly_used_global_function": [ + { + "file": "test.py", + "line": 1, + "column": 1 + }, + { + "file": "test.py", + "line": 1, + "column": 1 + }, + { + "file": "test.py", + "line": 1, + "column": 1 + }, + { + "file": "test.py", + "line": 1, + "column": 1 + }, + { + "file": "test.py", + "line": 1, + "column": 1 + } + ] + }, + "parameter_usages": { + "test.unused_global_function.unused_required_parameter": [], + "test.unused_global_function.unused_optional_parameter": [], + "test.commonly_used_global_function.useless_required_parameter": [ + { + "file": "test.py", + "line": 1, + "column": 1 + }, + { + "file": "test.py", + "line": 1, + "column": 1 + }, + { + "file": "test.py", + "line": 1, + "column": 1 + }, + { + "file": "test.py", + "line": 1, + "column": 1 + }, + { + "file": "test.py", + "line": 1, + "column": 1 + } + ], + "test.commonly_used_global_function.useful_required_parameter": [ + { + "file": "test.py", + "line": 1, + "column": 1 + }, + { + "file": "test.py", + "line": 1, + "column": 1 + }, + { + "file": "test.py", + "line": 1, + "column": 1 + }, + { + "file": "test.py", + "line": 1, + "column": 1 + }, + { + "file": "test.py", + "line": 1, + "column": 1 + } + ], + "test.commonly_used_global_function.unused_optional_parameter": [], + "test.commonly_used_global_function.useless_optional_parameter": [ + { + "file": "test.py", + "line": 1, + "column": 1 + }, + { + "file": "test.py", + "line": 1, + "column": 1 + } + ], + "test.commonly_used_global_function.useful_optional_parameter": [ + { + "file": "test.py", + "line": 1, + "column": 1 + }, + { + "file": "test.py", + "line": 1, + "column": 1 + } + ] + }, + "value_usages": { + "test.unused_global_function.unused_required_parameter": {}, + "test.unused_global_function.unused_optional_parameter": {}, + "test.commonly_used_global_function.useless_required_parameter": { + "'blup'": [ + { + "file": "test.py", + "line": 1, + "column": 1 + }, + { + "file": "test.py", + "line": 1, + "column": 1 + }, + { + "file": "test.py", + "line": 1, + "column": 1 + }, + { + "file": "test.py", + "line": 1, + "column": 1 + }, + { + "file": "test.py", + "line": 1, + "column": 1 + } + ] + }, + "test.commonly_used_global_function.useful_required_parameter": { + "'bla'": [ + { + "file": "test.py", + "line": 1, + "column": 1 + }, + { + "file": "test.py", + "line": 1, + "column": 1 + } + ], + "'blup'": [ + { + "file": "test.py", + "line": 1, + "column": 1 + }, + { + "file": "test.py", + "line": 1, + "column": 1 + }, + { + "file": "test.py", + "line": 1, + "column": 1 + } + ] + }, + "test.commonly_used_global_function.unused_optional_parameter": {}, + "test.commonly_used_global_function.useless_optional_parameter": { + "'bla'": [ + { + "file": "test.py", + "line": 1, + "column": 1 + }, + { + "file": "test.py", + "line": 1, + "column": 1 + } + ] + }, + "test.commonly_used_global_function.useful_optional_parameter": { + "'blup'": [ + { + "file": "test.py", + "line": 1, + "column": 1 + }, + { + "file": "test.py", + "line": 1, + "column": 1 + } + ] + } + } +} From 8115b156186c96eaa23fcd05be82bdd6ec346121 Mon Sep 17 00:00:00 2001 From: Lars Reimann Date: Sat, 16 Apr 2022 16:08:07 +0200 Subject: [PATCH 5/5] refactor: rename files to prevent mapping to incorrect schema --- package-parser/tests/data/constant/{api.json => api_data.json} | 0 .../tests/data/constant/{usages.json => usage_data.json} | 0 package-parser/tests/data/unused/{api.json => api_data.json} | 0 package-parser/tests/data/unused/{usages.json => usage_data.json} | 0 4 files changed, 0 insertions(+), 0 deletions(-) rename package-parser/tests/data/constant/{api.json => api_data.json} (100%) rename package-parser/tests/data/constant/{usages.json => usage_data.json} (100%) rename package-parser/tests/data/unused/{api.json => api_data.json} (100%) rename package-parser/tests/data/unused/{usages.json => usage_data.json} (100%) diff --git a/package-parser/tests/data/constant/api.json b/package-parser/tests/data/constant/api_data.json similarity index 100% rename from package-parser/tests/data/constant/api.json rename to package-parser/tests/data/constant/api_data.json diff --git a/package-parser/tests/data/constant/usages.json b/package-parser/tests/data/constant/usage_data.json similarity index 100% rename from package-parser/tests/data/constant/usages.json rename to package-parser/tests/data/constant/usage_data.json diff --git a/package-parser/tests/data/unused/api.json b/package-parser/tests/data/unused/api_data.json similarity index 100% rename from package-parser/tests/data/unused/api.json rename to package-parser/tests/data/unused/api_data.json diff --git a/package-parser/tests/data/unused/usages.json b/package-parser/tests/data/unused/usage_data.json similarity index 100% rename from package-parser/tests/data/unused/usages.json rename to package-parser/tests/data/unused/usage_data.json