Skip to content

Commit

Permalink
i
Browse files Browse the repository at this point in the history
  • Loading branch information
tlocke committed Apr 28, 2024
1 parent f74cb9a commit c31cfeb
Showing 1 changed file with 17 additions and 12 deletions.
29 changes: 17 additions & 12 deletions test/dbapi/test_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ def test_unix_socket_missing():
conn_params = {"unix_sock": "/file-does-not-exist", "user": "doesn't-matter"}

with pytest.raises(InterfaceError):
with connect(**conn_params) as con:
con.close()
with connect(**conn_params):
pass


def test_internet_socket_connection_refused():
Expand All @@ -23,7 +23,8 @@ def test_internet_socket_connection_refused():
match="Can't create a connection to host localhost and port 0 "
"\\(timeout is None and source_address is None\\).",
):
connect(**conn_params)
with connect(**conn_params):
pass


def test_Connection_plain_socket(db_kwargs):
Expand All @@ -37,34 +38,37 @@ def test_Connection_plain_socket(db_kwargs):
"ssl_context": False,
}

con = connect(**conn_params)
cur = con.cursor()
with connect(**conn_params) as con:
cur = con.cursor()

cur.execute("SELECT 1")
res = cur.fetchall()
assert res[0][0] == 1
cur.execute("SELECT 1")
res = cur.fetchall()
assert res[0][0] == 1


def test_database_missing(db_kwargs):
db_kwargs["database"] = "missing-db"
with pytest.raises(DatabaseError):
connect(**db_kwargs)
with connect(**db_kwargs):
pass


def test_database_name_unicode(db_kwargs):
db_kwargs["database"] = "pg8000_sn\uFF6Fw"

# Should only raise an exception saying db doesn't exist
with pytest.raises(DatabaseError, match="3D000"):
connect(**db_kwargs)
with connect(**db_kwargs):
pass


def test_database_name_bytes(db_kwargs):
"""Should only raise an exception saying db doesn't exist"""

db_kwargs["database"] = bytes("pg8000_sn\uFF6Fw", "utf8")
with pytest.raises(DatabaseError, match="3D000"):
connect(**db_kwargs)
with connect(**db_kwargs):
pass


def test_password_bytes(con, db_kwargs):
Expand Down Expand Up @@ -106,7 +110,8 @@ def test_application_name_integer(db_kwargs):
InterfaceError,
match="The parameter application_name can't be of type " "<class 'int'>.",
):
connect(**db_kwargs)
with connect(**db_kwargs):
pass


def test_application_name_bytearray(db_kwargs):
Expand Down

0 comments on commit c31cfeb

Please sign in to comment.