Skip to content

Commit

Permalink
Merge pull request #289 from Breakthrough-Energy/jon/tox
Browse files Browse the repository at this point in the history
Combine ci workflows with tox
  • Loading branch information
jenhagg authored Sep 11, 2020
2 parents ded70f0 + a1c9ef8 commit 40009a7
Show file tree
Hide file tree
Showing 45 changed files with 181 additions and 143 deletions.
11 changes: 0 additions & 11 deletions .github/workflows/ci-lint.yml

This file was deleted.

17 changes: 11 additions & 6 deletions .github/workflows/ci-test.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
name: Run pytest
name: Run tox

on: [push]

jobs:
test:
ci:
if: "!contains(github.event.head_commit.message, 'skip_ci')"
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
toxenv: ['pytest-ci', 'checkformatting']
steps:
- uses: actions/checkout@v2
- name: Set up Python 3.x
Expand All @@ -13,14 +18,14 @@ jobs:
python-version: 3.x
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install pytest
python -m pip install --upgrade pip tox
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Start postgres container
if: ${{ matrix.toxenv == 'pytest-ci' }}
run: |
docker-compose -f stack.yml up -d
while ! nc -z localhost 5432; do sleep 1; done;
working-directory: powersimdata/data_access
- name: Run pytest
- name: Run tox
run: |
pytest . -m 'not ssh'
tox -e ${{ matrix.toxenv }}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
![Pytest](https://github.com/Breakthrough-Energy/PowerSimData/workflows/Run%20pytest/badge.svg)
![CI](https://github.com/Breakthrough-Energy/PowerSimData/workflows/Run%20tox/badge.svg)

# PowerSimData
This package has been written in order to carry out power flow study in the
Expand Down
7 changes: 4 additions & 3 deletions powersimdata/data_access/csv_store.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from powersimdata.utility import server_setup

import os
from pathlib import Path

import pandas as pd
import os

from powersimdata.utility import server_setup


class CsvStore:
Expand Down
4 changes: 2 additions & 2 deletions powersimdata/data_access/scenario_list.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import posixpath

from powersimdata.data_access.csv_store import CsvStore
from powersimdata.data_access.sql_store import SqlStore, to_data_frame
from powersimdata.utility import server_setup

import posixpath


class ScenarioTable(SqlStore):
"""Storage abstraction for scenario list using sql database."""
Expand Down
5 changes: 3 additions & 2 deletions powersimdata/data_access/sql_store.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import os

import pandas as pd
import psycopg2
import psycopg2.extensions
import psycopg2.extras
from psycopg2.sql import SQL, Identifier, Placeholder
import os
import pandas as pd


class SqlException(Exception):
Expand Down
7 changes: 4 additions & 3 deletions powersimdata/data_access/tests/test_execute_list_store.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from powersimdata.data_access.execute_list import ExecuteTable
from powersimdata.data_access.sql_store import SqlException
from collections import OrderedDict

import pytest
from collections import OrderedDict

from powersimdata.data_access.execute_list import ExecuteTable
from powersimdata.data_access.sql_store import SqlException

row_id = 9000

Expand Down
8 changes: 4 additions & 4 deletions powersimdata/data_access/tests/test_scenario_list_store.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from powersimdata.data_access.scenario_list import ScenarioTable
from powersimdata.data_access.sql_store import SqlException
import os
from collections import OrderedDict

import pytest
from collections import OrderedDict

import os
from powersimdata.data_access.scenario_list import ScenarioTable
from powersimdata.data_access.sql_store import SqlException

# uncomment to enable logging queries to stdout
# os.environ["DEBUG_MODE"] = "1"
Expand Down
4 changes: 2 additions & 2 deletions powersimdata/data_access/tests/test_sql_store.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from powersimdata.data_access.sql_store import SqlStore

import pytest

from powersimdata.data_access.sql_store import SqlStore


class DummySqlStore(SqlStore):
table = "my_table"
Expand Down
4 changes: 2 additions & 2 deletions powersimdata/design/generation/clean_capacity_scaling.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import jsonpickle
import json
import os
import pickle

import jsonpickle
import numpy as np
import pandas as pd

from powersimdata.design.scenario_info import ScenarioInfo
from powersimdata.design.mimic_grid import mimic_generation_capacity
from powersimdata.design.scenario_info import ScenarioInfo
from powersimdata.input.grid import Grid
from powersimdata.network.usa_tamu.usa_tamu_model import area_to_loadzone
from powersimdata.scenario.scenario import Scenario
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
import pytest

import pandas as pd
import pytest
from pandas.testing import assert_frame_equal, assert_series_equal

from powersimdata.tests.mock_scenario import MockScenario
from powersimdata.design.generation.clean_capacity_scaling import (
add_resource_data_to_targets,
add_demand_to_targets,
add_shortfall_to_targets,
add_new_capacities_independent,
add_new_capacities_collaborative,
create_change_table,
add_new_capacities_independent,
add_resource_data_to_targets,
add_shortfall_to_targets,
calculate_clean_capacity_scaling,
create_change_table,
)
from powersimdata.tests.mock_scenario import MockScenario


def test_independent_new_capacity():
Expand Down
1 change: 1 addition & 0 deletions powersimdata/design/tests/test_scenario_info.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import unittest

import pandas as pd

from powersimdata.design.scenario_info import ScenarioInfo
Expand Down
2 changes: 1 addition & 1 deletion powersimdata/design/transmission/mwmiles.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from powersimdata.utility.distance import haversine
from powersimdata.input.grid import Grid
from powersimdata.utility.distance import haversine


def calculate_mw_miles(scenario, exclude_branches=None):
Expand Down
2 changes: 1 addition & 1 deletion powersimdata/design/transmission/tests/test_mwmiles.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import unittest

from powersimdata.tests.mock_grid import MockGrid
from powersimdata.design.transmission.mwmiles import _calculate_mw_miles
from powersimdata.tests.mock_grid import MockGrid

# branch 11 from Seattle to San Francisco (~679 miles)
# branch 12 from Seattle to Spokane (~229 miles)
Expand Down
4 changes: 3 additions & 1 deletion powersimdata/design/transmission/tests/test_statelines.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import unittest

from powersimdata.design.transmission.statelines import (
_classify_interstate_intrastate,
)
from powersimdata.tests.mock_grid import MockGrid
from powersimdata.design.transmission.statelines import _classify_interstate_intrastate

# branch_id is the index
mock_branch = {
Expand Down
14 changes: 7 additions & 7 deletions powersimdata/design/transmission/tests/test_upgrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@
import numpy as np
import pandas as pd

from powersimdata.tests.mock_grid import MockGrid
from powersimdata.tests.mock_scenario import MockScenario
from powersimdata.tests.mock_change_table import MockChangeTable
from powersimdata.design.transmission.upgrade import (
_construct_composite_allow_list,
_find_branches_connected_to_bus,
_find_capacity_at_bus,
_find_first_degree_branches,
_find_stub_degree,
_find_capacity_at_bus,
scale_renewable_stubs,
get_branches_by_area,
_identify_mesh_branch_upgrades,
_construct_composite_allow_list,
_increment_branch_scaling,
get_branches_by_area,
scale_renewable_stubs,
)
from powersimdata.tests.mock_change_table import MockChangeTable
from powersimdata.tests.mock_grid import MockGrid
from powersimdata.tests.mock_scenario import MockScenario

"""
This test network is a ring, with several spurs coming off of it. The central
Expand Down
2 changes: 1 addition & 1 deletion powersimdata/design/transmission/upgrade.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import pandas as pd

from powersimdata.network.usa_tamu.usa_tamu_model import area_to_loadzone
from powersimdata.input.grid import Grid
from powersimdata.network.usa_tamu.usa_tamu_model import area_to_loadzone
from powersimdata.utility.distance import haversine


Expand Down
3 changes: 1 addition & 2 deletions powersimdata/input/change_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
scale_renewable_stubs,
)
from powersimdata.utility import server_setup
from powersimdata.utility.distance import haversine, find_closest_neighbor

from powersimdata.utility.distance import find_closest_neighbor, haversine

_resources = (
"coal",
Expand Down
2 changes: 1 addition & 1 deletion powersimdata/input/grid.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os

from powersimdata.network.usa_tamu.usa_tamu_model import TAMU
from powersimdata.input.scenario_grid import FromREISE, FromREISEjl
from powersimdata.network.usa_tamu.usa_tamu_model import TAMU


class Grid(object):
Expand Down
1 change: 1 addition & 0 deletions powersimdata/input/helpers.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os

import pandas as pd


Expand Down
9 changes: 5 additions & 4 deletions powersimdata/input/input_data.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
from powersimdata.utility import server_setup, backup
from powersimdata.utility.transfer_data import download
from powersimdata.scenario.helpers import interconnect2name

import os

import pandas as pd

from powersimdata.scenario.helpers import interconnect2name
from powersimdata.utility import backup, server_setup
from powersimdata.utility.transfer_data import download


class InputData(object):
"""Load input data.
Expand Down
3 changes: 2 additions & 1 deletion powersimdata/input/scenario_grid.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import os

import numpy as np
import pandas as pd
from scipy.io import loadmat

from powersimdata.input.abstract_grid import AbstractGrid
from powersimdata.input.helpers import (
add_coord_to_grid_data_frames,
add_zone_to_grid_data_frames,
add_interconnect_to_grid_data_frames,
add_zone_to_grid_data_frames,
)


Expand Down
3 changes: 1 addition & 2 deletions powersimdata/input/tests/test_change_table.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import pytest

from powersimdata.input.grid import Grid
from powersimdata.input.change_table import ChangeTable

from powersimdata.input.grid import Grid

grid = Grid(["USA"])
ct = ChangeTable(grid)
Expand Down
10 changes: 7 additions & 3 deletions powersimdata/input/tests/test_grid.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import copy

import numpy as np
import pandas as pd
import pytest
import copy

from powersimdata.network.usa_tamu.usa_tamu_model import TAMU, check_interconnect
from powersimdata.input.grid import Grid
from powersimdata.input.helpers import add_column_to_data_frame
from powersimdata.input.scenario_grid import format_gencost, link
from powersimdata.input.grid import Grid
from powersimdata.network.usa_tamu.usa_tamu_model import (
TAMU,
check_interconnect,
)


def test_interconnect_type():
Expand Down
3 changes: 2 additions & 1 deletion powersimdata/input/tests/test_transform_grid.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import copy

import numpy as np

from powersimdata.input.grid import Grid
from powersimdata.input.change_table import ChangeTable
from powersimdata.input.grid import Grid
from powersimdata.input.transform_grid import TransformGrid

grid = Grid(["USA"])
Expand Down
4 changes: 2 additions & 2 deletions powersimdata/input/tests/test_transform_profile.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import numpy as np
import pytest

from powersimdata.input.input_data import InputData
from powersimdata.utility.transfer_data import setup_server_connection
from powersimdata.input.change_table import ChangeTable
from powersimdata.input.grid import Grid
from powersimdata.input.input_data import InputData
from powersimdata.input.transform_grid import TransformGrid
from powersimdata.input.transform_profile import TransformProfile
from powersimdata.utility.transfer_data import setup_server_connection

interconnect = ["Western"]
param = {
Expand Down
1 change: 1 addition & 0 deletions powersimdata/input/transform_grid.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import copy

import numpy as np
import pandas as pd

Expand Down
2 changes: 1 addition & 1 deletion powersimdata/input/transform_profile.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import copy

from powersimdata.input.input_data import InputData
from powersimdata.input.grid import Grid
from powersimdata.input.input_data import InputData


class TransformProfile(object):
Expand Down
6 changes: 3 additions & 3 deletions powersimdata/network/usa_tamu/usa_tamu_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

from powersimdata.input.abstract_grid import AbstractGrid
from powersimdata.input.helpers import (
csv_to_data_frame,
add_zone_to_grid_data_frames,
add_coord_to_grid_data_frames,
add_zone_to_grid_data_frames,
csv_to_data_frame,
)
from powersimdata.network.csv_reader import CSVReader
from powersimdata.network.usa_tamu.constants.zones import (
abv2state,
state2loadzone,
interconnect2loadzone,
state2loadzone,
)


Expand Down
Loading

0 comments on commit 40009a7

Please sign in to comment.