Skip to content

Commit 4ac97e7

Browse files
authored
Test and pylint -fixes (#38)
* 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
1 parent 3e50dc0 commit 4ac97e7

File tree

6 files changed

+141
-38
lines changed

6 files changed

+141
-38
lines changed

.github/workflows/python-test.yml

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,9 @@ jobs:
1515
strategy:
1616
matrix:
1717
python-version:
18-
- "3.9"
1918
- "3.10"
2019
- "3.11"
2120
- "3.12"
22-
- "pypy-3.9"
23-
- "pypy-3.10"
2421

2522
steps:
2623
- uses: actions/checkout@v2
@@ -32,25 +29,25 @@ jobs:
3229
run: |
3330
python -m pip install --upgrade pip
3431
pip install poetry
35-
poetry install --with test
32+
poetry install --with dev
3633
- name: Lint
3734
run: |
3835
poetry run flake8 nordpool --max-line-length=88
3936
poetry run pylint nordpool
4037
- name: Run tests
4138
run: |
4239
poetry run coverage run -m unittest discover -b
43-
- name: Coveralls
44-
uses: AndreMiras/coveralls-python-action@develop
45-
with:
46-
parallel: true
47-
flag-name: run-${{ matrix.test_number }}
40+
# - name: Coveralls
41+
# uses: AndreMiras/coveralls-python-action@develop
42+
# with:
43+
# parallel: true
44+
# flag-name: run-${{ matrix.test_number }}
4845

49-
finish:
50-
needs: test
51-
runs-on: ubuntu-latest
52-
steps:
53-
- name: Coveralls Finished
54-
uses: AndreMiras/coveralls-python-action@develop
55-
with:
56-
parallel-finished: true
46+
# finish:
47+
# needs: test
48+
# runs-on: ubuntu-latest
49+
# steps:
50+
# - name: Coveralls Finished
51+
# uses: AndreMiras/coveralls-python-action@develop
52+
# with:
53+
# parallel-finished: true

nordpool/base.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1+
# pylint: disable=missing-module-docstring
12
from dateutil.parser import parse as parse_dt
23
from pytz import timezone, utc
34

45

5-
class CurrencyMismatch(ValueError):
6+
class CurrencyMismatch(ValueError): # pylint: disable=missing-class-docstring
67
pass
78

89

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

1213
def __init__(self, currency="EUR", timeout=None):

nordpool/elbas.py

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
1-
# -*- encoding: utf-8 -*-
2-
from __future__ import unicode_literals
3-
1+
# pylint: disable=missing-module-docstring
42
from datetime import date, datetime, timedelta
5-
from socket import timeout
63

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

19-
def _parse_json(self, data, columns, areas):
16+
def _parse_json(self, data, columns, areas): # pylint: disable=too-many-branches
2017
"""
2118
Parse json response from fetcher.
2219
Returns dictionary with
@@ -51,10 +48,9 @@ def _parse_json(self, data, columns, areas):
5148
# Loop through columns
5249
if r["Name"] is None:
5350
continue
54-
else:
55-
name = " ".join(r["Name"].split("-")).split(" ")
51+
name = " ".join(r["Name"].split("-")).split(" ")
5652
# Picks only "PH" product (hourly)
57-
if not (name[0] == "PH"):
53+
if not name[0] == "PH":
5854
continue
5955
row_start_time = self._parse_dt(
6056
"-".join([name[1], format(int(name[2]) - 1, "02")])
@@ -118,7 +114,7 @@ def _fetch_json(self, data_type, areas, end_date=None):
118114
# Return JSON response
119115
return r.json()
120116

121-
def fetch(self, data_type, columns, end_date=None, areas=[]):
117+
def fetch(self, data_type, columns, end_date=None, areas=None):
122118
"""
123119
Fetch data from API.
124120
Inputs:
@@ -145,8 +141,10 @@ def fetch(self, data_type, columns, end_date=None, areas=[]):
145141
def hourly(
146142
self,
147143
end_date=None,
148-
areas=[],
149-
columns=["Product", "High", "Low", "Last", "Avg", "Volume"],
144+
areas=None,
145+
columns=None,
150146
):
151147
"""Helper to fetch hourly data, see Prices.fetch()"""
148+
if columns is None:
149+
columns = ["Product", "High", "Low", "Last", "Avg", "Volume"]
152150
return self.fetch(self.HOURLY, columns, end_date, areas)

nordpool/elspot.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# pylint: disable=missing-module-docstring
12
from datetime import date, datetime, timedelta
23

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

204205

205206
class AioPrices(Prices):
207+
"""Class for fetching Nord Pool Elspot prices."""
208+
209+
# pylint: disable=invalid-overridden-method
210+
206211
def __init__(self, currency, client):
207212

208213
super().__init__(currency)
209214
self.client = client
210215

211216
async def _io(self, url, params):
212-
import inspect
217+
import inspect # pylint: disable=import-outside-toplevel
213218

214219
resp = await self.client.get(url, params=params)
215220
# aiohttp
216221
if inspect.isawaitable(resp.json()):
217222
return await resp.json()
218-
else:
219-
# Httpx and asks
220-
return resp.json()
223+
# Httpx and asks
224+
return resp.json()
221225

222226
async def _fetch_json(self, data_type, end_date=None, areas=None):
223227
"""Fetch JSON from API"""

poetry.lock

Lines changed: 104 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ homepage = "https://github.com/kipe/nordpool"
99
repository = "https://github.com/kipe/nordpool"
1010

1111
[tool.poetry.dependencies]
12-
python = "^3.9"
12+
python = ">=3.10,<3.13"
1313
python-dateutil = "^2.9.0.post0"
1414
requests = "^2.32.3"
1515
pytz = "^2024.2"
@@ -22,6 +22,8 @@ flake8 = "^7.1.1"
2222
vcrpy = "^6.0.2"
2323
time-machine = "^2.16.0"
2424
coverage = "^7.6.3"
25+
coveralls = "^4.0.1"
26+
pylint = "^3.3.1"
2527

2628
[build-system]
2729
requires = ["poetry-core"]

0 commit comments

Comments
 (0)