Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/scan test coverage #603

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

Conversation

dylanpulver
Copy link
Collaborator

@dylanpulver dylanpulver commented Sep 12, 2024

This PR begins on increasing the test coverage on safety scan

Summary by CodeRabbit

  • New Features

    • Introduced comprehensive unit tests for various functionalities in the Python ecosystem scanning module, enhancing reliability and coverage.
    • Added tests for dependency management, vulnerability handling, file scanning, and decorators.
  • Bug Fixes

    • Improved validation of critical methods related to project configuration and policy resolution.
  • Documentation

    • Enhanced test coverage documentation for the safety scanning functionalities, ensuring clarity on tested scenarios.

Copy link

coderabbitai bot commented Sep 12, 2024

Walkthrough

The changes encompass the addition of several unit test files and modifications to existing test files within the Python ecosystem scanning module. New tests validate functionalities such as dependency management, vulnerability handling, file scanning, and decorator behavior. Additionally, abstract classes and file handler classes are tested to ensure proper implementation and error handling. The updates enhance overall test coverage and reliability of the codebase.

Changes

Files Change Summary
tests/scan/ecosystems/python/test_dependencies.py, tests/scan/ecosystems/python/test_main.py Introduced unit tests for Python ecosystem scanning functionalities, including version handling, requirement pinning, and vulnerability management. Added test cases for various functions and classes.
tests/scan/ecosystems/test_base.py, tests/scan/ecosystems/test_target.py Added tests for abstract classes and context management in file handling, ensuring correct behavior and error handling during instantiation and file operations.
tests/scan/finder/test_file_finder.py, tests/scan/finder/test_handlers.py Introduced tests for file finding and handler functionalities, validating exclusion logic and ensuring correct instantiation and behavior of handler classes.
tests/scan/test_decorators.py, tests/scan/test_main.py, tests/scan/test_models.py Added tests for decorators, project configuration, and model functionalities, ensuring proper initialization, metadata injection, and method behaviors across various components.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant TestRunner
    participant EcosystemScanner
    participant DependencyManager
    participant FileHandler

    User->>TestRunner: Run Tests
    TestRunner->>EcosystemScanner: Validate Dependencies
    EcosystemScanner->>DependencyManager: Check Versions
    DependencyManager-->>EcosystemScanner: Return Results
    EcosystemScanner->>FileHandler: Handle Files
    FileHandler-->>EcosystemScanner: Return File Status
    EcosystemScanner-->>TestRunner: Complete Tests
    TestRunner-->>User: Test Results
Loading

Poem

🐰 In the garden of code, where functions bloom,
New tests sprout forth, dispelling the gloom.
With dependencies checked and handlers in line,
The ecosystem thrives, oh how it does shine!
So hop with delight, let the coverage grow,
For each little test makes our software glow! 🌼


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 5

Outside diff range and nitpick comments (2)
tests/scan/test_decorators.py (2)

1-7: Remove unused imports.

The static analysis tool Ruff has reported several unused imports:

  • safety.errors.SafetyException
  • safety.scan.models.SystemScanOutput
  • safety_schemas.models.ConfigModel
  • safety_schemas.models.ProjectModel
  • safety_schemas.models.PolicySource
  • safety_schemas.models.MetadataModel
  • safety_schemas.models.ReportSchemaVersion

Please remove these unused imports to keep the code clean and maintainable.

Tools
Ruff

5-5: safety.errors.SafetyException imported but unused

Remove unused import: safety.errors.SafetyException

(F401)


6-6: safety.scan.models.SystemScanOutput imported but unused

Remove unused import: safety.scan.models.SystemScanOutput

(F401)


7-7: safety_schemas.models.ConfigModel imported but unused

Remove unused import

(F401)


7-7: safety_schemas.models.ProjectModel imported but unused

Remove unused import

(F401)


7-7: safety_schemas.models.PolicySource imported but unused

Remove unused import

(F401)


7-7: safety_schemas.models.MetadataModel imported but unused

Remove unused import

(F401)


7-7: safety_schemas.models.ReportSchemaVersion imported but unused

Remove unused import

(F401)


9-14: Remove unused import.

