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

Initial setup of pytest #142

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
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
19 changes: 19 additions & 0 deletions noxfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
"""Automated testing."""
import nox


@nox.session()
def formatting(session):
"""Will tests current codebase for formatting."""
session.install("black", "flake8", "isort", "flake8-docstrings")
session.run("isort", "entsoe/", "tests/", "--check-only")
session.run("flake8", "entsoe/", "tests/", "--max-line-length=88", "--docstring-convention", "numpy")
session.run("black", "entsoe/", "tests/", "--check")


@nox.session(python=['3.7', '3.9'])
def tests(session):
"""Will execute tests on codebase."""
session.install("pytest", "pytest-cov", "pytest-mock", "requests_mock")
session.install("-e", ".")
session.run("pytest", "--cov=entsoe", "--cov-report=html", "tests/")
10 changes: 10 additions & 0 deletions requirements/dev.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
-r requirements.txt

nox
flake8
flake8-docstrings
black
isort
pytest-mock
pytest-cov
requests_mock
File renamed without changes.
30 changes: 30 additions & 0 deletions tests/test_rawclient.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import pandas as pd
import pytest
import requests as r
import requests_mock

from entsoe import EntsoeRawClient

start = pd.Timestamp("20171201", tz="Europe/Brussels")
end = pd.Timestamp("20180101", tz="Europe/Brussels")
country_code = "BE" # Belgium
country_code_from = "FR" # France
country_code_to = "DE_LU" # Germany-Luxembourg
type_marketagreement_type = "A01"
URL = "https://transparency.entsoe.eu/api"


def test_invalid_rawclient():
"""Will initiate RawClient without API key."""
with pytest.raises(TypeError):
EntsoeRawClient()


def test_rawclient_get_exception():
"""Will test if exception handling is triggered in _base_request."""
rm = requests_mock.Mocker()

with pytest.raises(r.HTTPError):
rm.get(URL, status_code=500)
client = EntsoeRawClient(api_key="test123")
client.query_load(country_code, start, end)