|
1 | 1 | import pytest |
2 | 2 |
|
3 | 3 | from MySQLdb import _mysql |
| 4 | +from MySQLdb.connections import Connection |
4 | 5 |
|
5 | 6 |
|
6 | 7 | def test_result_type(): |
7 | 8 | with pytest.raises(TypeError): |
8 | 9 | _mysql.result(b"xyz") |
| 10 | + |
| 11 | + |
| 12 | +@pytest.mark.parametrize("connection_type", [_mysql.connection, Connection]) |
| 13 | +@pytest.mark.parametrize("name", [5, None, b"closed", [], {}]) |
| 14 | +def test_connection_getattribute_non_string(connection_type, name): |
| 15 | + conn = connection_type.__new__(connection_type) |
| 16 | + with pytest.raises(TypeError): |
| 17 | + conn.__getattribute__(name) |
| 18 | + |
| 19 | + |
| 20 | +@pytest.mark.parametrize("connection_type", [_mysql.connection, Connection]) |
| 21 | +@pytest.mark.parametrize("name", ["missing", "closed\x00suffix", "\ud800"]) |
| 22 | +def test_connection_getattribute_missing(connection_type, name): |
| 23 | + conn = connection_type.__new__(connection_type) |
| 24 | + with pytest.raises(AttributeError): |
| 25 | + conn.__getattribute__(name) |
| 26 | + |
| 27 | + |
| 28 | +@pytest.mark.parametrize("connection_type", [_mysql.connection, Connection]) |
| 29 | +def test_connection_getattribute(connection_type): |
| 30 | + class AttributeName(str): |
| 31 | + pass |
| 32 | + |
| 33 | + conn = connection_type.__new__(connection_type) |
| 34 | + assert conn.closed == 1 |
| 35 | + assert conn.__getattribute__(AttributeName("closed")) == 1 |
| 36 | + assert conn.__class__ is connection_type |
0 commit comments