The static analysis tool Ruff has reported an unused import:

  • safety.scan.decorators.scan_system_command_init

Please remove this unused import to keep the code clean and maintainable.

Tools
Ruff

12-12: safety.scan.decorators.scan_system_command_init imported but unused

Remove unused import: safety.scan.decorators.scan_system_command_init

(F401)

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 15e757c and 1aaaa15.

Files selected for processing (9)
  • tests/scan/ecosystems/python/test_dependencies.py (1 hunks)
  • tests/scan/ecosystems/python/test_main.py (3 hunks)
  • tests/scan/ecosystems/test_base.py (1 hunks)
  • tests/scan/ecosystems/test_target.py (1 hunks)
  • tests/scan/finder/test_file_finder.py (1 hunks)
  • tests/scan/finder/test_handlers.py (1 hunks)
  • tests/scan/test_decorators.py (1 hunks)
  • tests/scan/test_main.py (1 hunks)
  • tests/scan/test_models.py (1 hunks)
Additional context used
Ruff
tests/scan/ecosystems/python/test_dependencies.py

2-2: unittest.mock.mock_open imported but unused

Remove unused import

(F401)


2-2: unittest.mock.patch imported but unused

Remove unused import

(F401)


4-4: collections.defaultdict imported but unused

Remove unused import: collections.defaultdict

(F401)


12-12: safety.scan.ecosystems.python.dependencies.read_requirements imported but unused

Remove unused import

(F401)


13-13: safety.scan.ecosystems.python.dependencies.read_dependencies imported but unused

Remove unused import

(F401)


13-13: safety.scan.ecosystems.python.dependencies.read_virtual_environment_dependencies imported but unused

Remove unused import

(F401)


14-14: safety.scan.ecosystems.python.dependencies.get_dependencies imported but unused

Remove unused import

(F401)


16-16: safety_schemas.models.PythonDependency imported but unused

Remove unused import

(F401)


16-16: safety_schemas.models.FileType imported but unused

Remove unused import

(F401)


17-17: safety.scan.ecosystems.base.InspectableFile imported but unused

Remove unused import: safety.scan.ecosystems.base.InspectableFile

(F401)


18-18: dparse.filetypes imported but unused

Remove unused import: dparse.filetypes

(F401)

tests/scan/ecosystems/test_base.py

4-4: safety_schemas.models.Ecosystem imported but unused

Remove unused import

(F401)


4-4: safety_schemas.models.FileType imported but unused

Remove unused import

(F401)

tests/scan/test_main.py

4-4: configparser.ConfigParser imported but unused

Remove unused import: configparser.ConfigParser

(F401)


5-5: pydantic.ValidationError imported but unused

Remove unused import: pydantic.ValidationError

(F401)


6-6: typing.Any imported but unused

Remove unused import

(F401)


6-6: typing.Dict imported but unused

Remove unused import

(F401)


6-6: typing.Set imported but unused

Remove unused import

(F401)


8-8: safety.auth.utils.SafetyAuthSession imported but unused

Remove unused import: safety.auth.utils.SafetyAuthSession

(F401)


9-9: safety.errors.SafetyError imported but unused

Remove unused import: safety.errors.SafetyError

(F401)


10-10: safety.scan.ecosystems.target.InspectableFileContext imported but unused

Remove unused import: safety.scan.ecosystems.target.InspectableFileContext

(F401)


11-11: safety.scan.models.ScanExport imported but unused

Remove unused import: safety.scan.models.ScanExport

(F401)


13-13: safety.scan.main.download_policy imported but unused

Remove unused import

(F401)


16-16: safety.scan.main.load_policy_file imported but unused

Remove unused import

(F401)


18-18: safety.scan.main.save_report_as imported but unused

Remove unused import

(F401)


21-21: safety_schemas.models.PolicyFileModel imported but unused

Remove unused import

(F401)


21-21: safety_schemas.models.PolicySource imported but unused

Remove unused import

(F401)


21-21: safety_schemas.models.ConfigModel imported but unused

Remove unused import

(F401)


21-21: safety_schemas.models.Stage imported but unused

Remove unused import

(F401)


21-21: safety_schemas.models.ScanType imported but unused

Remove unused import

