Skip to content

Commit

Permalink
add linters (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
vmagueta authored Jun 25, 2024
1 parent 715b239 commit 7aa2428
Show file tree
Hide file tree
Showing 15 changed files with 105 additions and 26 deletions.
27 changes: 26 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,33 @@ on:
workflow_dispatch:




jobs:
lint:
strategy:
fail-fast: true
matrix:
python-version: ['3.12']
os: [ubuntu-latest]
runs-on: ${{matrix.os}}
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
with:
python-version: ${{matrix.python-version}}
- name: Install Project
run: pip install '.[test]'
- name: Look for style errors
run: pflake8
- name: Checking for importing style
run: isort --profile=black --check --diff dundie tests integration
- name: Look for auto format errors
run: black --check --diff dundie tests integration


tests:
needs: lint
strategy:
fail-fast: false
matrix:
Expand All @@ -27,7 +52,7 @@ jobs:
- name: Install Project
run: pip install '.[test]'
- name: Run tests
run: pytest --junitxml=test-result.xml
run: pytest -v --junitxml=test-result.xml
- name: Publish Test Results
uses: EnricoMi/[email protected]
if: always()
Expand Down
11 changes: 10 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.PHONY: install virtualenv ipython clean test
.PHONY: install virtualenv ipython clean test pflake8


install:
Expand All @@ -14,6 +14,15 @@ ipython:
@.venv/bin/ipython


fmt:
@.venv/bin/isort dundie tests integration
@.venv/bin/black dundie tests integration


lint:
@.venv/bin/pflake8


test:
@.venv/bin/pytest -s

Expand Down
1 change: 0 additions & 1 deletion dundie/__main__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from dundie.cli import main


if __name__ == "__main__":
main()
11 changes: 4 additions & 7 deletions dundie/cli.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import argparse
from dundie.core import load

from dundie.core import load # noqa


def main():
Expand All @@ -12,15 +13,11 @@ def main():
type=str,
help="The subcommand to run",
choices=("load", "show", "send"),
default="help"
default="help",
)
parser.add_argument(
"filepath",
type=str,
help="Filepath to load",
default=None
"filepath", type=str, help="Filepath to load", default=None
)
args = parser.parse_args()


print(*globals()[args.subcommand](args.filepath))
1 change: 1 addition & 0 deletions dundie/core.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Core module of dundie"""

from dundie.utils.log import get_logger

log = get_logger()
Expand Down
12 changes: 6 additions & 6 deletions dundie/utils/log.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import os
import logging
import os
from logging import handlers

LOG_LEVEL = os.getenv("LOG_LEVEL", "WARNING").upper()
log = logging.getLogger("dundie")
fmt = logging.Formatter(
'%(asctime)s %(name)s %(levelname)s '
'l:%(lineno)d f:%(filename)s: %(message)s'
"%(asctime)s %(name)s %(levelname)s "
"l:%(lineno)d f:%(filename)s: %(message)s"
)


def get_logger(logfile="dundie.log"):
"""Returns a configured logger."""
#ch = logging.StreamHandler() # Console/terminal/stderr
#ch.setLevel(log_level)
# ch = logging.StreamHandler() # Console/terminal/stderr
# ch.setLevel(log_level)
fh = handlers.RotatingFileHandler(
logfile,
maxBytes=10**6,
Expand All @@ -22,6 +22,6 @@ def get_logger(logfile="dundie.log"):
fh.setLevel(LOG_LEVEL)
# ch.setFormatter(fmt)
fh.setFormatter(fmt)
#log.addHandler(ch)
# log.addHandler(ch)
log.addHandler(fh)
return log
6 changes: 5 additions & 1 deletion integration/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,9 @@
low: Low priority
"""


def pytest_configure(config):
map(lambda line: config.addinivalue_line("markers", line), MARKER.split("\n"))
map(
lambda line: config.addinivalue_line("markers", line),
MARKER.split("\n"),
)
18 changes: 11 additions & 7 deletions integration/test_load.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,28 @@
from subprocess import CalledProcessError, check_output

import pytest
from subprocess import check_output, CalledProcessError


@pytest.mark.integration
@pytest.mark.medium
def test_load_positive_call_load_command():
"""Test command load"""
out = check_output(
["dundie", "load", "assets/people.csv"]
).decode("utf-8").split("\n")
out = (
check_output(["dundie", "load", "assets/people.csv"])
.decode("utf-8")
.split("\n")
)
assert len(out) == 2


@pytest.mark.integration
@pytest.mark.medium
@pytest.mark.parametrize("wrong_command", ["loady", "carrega", "start"])
def test_load_negative_call_load_command_with_wrong_params(wrong_command):
"""Test command load"""
with pytest.raises(CalledProcessError) as error:
check_output(
["dundie", wrong_command, "assets/people.csv"]
).decode("utf-8").split("\n")
check_output(["dundie", wrong_command, "assets/people.csv"]).decode(
"utf-8"
).split("\n")

assert "status 2" in str(error.getrepr())
27 changes: 27 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,30 @@ testpaths = [
"tests",
"integration"
]


[tool.flake8]
exclude = [".venv", "build"]
max-line-length = 79


[tool.black]
line-length = 79
target-version = ["py36", "py37"]
exclude = '''
/(
\.eggs
| \.git
| \.venv
| _build
| build
| dist
| migrations
)/
'''


[tool.isort]
profile = "black"
src_paths = ["dundie", "tests", "integration"]
multi_line_output = 3 # VHI
6 changes: 6 additions & 0 deletions requirements.dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,11 @@ ipdb
pudb
pytest-watch

# Code Quality
flake8
pyproject-flake8
black
isort

# Install project as editable
-e .
4 changes: 4 additions & 0 deletions requirements.test.txt
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
pytest
flake8
pyproject-flake8
black
isort
1 change: 1 addition & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
low: Low priority
"""


def pytest_configure(config):
for line in MARKER.split("\n"):
config.addinivalue_line("markers", line)
2 changes: 1 addition & 1 deletion tests/constants.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
PEOPLE_FILE = 'tests/assets/people.csv'
PEOPLE_FILE = "tests/assets/people.csv"
4 changes: 3 additions & 1 deletion tests/test_load.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import pytest

from dundie.core import load

from .constants import PEOPLE_FILE


Expand All @@ -14,4 +16,4 @@ def test_load_positive_has_2_people(request):
@pytest.mark.high
def test_load_positive_first_name_starts_with_j(request):
"""Test load function starts with letter J."""
assert load(PEOPLE_FILE)[0][0] == 'J'
assert load(PEOPLE_FILE)[0][0] == "J"
Empty file removed tests/utils.py
Empty file.

0 comments on commit 7aa2428

Please sign in to comment.