Skip to content

Commit 4226874

Browse files
committed
fix(tests): add style testing
Added a new test to tools.sh for style checks using flake8 to ensure code quality. Added flake8 to pyproject dev dependencies.
1 parent 93cb808 commit 4226874

File tree

7 files changed

+26
-12
lines changed

7 files changed

+26
-12
lines changed

.flake8

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
[flake8]
2-
ignore = E261
2+
# Notes:
3+
# W503: https://peps.python.org/pep-0008/#should-a-line-break-before-or-after-a-binary-operator
4+
ignore = E261, W293, W503
35
max-line-length = 200
46
exclude = .git,.github,__pycache__,.pytest_cache,.venv,.venv_test,.vscode
57
max-complexity = 10

.github/workflows/python-package.yml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,8 @@ jobs:
3131
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
3232
- name: Lint with flake8
3333
run: |
34-
# stop the build if th1ere are Python syntax errors or undefined names
35-
# Notes:
36-
# W503: https://peps.python.org/pep-0008/#should-a-line-break-before-or-after-a-binary-operator
37-
flake8 . --count --select=E9,F63,F7,F82 --ignore=E261,W293,W503 --show-source --statistics
34+
# stop the build if there are Python syntax errors or undefined names
35+
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
3836
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
3937
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
4038
- name: Install stat-log-db package (dev)

stat_log_db/pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ dependencies = [
1414
[project.optional-dependencies]
1515
dev = [
1616
"pytest==8.4.1",
17-
"pytest-cov==6.2.1"
17+
"pytest-cov==6.2.1",
18+
"flake8==7.3.0"
1819
]
1920

2021
[project.scripts]

stat_log_db/src/stat_log_db/cli.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,6 @@ def main():
3434
if sl_db.is_file:
3535
os.remove(sl_db.file_name)
3636

37+
3738
if __name__ == "__main__":
3839
main()

stat_log_db/src/stat_log_db/db.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ def execute(self, query: str, parameters: tuple | None = None):
296296
if not isinstance(query, str):
297297
raise_auto_arg_type_error("query")
298298
if len(query) == 0:
299-
raise ValueError(f"'query' argument of execute cannot be an empty string!")
299+
raise ValueError("'query' argument of execute cannot be an empty string!")
300300
# Create a new space in memory that points to the same object that `parameters` points to
301301
params = parameters
302302
# If `params` points to None, update it to point to an empty tuple
@@ -381,7 +381,7 @@ def create_table(self, table_name: str, columns: list[tuple[str, str]], temp_tab
381381
if not isinstance(table_name, str):
382382
raise_auto_arg_type_error("table_name")
383383
if len(table_name) == 0:
384-
raise ValueError(f"'table_name' argument of create_table cannot be an empty string!")
384+
raise ValueError("'table_name' argument of create_table cannot be an empty string!")
385385

386386
# Validate and sanitize table name
387387
validated_table_name = self._validate_sql_identifier(table_name, "table name")

tests/test_tools.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ def _find_bash_executable(): # TODO: Improve this
7070
# If we get here, bash was not found
7171
raise FileNotFoundError(
7272
"Git Bash not found. Please install Git for Windows from https://git-scm.com/download/win "
73-
"or ensure bash.exe is in your PATH. Tried the following locations:\n" +
74-
"\n".join(f" - {path}" for path in common_paths)
73+
"or ensure bash.exe is in your PATH. Tried the following locations:\n"
74+
+ "\n".join(f" - {path}" for path in common_paths)
7575
)
7676

7777

@@ -121,7 +121,6 @@ def test_help():
121121
except AssertionError:
122122
assert out.strip() == readme_content.strip(), "Help output does not match README content (leading & trailing whitespace stripped)"
123123

124-
125124
@pytest.mark.skipif(GITHUB_ACTIONS, reason="Skipping test on GitHub Actions")
126125
def test_install_dev(test_venv):
127126
code, out = run_tools(["-id"], use_test_venv=True)
@@ -186,6 +185,14 @@ def test_test_invalid_arg():
186185
assert ("Unsupported argument" in out) or ("Invalid test mode" in out)
187186

188187

188+
@pytest.mark.skipif(GITHUB_ACTIONS, reason="Skipping test on GitHub Actions")
189+
def test_test_style():
190+
code, out = run_tools(["-ts"])
191+
assert code == 0
192+
assert "Running style tests" in out
193+
assert "flake8" in out
194+
195+
189196
@pytest.mark.skipif(GITHUB_ACTIONS, reason="Skipping test on GitHub Actions")
190197
def test_clean():
191198
code, out = run_tools(["-c"])

tools.sh

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ supported_installation_opts="d n"
55
install=""
66
uninstall=0
77
clean=0
8-
supported_test_opts="p t a d"
8+
supported_test_opts="p t a d s"
99
test=""
1010

1111
while getopts ":i:t:chu" flag; do
@@ -68,6 +68,11 @@ if [ -n "$test" ]; then
6868
echo "Running all tests..."
6969
pytest
7070
;;
71+
s)
72+
echo "Running style tests (flake8)..."
73+
flake8 .
74+
# flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
75+
;;
7176
*)
7277
echo "Invalid test mode '$test'. Use one of: $supported_test_opts" >&2
7378
exit 1

0 commit comments

Comments
 (0)