Skip to content

Commit 25dab08

Browse files
authored
Make the tests really run, and fix test failures (#78)
* Revert addition of timezone that caused test failures * Fix comparison with True in SQLAlchemy query * Install sqlalchemy and whoosh when running tests
1 parent 142b41e commit 25dab08

File tree

5 files changed

+10
-7
lines changed

5 files changed

+10
-7
lines changed

.github/workflows/test.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ jobs:
4444
- name: Install dependencies
4545
run: |
4646
python -m pip install --upgrade pip
47-
python -m pip install .[test]
47+
python -m pip install .[test,whoosh]
4848
4949
- name: Test with pytest
5050
run: python -m pytest -vv --durations 25

pyproject.toml

+2
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,11 @@ enable_error_code = [
116116

117117
[[tool.mypy.overrides]]
118118
module = [
119+
"pytest",
119120
"sqlalchemy",
120121
"sqlalchemy.orm",
121122
"sqlalchemy.sql",
123+
"sqlalchemy.sql.expression",
122124
"whoosh",
123125
"whoosh.analysis",
124126
"whoosh.fields",

sphinxcontrib/websupport/storage/sqlalchemy_db.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@
55

66
from __future__ import annotations
77

8-
from datetime import datetime, timezone
8+
from datetime import datetime
99

1010
from sqlalchemy import Boolean, Column, DateTime, ForeignKey, Integer, String, Text
1111
from sqlalchemy.orm import aliased, declarative_base, relationship, sessionmaker
12+
from sqlalchemy.sql.expression import true
1213

1314
Base = declarative_base()
1415
Session = sessionmaker()
@@ -51,7 +52,7 @@ def nested_comments(self, username, moderator):
5152

5253
# Filter out all comments that are not moderated yet.
5354
if not moderator:
54-
q = q.filter(Comment.displayed is True)
55+
q = q.filter(Comment.displayed == true())
5556

5657
# Retrieve all results. Results must be ordered by Comment.path
5758
# so that we can easily transform them from a flat list to a tree.
@@ -159,7 +160,7 @@ def serializable(self, vote=0):
159160
"""Creates a serializable representation of the comment. This is
160161
converted to JSON, and used on the client side.
161162
"""
162-
delta = datetime.now(tz=timezone.utc) - self.time
163+
delta = datetime.now() - self.time # noqa: DTZ005
163164

164165
time = {
165166
"year": self.time.year,

sphinxcontrib/websupport/storage/sqlalchemystorage.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from __future__ import annotations
44

5-
from datetime import datetime, timezone
5+
from datetime import datetime
66

77
import sqlalchemy
88
from sqlalchemy.orm import aliased
@@ -72,7 +72,7 @@ def add_comment(self, text, displayed, username, time,
7272
raise CommentNotAllowedError(msg)
7373

7474
comment = Comment(text, displayed, username, 0,
75-
time or datetime.now(tz=timezone.utc), proposal, proposal_diff)
75+
time or datetime.now(), proposal, proposal_diff) # noqa: DTZ005
7676
session.add(comment)
7777
session.flush()
7878
# We have to flush the session before setting the path so the

tests/conftest.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@
99
)
1010

1111

12-
@pytest.fixture(scope='session')
12+
@pytest.fixture(scope='session') # type: ignore[misc]
1313
def rootdir() -> Path:
1414
return Path(__file__).resolve().parent / 'roots'

0 commit comments

Comments
 (0)