From 0fe757703f15d9eee43abdbdbd40c0f01e97ab7d Mon Sep 17 00:00:00 2001 From: Nataliia Date: Tue, 4 Oct 2022 14:43:42 +0300 Subject: [PATCH 1/6] improved tests --- tests/test_main.py | 43 ++++++++++++++----------------------------- 1 file changed, 14 insertions(+), 29 deletions(-) diff --git a/tests/test_main.py b/tests/test_main.py index 5c632a77..50a04db8 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -1,14 +1,8 @@ import pytest -import re import ast import inspect -from app.main import ( - format_linter_error, - format_single_linter_file, - format_linter_report, -) - +from app import main @pytest.mark.parametrize( "error_linter,error_mate", @@ -69,7 +63,7 @@ ], ) def test_format_linter_error(error_linter, error_mate): - assert format_linter_error(error_linter) == error_mate, ( + assert main.format_linter_error(error_linter) == error_mate, ( f"Function 'format_linter_error' should return {error_mate}, " f"when 'error' equals to {error_linter}" ) @@ -78,9 +72,9 @@ def test_format_linter_error(error_linter, error_mate): @pytest.mark.parametrize( "func", [ - format_linter_error, - format_single_linter_file, - format_linter_report, + main.format_linter_error, + main.format_single_linter_file, + main.format_linter_report, ], ) def test_format_functions_one_line(func): @@ -139,7 +133,7 @@ def test_format_functions_one_line(func): ], ) def test_format_single_linter_file(file_path, errors, result): - assert format_single_linter_file(file_path, errors) == result, ( + assert main.format_single_linter_file(file_path, errors) == result, ( f"Function 'format_single_linter_file' should return {result}, " f"when 'file_path' equals to {file_path}, " f"and 'errors' equals to {errors}" @@ -340,28 +334,19 @@ def test_format_single_linter_file(file_path, errors, result): ], ) def test_format_linter_report(errors_linter, errors_mate): - assert format_linter_report(errors_linter) == errors_mate, ( + assert main.format_linter_report(errors_linter) == errors_mate, ( f"Function 'format_linter_report' should return {errors_mate} " f"when 'errors' equals to {errors_linter}" ) -def test_removed_comment(): - import app - with open(app.main.__file__, "r") as f: - file_content = f.read() - comment = re.compile("# write your code here") - assert not comment.search( - file_content - ), "You have to remove the unnecessary comment '# write your code here'" +def test_comment_deleted(): + lines = inspect.getsource(main) + assert "# write your code here" not in lines, ("Remove the unnecessary" + " comment '# write your code here'") def test_double_quotes_instead_of_single(): - import app - with open(app.main.__file__, "r") as f: - file_content = f.read() - comment = re.compile("\'") - assert not comment.search( - file_content - ), "You have to use a double quotes \"\" instead of single \'\'" - + lines = inspect.getsource(main) + assert "\'" not in lines, ("You have to use a double quotes \"\" instead" + " of single \'\'") From 5d8630508ee2694585b3222d0527c619f12bb339 Mon Sep 17 00:00:00 2001 From: Nataliia Date: Fri, 4 Nov 2022 12:58:19 +0200 Subject: [PATCH 2/6] inspect remade --- tests/test_main.py | 484 +++++++++++++++++++++++---------------------- 1 file changed, 245 insertions(+), 239 deletions(-) diff --git a/tests/test_main.py b/tests/test_main.py index 50a04db8..13de720e 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -3,67 +3,73 @@ import inspect from app import main +from app.main import ( + format_linter_error, + format_single_linter_file, + format_linter_report, +) + @pytest.mark.parametrize( "error_linter,error_mate", [ ( - { - "code": "E501", - "filename": "./source_code_2.py", - "line_number": 18, - "column_number": 80, - "text": "line too long (99 > 79 characters)", - "physical_line": ' return f"I like to filter, rounding, doubling, ' - "store and decorate numbers: {', '.join(items)}!\"", - }, - { - "line": 18, - "column": 80, - "message": "line too long (99 > 79 characters)", - "name": "E501", - "source": "flake8", - }, + { + "code": "E501", + "filename": "./source_code_2.py", + "line_number": 18, + "column_number": 80, + "text": "line too long (99 > 79 characters)", + "physical_line": ' return f"I like to filter, rounding, doubling, ' + "store and decorate numbers: {', '.join(items)}!\"", + }, + { + "line": 18, + "column": 80, + "message": "line too long (99 > 79 characters)", + "name": "E501", + "source": "flake8", + }, ), ( - { - "code": "E702", - "filename": "./source_code_1.py", - "line_number": 3, - "column_number": 74, - "text": "multiple statements on one line (semicolon)", - "physical_line": ' new_items = [f"{key} -> {value}" for key, ' - "value in items.items()]; return func(new_items)\n", - }, - { - "line": 3, - "column": 74, - "message": "multiple statements on one line (semicolon)", - "name": "E702", - "source": "flake8", - }, + { + "code": "E702", + "filename": "./source_code_1.py", + "line_number": 3, + "column_number": 74, + "text": "multiple statements on one line (semicolon)", + "physical_line": ' new_items = [f"{key} -> {value}" for key, ' + "value in items.items()]; return func(new_items)\n", + }, + { + "line": 3, + "column": 74, + "message": "multiple statements on one line (semicolon)", + "name": "E702", + "source": "flake8", + }, ), ( - { - "code": "E302", - "filename": "./source_code_1.py", - "line_number": 15, - "column_number": 1, - "text": "expected 2 blank lines, found 1", - "physical_line": "def number_filter(func):\n", - }, - { - "line": 15, - "column": 1, - "message": "expected 2 blank lines, found 1", - "name": "E302", - "source": "flake8", - }, + { + "code": "E302", + "filename": "./source_code_1.py", + "line_number": 15, + "column_number": 1, + "text": "expected 2 blank lines, found 1", + "physical_line": "def number_filter(func):\n", + }, + { + "line": 15, + "column": 1, + "message": "expected 2 blank lines, found 1", + "name": "E302", + "source": "flake8", + }, ), ], ) def test_format_linter_error(error_linter, error_mate): - assert main.format_linter_error(error_linter) == error_mate, ( + assert format_linter_error(error_linter) == error_mate, ( f"Function 'format_linter_error' should return {error_mate}, " f"when 'error' equals to {error_linter}" ) @@ -72,15 +78,15 @@ def test_format_linter_error(error_linter, error_mate): @pytest.mark.parametrize( "func", [ - main.format_linter_error, - main.format_single_linter_file, - main.format_linter_report, + format_linter_error, + format_single_linter_file, + format_linter_report, ], ) def test_format_functions_one_line(func): code = inspect.getsource(func) assert ( - isinstance(ast.parse(code).body[0].body[0], ast.Return) is True + isinstance(ast.parse(code).body[0].body[0], ast.Return) is True ), f"Function '{func.__name__}' should contain only return statement" @@ -88,65 +94,8 @@ def test_format_functions_one_line(func): "file_path,errors,result", [ ( - "./source_code_2.py", - [ - { - "code": "E501", - "filename": "./source_code_2.py", - "line_number": 18, - "column_number": 80, - "text": "line too long (99 > 79 characters)", - "physical_line": ' return f"I like to filter, rounding, doubling, ' - "store and decorate numbers: {', '.join(items)}!\"", - }, - { - "code": "W292", - "filename": "./source_code_2.py", - "line_number": 18, - "column_number": 100, - "text": "no newline at end of file", - "physical_line": ' return f"I like to filter, rounding, doubling, ' - "store and decorate numbers: {', '.join(items)}!\"", - }, - ], - { - "errors": [ - { - "line": 18, - "column": 80, - "message": "line too long (99 > 79 characters)", - "name": "E501", - "source": "flake8", - }, - { - "line": 18, - "column": 100, - "message": "no newline at end of file", - "name": "W292", - "source": "flake8", - }, - ], - "path": "./source_code_2.py", - "status": "failed", - }, - ) - ], -) -def test_format_single_linter_file(file_path, errors, result): - assert main.format_single_linter_file(file_path, errors) == result, ( - f"Function 'format_single_linter_file' should return {result}, " - f"when 'file_path' equals to {file_path}, " - f"and 'errors' equals to {errors}" - ) - - -@pytest.mark.parametrize( - "errors_linter,errors_mate", - [ - ( - { - "./test_source_code_2.py": [], - "./source_code_2.py": [ + "./source_code_2.py", + [ { "code": "E501", "filename": "./source_code_2.py", @@ -154,7 +103,7 @@ def test_format_single_linter_file(file_path, errors, result): "column_number": 80, "text": "line too long (99 > 79 characters)", "physical_line": ' return f"I like to filter, rounding, doubling, ' - "store and decorate numbers: {', '.join(items)}!\"", + "store and decorate numbers: {', '.join(items)}!\"", }, { "code": "W292", @@ -163,84 +112,9 @@ def test_format_single_linter_file(file_path, errors, result): "column_number": 100, "text": "no newline at end of file", "physical_line": ' return f"I like to filter, rounding, doubling, ' - "store and decorate numbers: {', '.join(items)}!\"", + "store and decorate numbers: {', '.join(items)}!\"", }, ], - "./source_code_1.py": [ - { - "code": "E702", - "filename": "./source_code_1.py", - "line_number": 3, - "column_number": 74, - "text": "multiple statements on one line (semicolon)", - "physical_line": ' new_items = [f"{key} -> {value}" for key, ' - "value in items.items()]; return func(new_items)\n", - }, - { - "code": "E501", - "filename": "./source_code_1.py", - "line_number": 3, - "column_number": 80, - "text": "line too long (97 > 79 characters)", - "physical_line": ' new_items = [f"{key} -> {value}" for key, ' - "value in items.items()]; return func(new_items)\n", - }, - { - "code": "E302", - "filename": "./source_code_1.py", - "line_number": 15, - "column_number": 1, - "text": "expected 2 blank lines, found 1", - "physical_line": "def number_filter(func):\n", - }, - { - "code": "E303", - "filename": "./source_code_1.py", - "line_number": 27, - "column_number": 1, - "text": "too many blank lines (6)", - "physical_line": "@number_filter\n", - }, - { - "code": "E501", - "filename": "./source_code_1.py", - "line_number": 31, - "column_number": 80, - "text": "line too long (99 > 79 characters)", - "physical_line": ' return f"I like to filter, rounding, doubling, ' - "store and decorate numbers: {', '.join(items)}!\"\n", - }, - ], - "./test_source_code_1.py": [ - { - "code": "E302", - "filename": "./test_source_code_1.py", - "line_number": 4, - "column_number": 1, - "text": "expected 2 blank lines, found 1", - "physical_line": "@pytest.mark.parametrize(\n", - }, - { - "code": "E501", - "filename": "./test_source_code_1.py", - "line_number": 32, - "column_number": 80, - "text": "line too long (84 > 79 characters)", - "physical_line": ' "decorate numbers: 1 -> 2, 2 -> 4, 6 -> 12, -111 -> -222, -50 -> ' - '-100!",\n', - }, - { - "code": "W292", - "filename": "./test_source_code_1.py", - "line_number": 112, - "column_number": 6, - "text": "no newline at end of file", - "physical_line": " )", - }, - ], - }, - [ - {"errors": [], "path": "./test_source_code_2.py", "status": "passed"}, { "errors": [ { @@ -261,80 +135,212 @@ def test_format_single_linter_file(file_path, errors, result): "path": "./source_code_2.py", "status": "failed", }, + ) + ], +) +def test_format_single_linter_file(file_path, errors, result): + assert format_single_linter_file(file_path, errors) == result, ( + f"Function 'format_single_linter_file' should return {result}, " + f"when 'file_path' equals to {file_path}, " + f"and 'errors' equals to {errors}" + ) + + +@pytest.mark.parametrize( + "errors_linter,errors_mate", + [ + ( { - "errors": [ + "./test_source_code_2.py": [], + "./source_code_2.py": [ { - "line": 3, - "column": 74, - "message": "multiple statements on one line (semicolon)", - "name": "E702", - "source": "flake8", + "code": "E501", + "filename": "./source_code_2.py", + "line_number": 18, + "column_number": 80, + "text": "line too long (99 > 79 characters)", + "physical_line": ' return f"I like to filter, rounding, doubling, ' + "store and decorate numbers: {', '.join(items)}!\"", }, { - "line": 3, - "column": 80, - "message": "line too long (97 > 79 characters)", - "name": "E501", - "source": "flake8", + "code": "W292", + "filename": "./source_code_2.py", + "line_number": 18, + "column_number": 100, + "text": "no newline at end of file", + "physical_line": ' return f"I like to filter, rounding, doubling, ' + "store and decorate numbers: {', '.join(items)}!\"", }, + ], + "./source_code_1.py": [ { - "line": 15, - "column": 1, - "message": "expected 2 blank lines, found 1", - "name": "E302", - "source": "flake8", + "code": "E702", + "filename": "./source_code_1.py", + "line_number": 3, + "column_number": 74, + "text": "multiple statements on one line (semicolon)", + "physical_line": ' new_items = [f"{key} -> {value}" for key, ' + "value in items.items()]; return func(new_items)\n", }, { - "line": 27, - "column": 1, - "message": "too many blank lines (6)", - "name": "E303", - "source": "flake8", + "code": "E501", + "filename": "./source_code_1.py", + "line_number": 3, + "column_number": 80, + "text": "line too long (97 > 79 characters)", + "physical_line": ' new_items = [f"{key} -> {value}" for key, ' + "value in items.items()]; return func(new_items)\n", }, { - "line": 31, - "column": 80, - "message": "line too long (99 > 79 characters)", - "name": "E501", - "source": "flake8", + "code": "E302", + "filename": "./source_code_1.py", + "line_number": 15, + "column_number": 1, + "text": "expected 2 blank lines, found 1", + "physical_line": "def number_filter(func):\n", + }, + { + "code": "E303", + "filename": "./source_code_1.py", + "line_number": 27, + "column_number": 1, + "text": "too many blank lines (6)", + "physical_line": "@number_filter\n", + }, + { + "code": "E501", + "filename": "./source_code_1.py", + "line_number": 31, + "column_number": 80, + "text": "line too long (99 > 79 characters)", + "physical_line": ' return f"I like to filter, rounding, doubling, ' + "store and decorate numbers: {', '.join(items)}!\"\n", }, ], - "path": "./source_code_1.py", - "status": "failed", - }, - { - "errors": [ + "./test_source_code_1.py": [ { - "line": 4, - "column": 1, - "message": "expected 2 blank lines, found 1", - "name": "E302", - "source": "flake8", + "code": "E302", + "filename": "./test_source_code_1.py", + "line_number": 4, + "column_number": 1, + "text": "expected 2 blank lines, found 1", + "physical_line": "@pytest.mark.parametrize(\n", }, { - "line": 32, - "column": 80, - "message": "line too long (84 > 79 characters)", - "name": "E501", - "source": "flake8", + "code": "E501", + "filename": "./test_source_code_1.py", + "line_number": 32, + "column_number": 80, + "text": "line too long (84 > 79 characters)", + "physical_line": ' "decorate numbers: 1 -> 2, 2 -> 4, 6 -> 12, -111 -> -222, -50 -> ' + '-100!",\n', }, { - "line": 112, - "column": 6, - "message": "no newline at end of file", - "name": "W292", - "source": "flake8", + "code": "W292", + "filename": "./test_source_code_1.py", + "line_number": 112, + "column_number": 6, + "text": "no newline at end of file", + "physical_line": " )", }, ], - "path": "./test_source_code_1.py", - "status": "failed", }, - ], + [ + {"errors": [], "path": "./test_source_code_2.py", "status": "passed"}, + { + "errors": [ + { + "line": 18, + "column": 80, + "message": "line too long (99 > 79 characters)", + "name": "E501", + "source": "flake8", + }, + { + "line": 18, + "column": 100, + "message": "no newline at end of file", + "name": "W292", + "source": "flake8", + }, + ], + "path": "./source_code_2.py", + "status": "failed", + }, + { + "errors": [ + { + "line": 3, + "column": 74, + "message": "multiple statements on one line (semicolon)", + "name": "E702", + "source": "flake8", + }, + { + "line": 3, + "column": 80, + "message": "line too long (97 > 79 characters)", + "name": "E501", + "source": "flake8", + }, + { + "line": 15, + "column": 1, + "message": "expected 2 blank lines, found 1", + "name": "E302", + "source": "flake8", + }, + { + "line": 27, + "column": 1, + "message": "too many blank lines (6)", + "name": "E303", + "source": "flake8", + }, + { + "line": 31, + "column": 80, + "message": "line too long (99 > 79 characters)", + "name": "E501", + "source": "flake8", + }, + ], + "path": "./source_code_1.py", + "status": "failed", + }, + { + "errors": [ + { + "line": 4, + "column": 1, + "message": "expected 2 blank lines, found 1", + "name": "E302", + "source": "flake8", + }, + { + "line": 32, + "column": 80, + "message": "line too long (84 > 79 characters)", + "name": "E501", + "source": "flake8", + }, + { + "line": 112, + "column": 6, + "message": "no newline at end of file", + "name": "W292", + "source": "flake8", + }, + ], + "path": "./test_source_code_1.py", + "status": "failed", + }, + ], ) ], ) def test_format_linter_report(errors_linter, errors_mate): - assert main.format_linter_report(errors_linter) == errors_mate, ( + assert format_linter_report(errors_linter) == errors_mate, ( f"Function 'format_linter_report' should return {errors_mate} " f"when 'errors' equals to {errors_linter}" ) @@ -343,7 +349,7 @@ def test_format_linter_report(errors_linter, errors_mate): def test_comment_deleted(): lines = inspect.getsource(main) assert "# write your code here" not in lines, ("Remove the unnecessary" - " comment '# write your code here'") + " comment '# write your code here'") def test_double_quotes_instead_of_single(): From 7a0dacf36ee6942d43c0f6a1820f8ad5a39a6884 Mon Sep 17 00:00:00 2001 From: Nataliia Date: Fri, 4 Nov 2022 13:00:30 +0200 Subject: [PATCH 3/6] inspect remade --- tests/test_main.py | 264 ++++++++++++++++++++++----------------------- 1 file changed, 132 insertions(+), 132 deletions(-) diff --git a/tests/test_main.py b/tests/test_main.py index 13de720e..5433778f 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -14,34 +14,34 @@ "error_linter,error_mate", [ ( - { - "code": "E501", - "filename": "./source_code_2.py", - "line_number": 18, - "column_number": 80, - "text": "line too long (99 > 79 characters)", - "physical_line": ' return f"I like to filter, rounding, doubling, ' - "store and decorate numbers: {', '.join(items)}!\"", - }, - { - "line": 18, - "column": 80, - "message": "line too long (99 > 79 characters)", - "name": "E501", - "source": "flake8", - }, + { + "code": "E501", + "filename": "./source_code_2.py", + "line_number": 18, + "column_number": 80, + "text": "line too long (99 > 79 characters)", + "physical_line": ' return f"I like to filter, rounding, doubling, ' + "store and decorate numbers: {', '.join(items)}!\"", + }, + { + "line": 18, + "column": 80, + "message": "line too long (99 > 79 characters)", + "name": "E501", + "source": "flake8", + }, ), ( - { - "code": "E702", - "filename": "./source_code_1.py", - "line_number": 3, - "column_number": 74, - "text": "multiple statements on one line (semicolon)", - "physical_line": ' new_items = [f"{key} -> {value}" for key, ' - "value in items.items()]; return func(new_items)\n", - }, - { + { + "code": "E702", + "filename": "./source_code_1.py", + "line_number": 3, + "column_number": 74, + "text": "multiple statements on one line (semicolon)", + "physical_line": ' new_items = [f"{key} -> {value}" for key, ' + "value in items.items()]; return func(new_items)\n", + }, + { "line": 3, "column": 74, "message": "multiple statements on one line (semicolon)", @@ -50,15 +50,15 @@ }, ), ( - { - "code": "E302", - "filename": "./source_code_1.py", - "line_number": 15, - "column_number": 1, - "text": "expected 2 blank lines, found 1", - "physical_line": "def number_filter(func):\n", - }, - { + { + "code": "E302", + "filename": "./source_code_1.py", + "line_number": 15, + "column_number": 1, + "text": "expected 2 blank lines, found 1", + "physical_line": "def number_filter(func):\n", + }, + { "line": 15, "column": 1, "message": "expected 2 blank lines, found 1", @@ -94,7 +94,7 @@ def test_format_functions_one_line(func): "file_path,errors,result", [ ( - "./source_code_2.py", + "./source_code_2.py", [ { "code": "E501", @@ -150,102 +150,102 @@ def test_format_single_linter_file(file_path, errors, result): "errors_linter,errors_mate", [ ( - { - "./test_source_code_2.py": [], - "./source_code_2.py": [ - { - "code": "E501", - "filename": "./source_code_2.py", - "line_number": 18, - "column_number": 80, - "text": "line too long (99 > 79 characters)", - "physical_line": ' return f"I like to filter, rounding, doubling, ' - "store and decorate numbers: {', '.join(items)}!\"", - }, - { - "code": "W292", - "filename": "./source_code_2.py", - "line_number": 18, - "column_number": 100, - "text": "no newline at end of file", - "physical_line": ' return f"I like to filter, rounding, doubling, ' - "store and decorate numbers: {', '.join(items)}!\"", - }, - ], - "./source_code_1.py": [ - { - "code": "E702", - "filename": "./source_code_1.py", - "line_number": 3, - "column_number": 74, - "text": "multiple statements on one line (semicolon)", - "physical_line": ' new_items = [f"{key} -> {value}" for key, ' - "value in items.items()]; return func(new_items)\n", - }, - { - "code": "E501", - "filename": "./source_code_1.py", - "line_number": 3, - "column_number": 80, - "text": "line too long (97 > 79 characters)", - "physical_line": ' new_items = [f"{key} -> {value}" for key, ' - "value in items.items()]; return func(new_items)\n", - }, - { - "code": "E302", - "filename": "./source_code_1.py", - "line_number": 15, - "column_number": 1, - "text": "expected 2 blank lines, found 1", - "physical_line": "def number_filter(func):\n", - }, - { - "code": "E303", - "filename": "./source_code_1.py", - "line_number": 27, - "column_number": 1, - "text": "too many blank lines (6)", - "physical_line": "@number_filter\n", - }, - { - "code": "E501", - "filename": "./source_code_1.py", - "line_number": 31, - "column_number": 80, - "text": "line too long (99 > 79 characters)", - "physical_line": ' return f"I like to filter, rounding, doubling, ' - "store and decorate numbers: {', '.join(items)}!\"\n", - }, - ], - "./test_source_code_1.py": [ - { - "code": "E302", - "filename": "./test_source_code_1.py", - "line_number": 4, - "column_number": 1, - "text": "expected 2 blank lines, found 1", - "physical_line": "@pytest.mark.parametrize(\n", - }, - { - "code": "E501", - "filename": "./test_source_code_1.py", - "line_number": 32, - "column_number": 80, - "text": "line too long (84 > 79 characters)", - "physical_line": ' "decorate numbers: 1 -> 2, 2 -> 4, 6 -> 12, -111 -> -222, -50 -> ' - '-100!",\n', - }, - { - "code": "W292", - "filename": "./test_source_code_1.py", - "line_number": 112, - "column_number": 6, - "text": "no newline at end of file", - "physical_line": " )", - }, - ], - }, - [ + { + "./test_source_code_2.py": [], + "./source_code_2.py": [ + { + "code": "E501", + "filename": "./source_code_2.py", + "line_number": 18, + "column_number": 80, + "text": "line too long (99 > 79 characters)", + "physical_line": ' return f"I like to filter, rounding, doubling, ' + "store and decorate numbers: {', '.join(items)}!\"", + }, + { + "code": "W292", + "filename": "./source_code_2.py", + "line_number": 18, + "column_number": 100, + "text": "no newline at end of file", + "physical_line": ' return f"I like to filter, rounding, doubling, ' + "store and decorate numbers: {', '.join(items)}!\"", + }, + ], + "./source_code_1.py": [ + { + "code": "E702", + "filename": "./source_code_1.py", + "line_number": 3, + "column_number": 74, + "text": "multiple statements on one line (semicolon)", + "physical_line": ' new_items = [f"{key} -> {value}" for key, ' + "value in items.items()]; return func(new_items)\n", + }, + { + "code": "E501", + "filename": "./source_code_1.py", + "line_number": 3, + "column_number": 80, + "text": "line too long (97 > 79 characters)", + "physical_line": ' new_items = [f"{key} -> {value}" for key, ' + "value in items.items()]; return func(new_items)\n", + }, + { + "code": "E302", + "filename": "./source_code_1.py", + "line_number": 15, + "column_number": 1, + "text": "expected 2 blank lines, found 1", + "physical_line": "def number_filter(func):\n", + }, + { + "code": "E303", + "filename": "./source_code_1.py", + "line_number": 27, + "column_number": 1, + "text": "too many blank lines (6)", + "physical_line": "@number_filter\n", + }, + { + "code": "E501", + "filename": "./source_code_1.py", + "line_number": 31, + "column_number": 80, + "text": "line too long (99 > 79 characters)", + "physical_line": ' return f"I like to filter, rounding, doubling, ' + "store and decorate numbers: {', '.join(items)}!\"\n", + }, + ], + "./test_source_code_1.py": [ + { + "code": "E302", + "filename": "./test_source_code_1.py", + "line_number": 4, + "column_number": 1, + "text": "expected 2 blank lines, found 1", + "physical_line": "@pytest.mark.parametrize(\n", + }, + { + "code": "E501", + "filename": "./test_source_code_1.py", + "line_number": 32, + "column_number": 80, + "text": "line too long (84 > 79 characters)", + "physical_line": ' "decorate numbers: 1 -> 2, 2 -> 4, 6 -> 12, -111 -> -222, -50 -> ' + '-100!",\n', + }, + { + "code": "W292", + "filename": "./test_source_code_1.py", + "line_number": 112, + "column_number": 6, + "text": "no newline at end of file", + "physical_line": " )", + }, + ], + }, + [ {"errors": [], "path": "./test_source_code_2.py", "status": "passed"}, { "errors": [ From 24dc9560b9adabe183d4627be24cb66df975306d Mon Sep 17 00:00:00 2001 From: Nataliia Date: Fri, 4 Nov 2022 13:03:47 +0200 Subject: [PATCH 4/6] tabulation fixed --- tests/test_main.py | 220 ++++++++++++++++++++++----------------------- 1 file changed, 110 insertions(+), 110 deletions(-) diff --git a/tests/test_main.py b/tests/test_main.py index 5433778f..0be6a05e 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -21,7 +21,7 @@ "column_number": 80, "text": "line too long (99 > 79 characters)", "physical_line": ' return f"I like to filter, rounding, doubling, ' - "store and decorate numbers: {', '.join(items)}!\"", + "store and decorate numbers: {', '.join(items)}!\"", }, { "line": 18, @@ -39,15 +39,15 @@ "column_number": 74, "text": "multiple statements on one line (semicolon)", "physical_line": ' new_items = [f"{key} -> {value}" for key, ' - "value in items.items()]; return func(new_items)\n", + "value in items.items()]; return func(new_items)\n", }, { - "line": 3, - "column": 74, - "message": "multiple statements on one line (semicolon)", - "name": "E702", - "source": "flake8", - }, + "line": 3, + "column": 74, + "message": "multiple statements on one line (semicolon)", + "name": "E702", + "source": "flake8", + }, ), ( { @@ -59,12 +59,12 @@ "physical_line": "def number_filter(func):\n", }, { - "line": 15, - "column": 1, - "message": "expected 2 blank lines, found 1", - "name": "E302", - "source": "flake8", - }, + "line": 15, + "column": 1, + "message": "expected 2 blank lines, found 1", + "name": "E302", + "source": "flake8", + }, ), ], ) @@ -86,7 +86,7 @@ def test_format_linter_error(error_linter, error_mate): def test_format_functions_one_line(func): code = inspect.getsource(func) assert ( - isinstance(ast.parse(code).body[0].body[0], ast.Return) is True + isinstance(ast.parse(code).body[0].body[0], ast.Return) is True ), f"Function '{func.__name__}' should contain only return statement" @@ -160,7 +160,7 @@ def test_format_single_linter_file(file_path, errors, result): "column_number": 80, "text": "line too long (99 > 79 characters)", "physical_line": ' return f"I like to filter, rounding, doubling, ' - "store and decorate numbers: {', '.join(items)}!\"", + "store and decorate numbers: {', '.join(items)}!\"", }, { "code": "W292", @@ -169,7 +169,7 @@ def test_format_single_linter_file(file_path, errors, result): "column_number": 100, "text": "no newline at end of file", "physical_line": ' return f"I like to filter, rounding, doubling, ' - "store and decorate numbers: {', '.join(items)}!\"", + "store and decorate numbers: {', '.join(items)}!\"", }, ], "./source_code_1.py": [ @@ -180,7 +180,7 @@ def test_format_single_linter_file(file_path, errors, result): "column_number": 74, "text": "multiple statements on one line (semicolon)", "physical_line": ' new_items = [f"{key} -> {value}" for key, ' - "value in items.items()]; return func(new_items)\n", + "value in items.items()]; return func(new_items)\n", }, { "code": "E501", @@ -189,7 +189,7 @@ def test_format_single_linter_file(file_path, errors, result): "column_number": 80, "text": "line too long (97 > 79 characters)", "physical_line": ' new_items = [f"{key} -> {value}" for key, ' - "value in items.items()]; return func(new_items)\n", + "value in items.items()]; return func(new_items)\n", }, { "code": "E302", @@ -233,7 +233,7 @@ def test_format_single_linter_file(file_path, errors, result): "column_number": 80, "text": "line too long (84 > 79 characters)", "physical_line": ' "decorate numbers: 1 -> 2, 2 -> 4, 6 -> 12, -111 -> -222, -50 -> ' - '-100!",\n', + '-100!",\n', }, { "code": "W292", @@ -246,96 +246,96 @@ def test_format_single_linter_file(file_path, errors, result): ], }, [ - {"errors": [], "path": "./test_source_code_2.py", "status": "passed"}, - { - "errors": [ - { - "line": 18, - "column": 80, - "message": "line too long (99 > 79 characters)", - "name": "E501", - "source": "flake8", - }, - { - "line": 18, - "column": 100, - "message": "no newline at end of file", - "name": "W292", - "source": "flake8", - }, - ], - "path": "./source_code_2.py", - "status": "failed", - }, - { - "errors": [ - { - "line": 3, - "column": 74, - "message": "multiple statements on one line (semicolon)", - "name": "E702", - "source": "flake8", - }, - { - "line": 3, - "column": 80, - "message": "line too long (97 > 79 characters)", - "name": "E501", - "source": "flake8", - }, - { - "line": 15, - "column": 1, - "message": "expected 2 blank lines, found 1", - "name": "E302", - "source": "flake8", - }, - { - "line": 27, - "column": 1, - "message": "too many blank lines (6)", - "name": "E303", - "source": "flake8", - }, - { - "line": 31, - "column": 80, - "message": "line too long (99 > 79 characters)", - "name": "E501", - "source": "flake8", - }, - ], - "path": "./source_code_1.py", - "status": "failed", - }, - { - "errors": [ - { - "line": 4, - "column": 1, - "message": "expected 2 blank lines, found 1", - "name": "E302", - "source": "flake8", - }, - { - "line": 32, - "column": 80, - "message": "line too long (84 > 79 characters)", - "name": "E501", - "source": "flake8", - }, - { - "line": 112, - "column": 6, - "message": "no newline at end of file", - "name": "W292", - "source": "flake8", - }, - ], - "path": "./test_source_code_1.py", - "status": "failed", - }, - ], + {"errors": [], "path": "./test_source_code_2.py", "status": "passed"}, + { + "errors": [ + { + "line": 18, + "column": 80, + "message": "line too long (99 > 79 characters)", + "name": "E501", + "source": "flake8", + }, + { + "line": 18, + "column": 100, + "message": "no newline at end of file", + "name": "W292", + "source": "flake8", + }, + ], + "path": "./source_code_2.py", + "status": "failed", + }, + { + "errors": [ + { + "line": 3, + "column": 74, + "message": "multiple statements on one line (semicolon)", + "name": "E702", + "source": "flake8", + }, + { + "line": 3, + "column": 80, + "message": "line too long (97 > 79 characters)", + "name": "E501", + "source": "flake8", + }, + { + "line": 15, + "column": 1, + "message": "expected 2 blank lines, found 1", + "name": "E302", + "source": "flake8", + }, + { + "line": 27, + "column": 1, + "message": "too many blank lines (6)", + "name": "E303", + "source": "flake8", + }, + { + "line": 31, + "column": 80, + "message": "line too long (99 > 79 characters)", + "name": "E501", + "source": "flake8", + }, + ], + "path": "./source_code_1.py", + "status": "failed", + }, + { + "errors": [ + { + "line": 4, + "column": 1, + "message": "expected 2 blank lines, found 1", + "name": "E302", + "source": "flake8", + }, + { + "line": 32, + "column": 80, + "message": "line too long (84 > 79 characters)", + "name": "E501", + "source": "flake8", + }, + { + "line": 112, + "column": 6, + "message": "no newline at end of file", + "name": "W292", + "source": "flake8", + }, + ], + "path": "./test_source_code_1.py", + "status": "failed", + }, + ], ) ], ) From 868e570742a007725445fed29a33a01e09091c9b Mon Sep 17 00:00:00 2001 From: Nataliia Date: Fri, 4 Nov 2022 13:12:30 +0200 Subject: [PATCH 5/6] tabulation fixed --- tests/test_main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_main.py b/tests/test_main.py index 0be6a05e..274131e0 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -214,7 +214,7 @@ def test_format_single_linter_file(file_path, errors, result): "column_number": 80, "text": "line too long (99 > 79 characters)", "physical_line": ' return f"I like to filter, rounding, doubling, ' - "store and decorate numbers: {', '.join(items)}!\"\n", + "store and decorate numbers: {', '.join(items)}!\"\n", }, ], "./test_source_code_1.py": [ From ee3649d9b2c7609d4720fa5969ce0ce3a7b0f1a3 Mon Sep 17 00:00:00 2001 From: Nataliia Date: Fri, 4 Nov 2022 14:16:48 +0200 Subject: [PATCH 6/6] black runned --- tests/test_main.py | 80 ++++++++++++++++++++++++---------------------- 1 file changed, 41 insertions(+), 39 deletions(-) diff --git a/tests/test_main.py b/tests/test_main.py index 274131e0..85db2374 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -95,46 +95,46 @@ def test_format_functions_one_line(func): [ ( "./source_code_2.py", - [ + [ + { + "code": "E501", + "filename": "./source_code_2.py", + "line_number": 18, + "column_number": 80, + "text": "line too long (99 > 79 characters)", + "physical_line": ' return f"I like to filter, rounding, doubling, ' + "store and decorate numbers: {', '.join(items)}!\"", + }, + { + "code": "W292", + "filename": "./source_code_2.py", + "line_number": 18, + "column_number": 100, + "text": "no newline at end of file", + "physical_line": ' return f"I like to filter, rounding, doubling, ' + "store and decorate numbers: {', '.join(items)}!\"", + }, + ], + { + "errors": [ { - "code": "E501", - "filename": "./source_code_2.py", - "line_number": 18, - "column_number": 80, - "text": "line too long (99 > 79 characters)", - "physical_line": ' return f"I like to filter, rounding, doubling, ' - "store and decorate numbers: {', '.join(items)}!\"", + "line": 18, + "column": 80, + "message": "line too long (99 > 79 characters)", + "name": "E501", + "source": "flake8", }, { - "code": "W292", - "filename": "./source_code_2.py", - "line_number": 18, - "column_number": 100, - "text": "no newline at end of file", - "physical_line": ' return f"I like to filter, rounding, doubling, ' - "store and decorate numbers: {', '.join(items)}!\"", + "line": 18, + "column": 100, + "message": "no newline at end of file", + "name": "W292", + "source": "flake8", }, ], - { - "errors": [ - { - "line": 18, - "column": 80, - "message": "line too long (99 > 79 characters)", - "name": "E501", - "source": "flake8", - }, - { - "line": 18, - "column": 100, - "message": "no newline at end of file", - "name": "W292", - "source": "flake8", - }, - ], - "path": "./source_code_2.py", - "status": "failed", - }, + "path": "./source_code_2.py", + "status": "failed", + }, ) ], ) @@ -348,11 +348,13 @@ def test_format_linter_report(errors_linter, errors_mate): def test_comment_deleted(): lines = inspect.getsource(main) - assert "# write your code here" not in lines, ("Remove the unnecessary" - " comment '# write your code here'") + assert "# write your code here" not in lines, ( + "Remove the unnecessary" " comment '# write your code here'" + ) def test_double_quotes_instead_of_single(): lines = inspect.getsource(main) - assert "\'" not in lines, ("You have to use a double quotes \"\" instead" - " of single \'\'") + assert "'" not in lines, ( + 'You have to use a double quotes "" instead' " of single ''" + )