(F401)


22-22: importlib imported but unused

Remove unused import: importlib

(F401)


23-23: time imported but unused

Remove unused import: time

(F401)

tests/scan/test_models.py

3-3: typing.Optional imported but unused

Remove unused import: typing.Optional

(F401)


5-5: pydantic.dataclasses.dataclass imported but unused

Remove unused import: pydantic.dataclasses.dataclass

(F401)

tests/scan/finder/test_file_finder.py

37-37: Undefined name self

(F821)


56-56: Undefined name self

(F821)

tests/scan/test_decorators.py

5-5: safety.errors.SafetyException imported but unused

Remove unused import: safety.errors.SafetyException

(F401)


6-6: safety.scan.models.SystemScanOutput imported but unused

Remove unused import: safety.scan.models.SystemScanOutput

(F401)


7-7: safety_schemas.models.ConfigModel imported but unused

Remove unused import

(F401)


7-7: safety_schemas.models.ProjectModel imported but unused

Remove unused import

(F401)


7-7: safety_schemas.models.PolicySource imported but unused

Remove unused import

(F401)


7-7: safety_schemas.models.MetadataModel imported but unused

Remove unused import

(F401)


7-7: safety_schemas.models.ReportSchemaVersion imported but unused

Remove unused import

(F401)


12-12: safety.scan.decorators.scan_system_command_init imported but unused

Remove unused import: safety.scan.decorators.scan_system_command_init

(F401)

tests/scan/ecosystems/python/test_main.py

3-3: datetime.datetime imported but unused

Remove unused import: datetime.datetime

(F401)


4-4: packaging.specifiers.SpecifierSet imported but unused

Remove unused import: packaging.specifiers.SpecifierSet

(F401)


8-8: safety.scan.ecosystems.python.main.get_vulnerability imported but unused

Remove unused import: safety.scan.ecosystems.python.main.get_vulnerability

(F401)


11-11: safety_schemas.models.ConfigModel imported but unused

Remove unused import

(F401)


11-11: safety_schemas.models.Vulnerability imported but unused

Remove unused import

(F401)


12-12: safety_schemas.models.IgnoredItems imported but unused

Remove unused import

(F401)


12-12: safety_schemas.models.IgnoredItemDetail imported but unused

Remove unused import

(F401)


14-14: safety.models.Severity imported but unused

Remove unused import: safety.models.Severity

(F401)

Additional comments not posted (33)
tests/scan/ecosystems/python/test_dependencies.py (5)

23-28: LGTM!

The code changes are approved.


31-35: LGTM!

The code changes are approved.


37-40: LGTM!

The code changes are approved.


42-44: LGTM!

The code changes are approved.


46-51: LGTM!

The code changes are approved.

tests/scan/ecosystems/test_base.py (3)

7-23: LGTM!

The TestInspectable class is well-implemented and covers the expected behavior of the Inspectable abstract base class. The test methods are correctly named and use the unittest framework to assert the expected behavior.


25-40: LGTM!

The TestRemediable class is well-implemented and covers the expected behavior of the Remediable abstract base class. The test methods are correctly named and use the unittest framework to assert the expected behavior.


43-53: LGTM!

The TestInspectableFile class is well-implemented and covers the initialization of the InspectableFile abstract base class. The test method is correctly named and uses the unittest framework to assert the expected behavior.

tests/scan/finder/test_handlers.py (5)

10-12: LGTM!

The code changes are approved. The TestableFileHandler class is a valid concrete subclass of FileHandler that is used for testing purposes.


14-29: LGTM!

The code changes are approved. The TestFileHandler class correctly tests the FileHandler class.


32-41: LGTM!

The code changes are approved. The TestPythonFileHandler class correctly tests the PythonFileHandler class.


44-53: LGTM!

The code changes are approved. The TestSafetyProjectFileHandler class correctly tests the SafetyProjectFileHandler class.


56-60: LGTM!

The code changes are approved. The TestEcosystemHandlerMapping class correctly tests the ECOSYSTEM_HANDLER_MAPPING dictionary.

tests/scan/ecosystems/test_target.py (2)

9-33: LGTM!

