]> git.ipfire.org Git - thirdparty/psycopg.git/commitdiff
Check that tzinfo.utcoffset() does not return None in conninfo tests
authorDenis Laxalde <denis.laxalde@dalibo.com>
Fri, 5 Nov 2021 08:27:45 +0000 (09:27 +0100)
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>
Wed, 10 Nov 2021 01:57:39 +0000 (02:57 +0100)
Avoids mypy error:
  error: Item "None" of "Optional[timedelta]" has no attribute "total_seconds"  [union-attr]

Now test_conninfo.py type checks.

pyproject.toml
tests/test_conninfo.py

index 3872d51622bda8334d3a53f2b842d58b86e17861..42c7e27f4a22ea3a078716bef2cd089dd3a457ed 100644 (file)
@@ -23,6 +23,7 @@ files = [
     "tests/pool",
     "tests/pq",
     "tests/scripts",
+    "tests/test_conninfo.py",
     "tests/test_dns*",
     "tests/test_psycopg_dbapi20.py",
     "tests/test_sql.py",
index c210a3b375a264d06f59d3f9884e9bca55e550c3..4d098d24d052107e49c263c28a7455304cd756a1 100644 (file)
@@ -227,8 +227,10 @@ class TestConnectionInfo:
         conn.execute("set timezone to 'Europe/Rome'")
         tz = conn.info.timezone
         assert isinstance(tz, dt.tzinfo)
-        assert tz.utcoffset(dt.datetime(2000, 1, 1)).total_seconds() == 3600
-        assert tz.utcoffset(dt.datetime(2000, 7, 1)).total_seconds() == 7200
+        offset = tz.utcoffset(dt.datetime(2000, 1, 1))
+        assert offset and offset.total_seconds() == 3600
+        offset = tz.utcoffset(dt.datetime(2000, 7, 1))
+        assert offset and offset.total_seconds() == 7200
 
     def test_timezone_warn(self, conn, caplog):
         conn.execute("set timezone to 'FOOBAR0'")