Skip to content

Commit

Permalink
test: add test for updated package descriptor
Browse files Browse the repository at this point in the history
  • Loading branch information
ejortega committed Jul 28, 2023
1 parent 9adfdd6 commit 03a8a6c
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions tests/unit/test_parse.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
"""Test the lockfile current_lockfile_packages function."""

import json
from unittest.mock import patch
from phylum.ci.common import PackageDescriptor
from phylum.ci.lockfile import Lockfile
from pathlib import Path

import pytest

Check failure on line 9 in tests/unit/test_parse.py

View workflow job for this annotation

GitHub Actions / Quality Assurance (3.11)

Ruff (F401)

tests/unit/test_parse.py:9:8: F401 `pytest` imported but unused

@patch("subprocess.run")
def test_current_lockfile_packages(mock_run):

Check failure on line 12 in tests/unit/test_parse.py

View workflow job for this annotation

GitHub Actions / Quality Assurance (3.11)

Ruff (I001)

tests/unit/test_parse.py:3:1: I001 Import block is un-sorted or un-formatted
# Prepare the mock

Check failure on line 13 in tests/unit/test_parse.py

View workflow job for this annotation

GitHub Actions / Quality Assurance (3.11)

Ruff (D103)

tests/unit/test_parse.py:13:5: D103 Missing docstring in public function
mock_run.return_value.stdout = json.dumps([
{
"name": "quote",
"version": "1.0.21",
"type": "cargo",
"lockfile": "Cargo.lock"
},
{
"name": "example",
"version": "0.1.0",

Check failure on line 23 in tests/unit/test_parse.py

View workflow job for this annotation

GitHub Actions / Quality Assurance (3.11)

Ruff (COM812)

tests/unit/test_parse.py:23:10: COM812 Trailing comma missing
"type": "npm",
}
])

lockfile = Lockfile(Path("Cargo.lock"), Path("dummy_cli_path"), None)

# Test the current_lockfile_packages method
packages = lockfile.current_lockfile_packages()
expected_cargo_package = PackageDescriptor("quote", "1.0.21", "cargo", "Cargo.lock")
expected_npm_package = PackageDescriptor("example", "0.1.0", "npm")

Check failure on line 33 in tests/unit/test_parse.py

View workflow job for this annotation

GitHub Actions / Quality Assurance (3.11)

Ruff (PLR2004)

tests/unit/test_parse.py:33:29: PLR2004 Magic value used in comparison, consider replacing 2 with a constant variable


assert len(packages) == 2
assert packages[0] == expected_cargo_package
assert packages[1] == expected_npm_package

Check failure on line 39 in tests/unit/test_parse.py

View workflow job for this annotation

GitHub Actions / Quality Assurance (3.11)

Ruff (COM812)

tests/unit/test_parse.py:39:106: COM812 Trailing comma missing
# Ensure the mock was called correctly
mock_run.assert_called_once_with(
[str(lockfile.cli_path), "parse", str(lockfile.path)],
check=True, capture_output=True, text=True
)

0 comments on commit 03a8a6c

Please sign in to comment.