Skip to content

Commit

Permalink
WIP: add pyproject.toml, test_toml.py; edited setup.py to avoid overw…
Browse files Browse the repository at this point in the history
…riting with pyproject.toml

target to fix: issue PolicyEngine#256
  • Loading branch information
SylviaDu99 committed Sep 12, 2024
1 parent 996737a commit a828427
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
7 changes: 7 additions & 0 deletions changelog_entry.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
- bump: minor
changes:
added:
- pyproject.toml, transforming from setup.py
- testing for pyproject.toml
changed:
- edited dependencies in setup.py to avoid overwriting
19 changes: 16 additions & 3 deletions test_toml.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import pytest
from packaging import version


@pytest.fixture(scope="module")
def toml_data():
file_path = "pyproject.toml"
Expand All @@ -12,6 +13,7 @@ def toml_data():
with open(file_path, "rb") as f:
return tomli.load(f)


def test_toml_syntax():
file_path = "pyproject.toml"
try:
Expand All @@ -20,32 +22,43 @@ def test_toml_syntax():
except tomli.TOMLDecodeError as e:
pytest.fail(f"TOML syntax error: {e}")


def test_required_fields(toml_data):
required_fields = ["name", "version", "description"]
for field in required_fields:
assert field in toml_data.get("project", {}), f"Missing required field: {field}"
assert field in toml_data.get(
"project", {}
), f"Missing required field: {field}"


def test_build_system(toml_data):
build_system = toml_data.get("build-system", {})
assert "requires" in build_system, "Build system 'requires' is missing."
assert "build-backend" in build_system, "Build system 'build-backend' is missing."
assert (
"build-backend" in build_system
), "Build system 'build-backend' is missing."


def test_package_build():
try:
subprocess.run(["python", "-m", "build"], check=True)
except subprocess.CalledProcessError:
pytest.fail("Failed to build package.")


def test_package_installation():
try:
subprocess.run(["pip", "install", "."], check=True)
except subprocess.CalledProcessError:
pytest.fail("Failed to install package.")


def test_run_tests():
try:
subprocess.run(["pytest"], check=True)
except subprocess.CalledProcessError:
pytest.fail("Some tests failed.")
except FileNotFoundError:
pytest.skip("pytest not found. Make sure it's installed and in your PATH.")
pytest.skip(
"pytest not found. Make sure it's installed and in your PATH."
)

0 comments on commit a828427

Please sign in to comment.