The test class TestInspectableFileContext is well-structured and follows the AAA (Arrange-Act-Assert) pattern. The test methods cover the success and failure scenarios of the __enter__ and __exit__ methods of the InspectableFileContext class and use appropriate assertions to verify the behavior.

The code changes are approved.


34-50: LGTM!

The test class TestTargetFile is well-structured and follows the AAA (Arrange-Act-Assert) pattern. The test methods cover the success and failure scenarios of the create method of the TargetFile class and use appropriate assertions to verify the behavior.

The code changes are approved.

tests/scan/test_main.py (3)

26-41: LGTM!

The test method test_load_unverified_project_from_config is well-structured and properly tests the load_unverified_project_from_config function. It mocks the necessary dependencies, calls the function with the expected arguments, and makes appropriate assertions on the returned UnverifiedProjectModel instance.


42-52: LGTM!

The test method test_save_project_info effectively tests the save_project_info function. It mocks the required dependencies, creates the necessary input objects, calls the function, and asserts the expected function calls were made with the correct arguments.


53-67: LGTM!

The test method test_resolve_policy thoroughly tests the resolve_policy function by covering all the possible combinations of local_policy and cloud_policy arguments. The test cases are well-defined and the assertions verify the expected behavior of the function in each scenario.

tests/scan/test_models.py (5)

8-19: LGTM!

The code changes are approved. The unit tests for the FormatMixin class are well-written and cover various test cases.


30-39: LGTM!

The code changes are approved. The unit test for the ScanOutput enum is well-written and covers various test cases.


42-52: LGTM!

The code changes are approved. The unit test for the ScanExport enum is well-written and covers various test cases, including the ValueError exception for an unsupported enum value.


55-59: LGTM!

The code changes are approved. The unit test for the SystemScanOutput enum is well-written and covers various test cases.


68-82: LGTM!

The code changes are approved. The unit test for the UnverifiedProjectModel dataclass is well-written and correctly tests the dataclass by creating an instance and asserting its attributes.

tests/scan/finder/test_file_finder.py (2)

8-22: LGTM!

The test class TestShouldExclude and its test methods are implemented correctly. The test methods cover the necessary scenarios and use appropriate assertions to validate the expected behavior of the should_exclude function.


24-80: LGTM, ignore the static analysis hints!

The test class TestFileFinder and its test methods are implemented correctly. The test methods cover the necessary scenarios, use appropriate assertions to validate the expected behavior, and correctly mock the external dependencies. The setup method is correctly initializing the necessary attributes for the test methods.

Regarding the static analysis hints about undefined names self at lines 37 and 56, they can be ignored as false positives because self is a valid reference within the context of a class method.

Tools
Ruff

37-37: Undefined name self

(F821)


56-56: Undefined name self

(F821)

tests/scan/test_decorators.py (3)

16-26: LGTM!

The code changes are approved.


27-69: LGTM!

The code changes are approved.


71-94: LGTM!

The code changes are approved.

tests/scan/ecosystems/python/test_main.py (5)

85-94: LGTM!

The code changes are approved.


97-102: LGTM!

The code changes are approved.


105-112: LGTM!

The code changes are approved.


114-143: LGTM!

The code changes are approved.


Line range hint 29-83: LGTM!

The code changes are approved.

Comment on lines +1 to +18
import unittest
from unittest.mock import MagicMock, mock_open, patch
from pathlib import Path
from collections import defaultdict

from packaging.specifiers import SpecifierSet
from packaging.version import parse as parse_version

from safety.scan.ecosystems.python.main import (
get_closest_ver, is_pinned_requirement)
from safety.scan.ecosystems.python.dependencies import (
find_version,is_supported_by_parser, parse_requirement, read_requirements,
read_dependencies, read_virtual_environment_dependencies,
get_dependencies
)
from safety_schemas.models import PythonDependency, PythonSpecification, FileType
from safety.scan.ecosystems.base import InspectableFile
from dparse import filetypes
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove unused imports.

