Visitar URL original
bpo-42213: Remove redundant cyclic GC hack in sqlite3 by erlend-aasland · Pull Request #26462 · python/cpython · GitHub
Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Address review: Explicitly close opened database files
  • Loading branch information
Erlend E. Aasland
Erlend E. Aasland committed Jun 2, 2021
commit b53aacbc60abe110c4fd144470ed3c29783718f3
14 changes: 12 additions & 2 deletions Lib/sqlite3/test/dbapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,26 +170,35 @@ def test_in_transaction_ro(self):
with self.assertRaises(AttributeError):
self.cx.in_transaction = True


class OpenTests(unittest.TestCase):
def tearDown(self):
unlink(TESTFN)

def test_open_with_path_like_object(self):
""" Checks that we can successfully connect to a database using an object that
is PathLike, i.e. has __fspath__(). """
self.addCleanup(unlink, TESTFN)
class Path:
def __fspath__(self):
return TESTFN
path = Path()
with sqlite.connect(path) as cx:
cx.execute('create table test(id integer)')
cx.close()
Comment thread
erlend-aasland marked this conversation as resolved.
Outdated

def test_open_uri(self):
self.addCleanup(unlink, TESTFN)
with sqlite.connect(TESTFN) as cx:
cx.execute('create table test(id integer)')
cx.close()

with sqlite.connect('file:' + TESTFN, uri=True) as cx:
cx.execute('insert into test(id) values(0)')
cx.close()

with sqlite.connect('file:' + TESTFN + '?mode=ro', uri=True) as cx:
with self.assertRaises(sqlite.OperationalError):
cx.execute('insert into test(id) values(1)')
cx.close()


class CursorTests(unittest.TestCase):
Expand Down Expand Up @@ -942,6 +951,7 @@ def suite():
CursorTests,
ExtensionTests,
ModuleTests,
OpenTests,
SqliteOnConflictTests,
ThreadTests,
]
Expand Down
2 changes: 2 additions & 0 deletions Lib/sqlite3/test/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,8 @@ def trace(statement):
cur.execute(queries[0])
con2.execute("create table bar(x)")
cur.execute(queries[1])
con1.close()
con2.close()
Comment thread
erlend-aasland marked this conversation as resolved.
Outdated
self.assertEqual(traced_statements, queries)


Expand Down