Skip to content

Commit

Permalink
Add linting to Makefile
Browse files Browse the repository at this point in the history
This commits will extend the `Makefile` introduced in #54 to include a
`lint` command and the `test-package.yml` GitHub actions template
updated to make use of the `make` commands. Additionally, linting will
be applied to the codebase.
  • Loading branch information
smoothml committed Apr 17, 2024
1 parent 799dca4 commit 1b4d438
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 14 deletions.
9 changes: 2 additions & 7 deletions .github/workflows/test-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,10 @@ jobs:
run: |
poetry install --all-extras
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
poetry run flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
poetry run flake8 . --count --exit-zero --max-complexity=10 --max-line-length=119 --statistics --ignore E203,E266,E501,W503
run: make lint
- name: Test with pytest
env:
SQL_MOCK_CLICKHOUSE_HOST: 127.0.0.1
SQL_MOCK_CLICKHOUSE_PORT: 8123
SQL_MOCK_CLICKHOUSE_USER: default
run: |
poetry run pytest tests/
run: make test
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ SHELL := /bin/bash
help: ## Show all available commands
@awk 'BEGIN {FS = ":.*##"; printf "Usage: make \033[36m<target>\033[0m\n"} /^[a-zA-Z_-]+:.*?##/ { printf " \033[36m%-13s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST);

.PHONY: lint
lint: ## Lint code with flake8
poetry run flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics # stop the build if there are Python syntax errors or undefined names
poetry run flake8 . --count --exit-zero --max-complexity=10 --max-line-length=119 --statistics --ignore E203,E266,E501,W503 # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide

.PHONY: test
test: ## Run test pipeline
poetry run pytest tests/
Expand Down
7 changes: 4 additions & 3 deletions src/sql_mock/bigquery/column_mocks.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from typing import Any

from sql_mock.column_mocks import BaseColumnMock


Expand All @@ -7,7 +8,7 @@ class BigQueryColumnMock(BaseColumnMock):


class Boolean(BigQueryColumnMock):
dtype = 'Boolean'
dtype = "Boolean"


class Int(BigQueryColumnMock):
Expand All @@ -33,7 +34,7 @@ def __init__(self, default, precision, scale, nullable=False) -> None:


class Timestamp(BigQueryColumnMock):
dtype = 'Timestamp'
dtype = "Timestamp"


class Array(BigQueryColumnMock):
Expand All @@ -43,7 +44,7 @@ def __init__(
self,
inner_type: BigQueryColumnMock,
default: Any,
nullable: bool=False,
nullable: bool = False,
) -> None:
self.dtype = f"Array<{inner_type.dtype}>"
super().__init__(default, nullable)
3 changes: 2 additions & 1 deletion src/sql_mock/clickhouse/column_mocks.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from typing import Any

from sql_mock.column_mocks import BaseColumnMock


Expand Down Expand Up @@ -50,7 +51,7 @@ def __init__(
self,
inner_type: ClickhouseColumnMock,
default: Any,
nullable: bool=False,
nullable: bool = False,
) -> None:
self.dtype = f"Array({inner_type.dtype})"
super().__init__(default, nullable)
3 changes: 1 addition & 2 deletions tests/sql_mock/redshift/test_column_mocks.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from sql_mock.redshift.column_mocks import RedshiftColumnMock, DECIMAL
from sql_mock.redshift.column_mocks import DECIMAL, RedshiftColumnMock


def test_init_nullable():
Expand Down Expand Up @@ -45,4 +45,3 @@ def test_decimal_initialization_nullable(self):
assert decimal_col.dtype == "DECIMAL(10, 2)"
assert decimal_col.default is None
assert decimal_col.nullable

2 changes: 1 addition & 1 deletion tests/test_table_mocks/test_assert_equal.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class MockTestTable(BaseTableMock):
id="Matching data - Missing keys ignored - Order ignored - including mixed None and int values",
),
pytest.param(
[{"name":None, "age": 25, "city": "New York"}, {"name": "Bob", "age": 30, "city": "Munich"}], # data
[{"name": None, "age": 25, "city": "New York"}, {"name": "Bob", "age": 30, "city": "Munich"}], # data
[{"name": None, "age": 25}, {"name": "Bob", "age": 30}], # expected_data
True, # ignore_missing_keys
True, # ignore_order
Expand Down

0 comments on commit 1b4d438

Please sign in to comment.