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

Add tests #12

Merged
merged 6 commits into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ exclude: '^docs/conf.py'

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
rev: v4.6.0
hooks:
- id: trailing-whitespace
- id: check-added-large-files
Expand Down Expand Up @@ -41,7 +41,7 @@ repos:
args: [--settings-path=pyproject.toml]

- repo: https://github.com/psf/black
rev: 24.1.1
rev: 24.8.0
hooks:
- id: black
args: [--config=pyproject.toml]
Expand All @@ -54,7 +54,7 @@ repos:
# additional_dependencies: [black]

- repo: https://github.com/PyCQA/flake8
rev: 7.0.0
rev: 7.1.1
hooks:
- id: flake8
additional_dependencies: [Flake8-pyproject]
Expand Down
18 changes: 12 additions & 6 deletions bw_scenarios/importer.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
import pandas as pd
from typing import Optional, Union
"""
bw_scenarios module to parse the SDF.

"""

from os import PathLike
from pathlib import Path
from typing import Optional, Union

import pandas as pd

from .scenario import Scenario

Expand Down Expand Up @@ -89,7 +95,8 @@ def from_csv(
@classmethod
def from_dataframe(cls, df: pd.DataFrame) -> "SDFImporter":
"""
Parse the SDF input data from a dataframe that is read in either from a csv or excel file.
Parse the SDF input data from a dataframe that is read in either from a csv or
excel file.
"""

# check if the dataframe contains the expected columns
Expand All @@ -111,9 +118,8 @@ def from_dataframe(cls, df: pd.DataFrame) -> "SDFImporter":

if not all([col in df.columns for col in expected_columns]):
raise ValueError(
"Warning: the dataframe does not contain the expected columns: {}".format(
expected_columns
)
"Warning: the dataframe does not contain "
"the expected columns: {}".format(expected_columns)
)

df["from id"] = None
Expand Down
16 changes: 14 additions & 2 deletions tests/test_importer.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,20 @@
"""
Tests for the importer module of bw_scenarios.
"""

import pytest

from bw_scenarios.importer import SDFImporter


def test_from_dataframe_wrong_cols(bogus_df):
with pytest.raises(ValueError):
SDFImporter().from_dataframe(bogus_df)
"""
Verify that the SDFIMporter raises ValueError when supplied a bogus df.

Parameters
----------

bogus_df: a pandas dataframe with bougus columns.
"""
with pytest.raises(ValueError):
SDFImporter().from_dataframe(bogus_df)
Loading