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

test: add test for mismatch package build #4785

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions dev-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@ types-PyYAML
types-requests
types-setuptools
types-toml
build
27 changes: 27 additions & 0 deletions test/test_mismatch_cli.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import shutil
import sqlite3
import subprocess
from pathlib import Path
from test.utils import LONG_TESTS
from unittest.mock import patch

import pytest
Expand All @@ -26,6 +29,14 @@ def test_db(tmpdir_factory):
yield str(db_file)


@pytest.fixture(scope="module")
def build_cleanup():
yield
dist_dir = Path(__file__).resolve().parent.parent / "dist"
if dist_dir.exists():
shutil.rmtree(dist_dir)


def test_lookup(capsys, monkeypatch, test_db):
# Test with custom database path using the --database flag
monkeypatch.setattr(
Expand Down Expand Up @@ -93,3 +104,19 @@ def verify_db(test_db):
"facebook",
)
assert expected in result


@pytest.mark.skipif(not LONG_TESTS(), reason="Skipping long tests")
def test_package_build(build_cleanup):
print("Building package")
build = subprocess.run(["python", "-m", "build"], check=True)
Copy link
Contributor

@Prtm2110 Prtm2110 Feb 10, 2025

Choose a reason for hiding this comment

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

Hello, To ensure the code runs on all systems, consider using the path to the Python executable, which can be accessed via sys.executable and import sys. Other than this it looks good!

Suggested change
build = subprocess.run(["python", "-m", "build"], check=True)
build = subprocess.run([sys.executable, "-m", "build"], check=True)

Copy link
Author

Choose a reason for hiding this comment

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

didn't know about this. thanks.

assert build.returncode == 0, "Python build failed"

print("Install package")
Copy link
Contributor

@Prtm2110 Prtm2110 Feb 10, 2025

Choose a reason for hiding this comment

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

Suggested change
print("Install package")

We should not have any print statements in a test file

dist_dir = Path(__file__).resolve().parent.parent / "dist"
package_path = list(dist_dir.glob("*.whl"))[0]
subprocess.run(["pip", "install", str(package_path)], check=True)

result = subprocess.run(["mismatch", "--help"], capture_output=True, text=True)
print(result)
assert "ModuleNotFoundError: No module named 'mismatch'" not in result.stderr