The static analysis tool has flagged several unused imports:

  • unittest.mock.mock_open
  • unittest.mock.patch
  • collections.defaultdict
  • safety.scan.ecosystems.python.dependencies.read_requirements
  • safety.scan.ecosystems.python.dependencies.read_dependencies
  • safety.scan.ecosystems.python.dependencies.read_virtual_environment_dependencies
  • safety.scan.ecosystems.python.dependencies.get_dependencies
  • safety_schemas.models.PythonDependency
  • safety_schemas.models.FileType
  • safety.scan.ecosystems.base.InspectableFile
  • dparse.filetypes

Please remove these unused imports to improve the code quality.

Tools
Ruff

2-2: unittest.mock.mock_open imported but unused

Remove unused import

(F401)


2-2: unittest.mock.patch imported but unused

Remove unused import

(F401)


4-4: collections.defaultdict imported but unused

Remove unused import: collections.defaultdict

(F401)


12-12: safety.scan.ecosystems.python.dependencies.read_requirements imported but unused

Remove unused import

(F401)


13-13: safety.scan.ecosystems.python.dependencies.read_dependencies imported but unused

Remove unused import

(F401)


13-13: safety.scan.ecosystems.python.dependencies.read_virtual_environment_dependencies imported but unused

Remove unused import

(F401)


14-14: safety.scan.ecosystems.python.dependencies.get_dependencies imported but unused

Remove unused import

(F401)


16-16: safety_schemas.models.PythonDependency imported but unused

Remove unused import

(F401)


16-16: safety_schemas.models.FileType imported but unused

Remove unused import

(F401)


17-17: safety.scan.ecosystems.base.InspectableFile imported but unused

Remove unused import: safety.scan.ecosystems.base.InspectableFile

(F401)


18-18: dparse.filetypes imported but unused

Remove unused import: dparse.filetypes

(F401)

import unittest
from unittest.mock import MagicMock
from typer import FileTextWrite
from safety_schemas.models import ConfigModel, DependencyResultModel, Ecosystem, FileType
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove unused imports.

The imports Ecosystem and FileType from safety_schemas.models are not used in the code. Please remove them to improve code readability and maintainability.

Apply this diff to remove the unused imports:

-from safety_schemas.models import ConfigModel, DependencyResultModel, Ecosystem, FileType
+from safety_schemas.models import ConfigModel, DependencyResultModel
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
from safety_schemas.models import ConfigModel, DependencyResultModel, Ecosystem, FileType
from safety_schemas.models import ConfigModel, DependencyResultModel
Tools
Ruff

4-4: safety_schemas.models.Ecosystem imported but unused

Remove unused import

(F401)


4-4: safety_schemas.models.FileType imported but unused

Remove unused import

(F401)

Comment on lines +1 to +23
import unittest
from unittest.mock import MagicMock, patch, mock_open
from pathlib import Path
from configparser import ConfigParser
from pydantic import ValidationError
from typing import Any, Dict, Set, Tuple

from safety.auth.utils import SafetyAuthSession
from safety.errors import SafetyError
from safety.scan.ecosystems.target import InspectableFileContext
from safety.scan.models import ScanExport, UnverifiedProjectModel
from safety.scan.main import (
download_policy,
load_unverified_project_from_config,
save_project_info,
load_policy_file,
resolve_policy,
save_report_as,
process_files
)
from safety_schemas.models import FileType, PolicyFileModel, PolicySource, ConfigModel, Stage, ProjectModel, ScanType
import importlib
import time
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove unused imports.

The following imports are unused in the file and should be removed to keep the code clean and maintainable:

  • configparser.ConfigParser
  • pydantic.ValidationError
  • typing.Any
  • typing.Dict
  • typing.Set
  • safety.auth.utils.SafetyAuthSession
  • safety.errors.SafetyError
  • safety.scan.ecosystems.target.InspectableFileContext
  • safety.scan.models.ScanExport
  • safety.scan.main.download_policy
  • safety.scan.main.load_policy_file
  • safety.scan.main.save_report_as
  • safety_schemas.models.PolicyFileModel
  • safety_schemas.models.PolicySource
  • safety_schemas.models.ConfigModel
  • safety_schemas.models.Stage
  • safety_schemas.models.ScanType
  • importlib
  • time
Tools
Ruff

4-4: configparser.ConfigParser imported but unused

Remove unused import: configparser.ConfigParser

