Skip to content

Commit

Permalink
Test and pylint -fixes (#38)
Browse files Browse the repository at this point in the history
* Test and pylint -fixes
* Drop support for Python 3.9, just can't be arsed
* Remove coveralls for now, need to check later
* Remove pypy tests at least for now
  • Loading branch information
kipe authored Oct 15, 2024
1 parent 3e50dc0 commit 4ac97e7
Show file tree
Hide file tree
Showing 6 changed files with 141 additions and 38 deletions.
31 changes: 14 additions & 17 deletions .github/workflows/python-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,9 @@ jobs:
strategy:
matrix:
python-version:
- "3.9"
- "3.10"
- "3.11"
- "3.12"
- "pypy-3.9"
- "pypy-3.10"

steps:
- uses: actions/checkout@v2
Expand All @@ -32,25 +29,25 @@ jobs:
run: |
python -m pip install --upgrade pip
pip install poetry
poetry install --with test
poetry install --with dev
- name: Lint
run: |
poetry run flake8 nordpool --max-line-length=88
poetry run pylint nordpool
- name: Run tests
run: |
poetry run coverage run -m unittest discover -b
- name: Coveralls
uses: AndreMiras/coveralls-python-action@develop
with:
parallel: true
flag-name: run-${{ matrix.test_number }}
# - name: Coveralls
# uses: AndreMiras/coveralls-python-action@develop
# with:
# parallel: true
# flag-name: run-${{ matrix.test_number }}

finish:
needs: test
runs-on: ubuntu-latest
steps:
- name: Coveralls Finished
uses: AndreMiras/coveralls-python-action@develop
with:
parallel-finished: true
# finish:
# needs: test
# runs-on: ubuntu-latest
# steps:
# - name: Coveralls Finished
# uses: AndreMiras/coveralls-python-action@develop
# with:
# parallel-finished: true
5 changes: 3 additions & 2 deletions nordpool/base.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
# pylint: disable=missing-module-docstring
from dateutil.parser import parse as parse_dt
from pytz import timezone, utc


class CurrencyMismatch(ValueError):
class CurrencyMismatch(ValueError): # pylint: disable=missing-class-docstring
pass


class Base(object):
class Base: # pylint: disable=too-few-public-methods
"""Class for fetching Nord Pool Elspot prices."""

def __init__(self, currency="EUR", timeout=None):
Expand Down
20 changes: 9 additions & 11 deletions nordpool/elbas.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
# -*- encoding: utf-8 -*-
from __future__ import unicode_literals

# pylint: disable=missing-module-docstring
from datetime import date, datetime, timedelta
from socket import timeout

import requests
from dateutil.parser import parse as parse_dt
Expand All @@ -16,7 +13,7 @@ class Prices(Base):
HOURLY = 194
API_URL = "https://www.nordpoolgroup.com/api/marketdata/page/%i"

def _parse_json(self, data, columns, areas):
def _parse_json(self, data, columns, areas): # pylint: disable=too-many-branches
"""
Parse json response from fetcher.
Returns dictionary with
Expand Down Expand Up @@ -51,10 +48,9 @@ def _parse_json(self, data, columns, areas):
# Loop through columns
if r["Name"] is None:
continue
else:
name = " ".join(r["Name"].split("-")).split(" ")
name = " ".join(r["Name"].split("-")).split(" ")
# Picks only "PH" product (hourly)
if not (name[0] == "PH"):
if not name[0] == "PH":
continue
row_start_time = self._parse_dt(
"-".join([name[1], format(int(name[2]) - 1, "02")])
Expand Down Expand Up @@ -118,7 +114,7 @@ def _fetch_json(self, data_type, areas, end_date=None):
# Return JSON response
return r.json()

def fetch(self, data_type, columns, end_date=None, areas=[]):
def fetch(self, data_type, columns, end_date=None, areas=None):
"""
Fetch data from API.
Inputs:
Expand All @@ -145,8 +141,10 @@ def fetch(self, data_type, columns, end_date=None, areas=[]):
def hourly(
self,
end_date=None,
areas=[],
columns=["Product", "High", "Low", "Last", "Avg", "Volume"],
areas=None,
columns=None,
):
"""Helper to fetch hourly data, see Prices.fetch()"""
if columns is None:
columns = ["Product", "High", "Low", "Last", "Avg", "Volume"]
return self.fetch(self.HOURLY, columns, end_date, areas)
12 changes: 8 additions & 4 deletions nordpool/elspot.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# pylint: disable=missing-module-docstring
from datetime import date, datetime, timedelta

from pytz import utc
Expand Down Expand Up @@ -203,21 +204,24 @@ def yearly(self, end_date=None, areas=None):


class AioPrices(Prices):
"""Class for fetching Nord Pool Elspot prices."""

# pylint: disable=invalid-overridden-method

def __init__(self, currency, client):

super().__init__(currency)
self.client = client

async def _io(self, url, params):
import inspect
import inspect # pylint: disable=import-outside-toplevel

resp = await self.client.get(url, params=params)
# aiohttp
if inspect.isawaitable(resp.json()):
return await resp.json()
else:
# Httpx and asks
return resp.json()
# Httpx and asks
return resp.json()

async def _fetch_json(self, data_type, end_date=None, areas=None):
"""Fetch JSON from API"""
Expand Down
107 changes: 104 additions & 3 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ homepage = "https://github.com/kipe/nordpool"
repository = "https://github.com/kipe/nordpool"

[tool.poetry.dependencies]
python = "^3.9"
python = ">=3.10,<3.13"
python-dateutil = "^2.9.0.post0"
requests = "^2.32.3"
pytz = "^2024.2"
Expand All @@ -22,6 +22,8 @@ flake8 = "^7.1.1"
vcrpy = "^6.0.2"
time-machine = "^2.16.0"
coverage = "^7.6.3"
coveralls = "^4.0.1"
pylint = "^3.3.1"

[build-system]
requires = ["poetry-core"]
Expand Down

0 comments on commit 4ac97e7

Please sign in to comment.