From c3fc40583e83d79c3b4212a9dc75893c4ec3f6ae Mon Sep 17 00:00:00 2001 From: Lars Reimann Date: Sun, 17 Apr 2022 13:37:44 +0200 Subject: [PATCH] test: data for unused and constant annotations (#439) * test: api data for unused annotations * test: usage data for unused annotations * test: api data for constant annotations * test: usage data for constant annotations * refactor: rename files to prevent mapping to incorrect schema --- .../tests/data/constant/api_data.json | 118 ++++++++++ .../tests/data/constant/usage_data.json | 209 ++++++++++++++++++ .../tests/data/unused/api_data.json | 129 +++++++++++ .../tests/data/unused/usage_data.json | 113 ++++++++++ 4 files changed, 569 insertions(+) create mode 100644 package-parser/tests/data/constant/api_data.json create mode 100644 package-parser/tests/data/constant/usage_data.json create mode 100644 package-parser/tests/data/unused/api_data.json create mode 100644 package-parser/tests/data/unused/usage_data.json diff --git a/package-parser/tests/data/constant/api_data.json b/package-parser/tests/data/constant/api_data.json new file mode 100644 index 000000000..d4bca8ec1 --- /dev/null +++ b/package-parser/tests/data/constant/api_data.json @@ -0,0 +1,118 @@ +{ + "distribution": "test", + "package": "test", + "version": "0.0.1", + "modules": [ + { + "name": "test", + "imports": [], + "from_imports": [], + "classes": [], + "functions": [ + "test.unused_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": "" + } + ] +} diff --git a/package-parser/tests/data/constant/usage_data.json b/package-parser/tests/data/constant/usage_data.json new file mode 100644 index 000000000..eeea81af8 --- /dev/null +++ b/package-parser/tests/data/constant/usage_data.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 + } + ] + } + } +} diff --git a/package-parser/tests/data/unused/api_data.json b/package-parser/tests/data/unused/api_data.json new file mode 100644 index 000000000..3164ee5fb --- /dev/null +++ b/package-parser/tests/data/unused/api_data.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": "" + } + ] +} diff --git a/package-parser/tests/data/unused/usage_data.json b/package-parser/tests/data/unused/usage_data.json new file mode 100644 index 000000000..39a6d40c6 --- /dev/null +++ b/package-parser/tests/data/unused/usage_data.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": {} +}