Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
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
41 changes: 41 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,47 @@ jobs:
run: |
pytest

test_pypsa2smspp:
# Test pypsa2smspp package integration
name: Test pypsa2smspp integration
needs:
- test
runs-on: ${{ matrix.os }}
permissions:
contents: read
strategy:
fail-fast: false
matrix:
python-version:
- "3.13"
- "3.12"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Limit to 3.13

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Updated to Python 3.13 only in commit cb80a74.

os:
- ubuntu-latest
env:
MPLBACKEND: Agg # https://github.com/orgs/community/discussions/26434
steps:
- uses: actions/checkout@v5
with:
fetch-depth: 0 # Needed for setuptools_scm

- name: Set up Python ${{ matrix.python-version }} on ${{ matrix.os }}
uses: actions/setup-python@v6
with:
python-version: ${{ matrix.python-version }}

- name: Install package and dependencies
run: |
python -m pip install --upgrade pip
pip install .[dev]

- name: Install pypsa2smspp
run: |
pip install pypsa2smspp

- name: Test pypsa2smspp integration
run: |
pytest test/test_pypsa2smspp.py -v
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I want to execute pytest on pypsa2smspp package using the pysmspp package being tested

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Updated in commit cb80a74. The CI now clones the pypsa2smspp repository and runs its full test suite, which will use the pysmspp package being tested from the current PR.


test_with_smspp:
# Test package build in matrix of OS and Python versions
name: Test package with SMSpp
Expand Down
54 changes: 54 additions & 0 deletions test/test_pypsa2smspp.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
"""Tests for pypsa2smspp package integration."""

import pytest


def test_pypsa2smspp_import():
"""Test that pypsa2smspp can be imported."""
import pypsa2smspp

assert hasattr(pypsa2smspp, "Transformation")
assert hasattr(pypsa2smspp, "TransformationConfig")


def test_pypsa2smspp_basic_functionality():
"""Test basic pypsa2smspp functionality with a simple network."""
import pypsa
import pypsa2smspp

# Create a simple PyPSA network
n = pypsa.Network()
n.add("Bus", "bus0")
n.add("Generator", "gen0", bus="bus0", p_nom=100, marginal_cost=50)
n.add("Load", "load0", bus="bus0", p_set=80)

# Verify the network was created
assert len(n.buses) == 1
assert len(n.generators) == 1
assert len(n.loads) == 1

# Test that we can instantiate TransformationConfig
config = pypsa2smspp.TransformationConfig()
assert config is not None


def test_pypsa2smspp_config_loading():
"""Test that pypsa2smspp can load its default configuration."""
import pypsa2smspp
import yaml
import os

# Find the config file
pypsa2smspp_path = pypsa2smspp.__file__
config_path = os.path.join(
os.path.dirname(pypsa2smspp_path), "data", "config_default.yaml"
)

assert os.path.exists(config_path), f"Config file not found at {config_path}"

# Load and verify config
with open(config_path) as f:
config = yaml.safe_load(f)

assert config is not None
assert isinstance(config, dict)