(F401)


5-5: pydantic.ValidationError imported but unused

Remove unused import: pydantic.ValidationError

(F401)


6-6: typing.Any imported but unused

Remove unused import

(F401)


6-6: typing.Dict imported but unused

Remove unused import

(F401)


6-6: typing.Set imported but unused

Remove unused import

(F401)


8-8: safety.auth.utils.SafetyAuthSession imported but unused

Remove unused import: safety.auth.utils.SafetyAuthSession

(F401)


9-9: safety.errors.SafetyError imported but unused

Remove unused import: safety.errors.SafetyError

(F401)


10-10: safety.scan.ecosystems.target.InspectableFileContext imported but unused

Remove unused import: safety.scan.ecosystems.target.InspectableFileContext

(F401)


11-11: safety.scan.models.ScanExport imported but unused

Remove unused import: safety.scan.models.ScanExport

(F401)


13-13: safety.scan.main.download_policy imported but unused

Remove unused import

(F401)


16-16: safety.scan.main.load_policy_file imported but unused

Remove unused import

(F401)


18-18: safety.scan.main.save_report_as imported but unused

Remove unused import

(F401)


21-21: safety_schemas.models.PolicyFileModel imported but unused

Remove unused import

(F401)


21-21: safety_schemas.models.PolicySource imported but unused

Remove unused import

(F401)


21-21: safety_schemas.models.ConfigModel imported but unused

Remove unused import

(F401)


21-21: safety_schemas.models.Stage imported but unused

Remove unused import

(F401)


21-21: safety_schemas.models.ScanType imported but unused

Remove unused import

(F401)


22-22: importlib imported but unused

Remove unused import: importlib

(F401)


23-23: time imported but unused

Remove unused import: time

(F401)

@@ -0,0 +1,86 @@
import unittest
from pathlib import Path
from typing import Optional
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove unused imports.

The following imports are unused and can be removed:

  • Optional from typing
  • dataclass from pydantic.dataclasses

Apply this diff to remove the unused imports:

-from typing import Optional
-from pydantic.dataclasses import dataclass

Also applies to: 5-5

Tools
Ruff

3-3: typing.Optional imported but unused

Remove unused import: typing.Optional

(F401)

Comment on lines +3 to +14
from datetime import datetime
from packaging.specifiers import SpecifierSet

from safety.scan.ecosystems.python.main import (
should_fail, VulnerabilitySeverityLabels,
ignore_vuln_if_needed, get_vulnerability, PythonFile
)
from safety_schemas.models import (
ConfigModel, Vulnerability, PythonDependency, PythonSpecification,
FileType, IgnoredItems, IgnoredItemDetail, IgnoreCodes
)
from safety.models import Severity
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove unused imports.

The code changes are approved. However, please remove the following unused imports to improve code quality:

  • datetime.datetime (line 3)
  • packaging.specifiers.SpecifierSet (line 4)
  • safety.scan.ecosystems.python.main.get_vulnerability (line 8)
  • safety_schemas.models.ConfigModel (line 11)
  • safety_schemas.models.Vulnerability (line 11)
  • safety_schemas.models.IgnoredItems (line 12)
  • safety_schemas.models.IgnoredItemDetail (line 12)
  • safety.models.Severity (line 14)
Tools
Ruff

3-3: datetime.datetime imported but unused

Remove unused import: datetime.datetime

(F401)


4-4: packaging.specifiers.SpecifierSet imported but unused

Remove unused import: packaging.specifiers.SpecifierSet

(F401)


8-8: safety.scan.ecosystems.python.main.get_vulnerability imported but unused

Remove unused import: safety.scan.ecosystems.python.main.get_vulnerability

(F401)


11-11: safety_schemas.models.ConfigModel imported but unused

Remove unused import

(F401)


11-11: safety_schemas.models.Vulnerability imported but unused

Remove unused import

(F401)


12-12: safety_schemas.models.IgnoredItems imported but unused

Remove unused import

(F401)


12-12: safety_schemas.models.IgnoredItemDetail imported but unused

Remove unused import

(F401)


14-14: safety.models.Severity imported but unused

Remove unused import: safety.models.Severity

(F401)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant