◐ Shell
clean mode source ↗

bpo-26187: Tests sqlite3 trace callback no duplicate on shcema changing by palaviv · Pull Request #461 · python/cpython

berkerpeksag

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please also add a note to Misc/NEWS and mention the v2 API change.

@unittest.skipIf(sqlite.sqlite_version_info < (3, 3, 9), "sqlite3_prepare_v2 is not available")
def CheckTraceCallbackContent(self):
"""
Test that the statement are correct. Fix for bpo-26187

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Docstring is not needed here. Just add a comment with a reference to bpo-26187.


import unittest
import sqlite3 as sqlite
from tempfile import NamedTemporaryFile

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: I'd prefer import tempfile.

def trace(statement):
traced_statements.append(statement)

queries = ["create table foo(x)",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

traced_statements, trace and queries can go outside of the with statements.

"""
Test that the statement are correct. Fix for bpo-26187
"""
with NamedTemporaryFile(suffix='.sqlite') as db_path:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NamedTemporaryFile is known to be problematic on Windows. Did you check that it cleanups the temp file?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will look what they do in other test's and copy it.

con2.execute("create table bar(x)")
cur.execute(queries[1])
self.assertEqual(traced_statements, queries)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: Please delete the extra new line.