From 16b22d8892b742c7d3ede39f5b47c5ae7abf4023 Mon Sep 17 00:00:00 2001
From: Christian Heller <c.heller@plomlompom.de>
Date: Mon, 10 Feb 2025 14:57:18 +0100
Subject: [PATCH] Move tests directory out of src/.

---
 .mypy.ini                          |  2 ++
 src/.pylintrc => .pylintrc         |  2 +-
 scripts/pre-commit                 | 16 +++++------
 {src/tests => tests}/__init__.py   |  0
 {src/tests => tests}/conditions.py |  0
 {src/tests => tests}/days.py       |  0
 {src/tests => tests}/misc.py       |  0
 {src/tests => tests}/processes.py  |  0
 {src/tests => tests}/todos.py      |  0
 {src/tests => tests}/utils.py      | 45 ++++++++++++++++++++----------
 10 files changed, 40 insertions(+), 25 deletions(-)
 create mode 100644 .mypy.ini
 rename src/.pylintrc => .pylintrc (55%)
 rename {src/tests => tests}/__init__.py (100%)
 rename {src/tests => tests}/conditions.py (100%)
 rename {src/tests => tests}/days.py (100%)
 rename {src/tests => tests}/misc.py (100%)
 rename {src/tests => tests}/processes.py (100%)
 rename {src/tests => tests}/todos.py (100%)
 rename {src/tests => tests}/utils.py (97%)

diff --git a/.mypy.ini b/.mypy.ini
new file mode 100644
index 0000000..e4f7658
--- /dev/null
+++ b/.mypy.ini
@@ -0,0 +1,2 @@
+[mypy]
+mypy_path = $MYPY_CONFIG_FILE_DIR/src
diff --git a/src/.pylintrc b/.pylintrc
similarity index 55%
rename from src/.pylintrc
rename to .pylintrc
index 50133a0..45bc14d 100644
--- a/src/.pylintrc
+++ b/.pylintrc
@@ -1,3 +1,3 @@
 [BASIC]
-init-hook='import sys; sys.path.append(".")'
+init-hook='import sys; sys.path[0:0] = ["src"]'
 good-names-rgxs=(.*_)?(GET|POST)(_.+)?,,test_[A-Z]+
diff --git a/scripts/pre-commit b/scripts/pre-commit
index 21ad816..414cb51 100755
--- a/scripts/pre-commit
+++ b/scripts/pre-commit
@@ -1,13 +1,11 @@
 #!/bin/sh
-cd src
-for dir in $(echo '.' 'plomtask' 'tests'); do
-    echo "Running mypy on ${dir}/ …."
-    python3 -m mypy ${dir}/*.py
-    echo "Running flake8 on ${dir}/ …"
-    python3 -m flake8 ${dir}/*.py
-    echo "Running pylint on ${dir}/ …"
-    python3 -m pylint ${dir}/*.py
+DIRS='src src/plomtask tests'
+TOOLS='flake8 pylint mypy'
+for dir in $DIRS; do
+    for tool in $TOOLS; do
+        echo "Running ${tool} on ${dir}/ …."
+        python3 -m ${tool} ${dir}/*.py
+    done
 done
 echo "Running unittest-parallel on tests/."
 unittest-parallel -t . -s tests/ -p '*.py'
-rm test_db:*
diff --git a/src/tests/__init__.py b/tests/__init__.py
similarity index 100%
rename from src/tests/__init__.py
rename to tests/__init__.py
diff --git a/src/tests/conditions.py b/tests/conditions.py
similarity index 100%
rename from src/tests/conditions.py
rename to tests/conditions.py
diff --git a/src/tests/days.py b/tests/days.py
similarity index 100%
rename from src/tests/days.py
rename to tests/days.py
diff --git a/src/tests/misc.py b/tests/misc.py
similarity index 100%
rename from src/tests/misc.py
rename to tests/misc.py
diff --git a/src/tests/processes.py b/tests/processes.py
similarity index 100%
rename from src/tests/processes.py
rename to tests/processes.py
diff --git a/src/tests/todos.py b/tests/todos.py
similarity index 100%
rename from src/tests/todos.py
rename to tests/todos.py
diff --git a/src/tests/utils.py b/tests/utils.py
similarity index 97%
rename from src/tests/utils.py
rename to tests/utils.py
index a321806..071ad1f 100644
--- a/src/tests/utils.py
+++ b/tests/utils.py
@@ -1,27 +1,42 @@
 """Shared test utilities."""
 # pylint: disable=too-many-lines
+
+# included
 from __future__ import annotations
 from datetime import datetime, date as dt_date, timedelta
-from unittest import TestCase
-from typing import Mapping, Any, Callable
-from threading import Thread
-from pathlib import Path
 from http.client import HTTPConnection
-from time import sleep
 from json import loads as json_loads, dumps as json_dumps
-from urllib.parse import urlencode
-from uuid import uuid4
 from os import remove as remove_file
+from pathlib import Path
 from pprint import pprint
+from sys import path as sys_path
 from tempfile import gettempdir
-from plomtask.db import DatabaseFile, DatabaseConnection
-from plomtask.http import TaskHandler, TaskServer
-from plomtask.processes import Process, ProcessStep
-from plomtask.conditions import Condition
-from plomtask.days import Day
-from plomtask.todos import Todo
-from plomtask.versioned_attributes import VersionedAttribute, TIMESTAMP_FMT
-from plomtask.exceptions import NotFoundException, HandledException
+from threading import Thread
+from time import sleep
+from typing import Mapping, Any, Callable
+from unittest import TestCase
+from urllib.parse import urlencode
+from uuid import uuid4
+
+# ourselves; since we're outside repo's ./src, tell Python to look in there
+NAME_SRC_DIR = 'src'
+sys_path[0:0] = [NAME_SRC_DIR]
+# pylint: disable=wrong-import-position
+from plomtask.db import DatabaseFile, DatabaseConnection  # noqa: E402
+from plomtask.http import TaskHandler, TaskServer  # noqa: E402
+from plomtask.processes import Process, ProcessStep  # noqa: E402
+from plomtask.conditions import Condition  # noqa: E402
+from plomtask.days import Day  # noqa: E402
+from plomtask.todos import Todo  # noqa: E402
+from plomtask.versioned_attributes import (  # noqa: E402
+        VersionedAttribute, TIMESTAMP_FMT)
+from plomtask.exceptions import (  # noqa: E402
+        NotFoundException, HandledException)
+
+
+# to look for schema file in ./src/migrations rather than ./migrations
+DatabaseFile.path_schema = Path(NAME_SRC_DIR
+                                ).joinpath(DatabaseFile.path_schema)
 
 
 _VERSIONED_VALS: dict[str,
-- 
2.30.2