Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
my2to3
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Jobs
Commits
Open sidebar
nexedi
my2to3
Commits
eedbf224
Commit
eedbf224
authored
Aug 04, 2020
by
Bryton Lacquement
🚪
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fixup! trace: use temporary connections to the database
This fixes commit
575a5354
.
parent
575a5354
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
14 additions
and
13 deletions
+14
-13
my2to3/tests/__init__.py
my2to3/tests/__init__.py
+2
-2
my2to3/trace.py
my2to3/trace.py
+12
-11
No files found.
my2to3/tests/__init__.py
View file @
eedbf224
from
lib2to3.tests.test_fixers
import
FixerTestCase
as
lib2to3FixerTestCase
import
sqlite3
from
my2to3.trace
import
conn
,
get_data
,
tracing_functions
from
my2to3.trace
import
conn
ection
,
get_data
,
tracing_functions
class
FixerTestCase
(
lib2to3FixerTestCase
):
...
...
@@ -10,7 +10,7 @@ class FixerTestCase(lib2to3FixerTestCase):
super
(
FixerTestCase
,
self
).
setUp
(
fix_list
,
fixer_pkg
,
options
)
# Clear the database
with
conn
:
with
conn
ection
()
as
conn
:
for
table
in
conn
.
execute
(
"SELECT name FROM sqlite_master WHERE type='table'"
).
fetchall
():
conn
.
execute
(
"DELETE FROM %s"
%
table
)
...
...
my2to3/trace.py
View file @
eedbf224
import
__builtin__
,
imp
,
os
,
sqlite3
,
sys
,
types
from
contextlib
import
contextmanager
from
lib2to3.pgen2
import
tokenize
from
lib2to3.refactor
import
get_fixers_from_package
,
RefactoringTool
database
=
"traces.db"
@
contextmanager
def
connection
():
conn
=
sqlite3
.
connect
(
database
)
try
:
with
conn
:
yield
conn
finally
:
conn
.
close
()
tracing_functions
=
[]
def
create_table
(
table
,
*
columns
):
conn
=
sqlite3
.
connect
(
database
)
with
conn
:
with
connection
()
as
conn
:
v
=
', '
.
join
(
columns
)
conn
.
execute
(
"CREATE TABLE IF NOT EXISTS %s (%s, UNIQUE (%s))"
%
(
table
,
v
,
v
)
)
conn
.
close
()
def
insert_unique
(
*
values
):
conn
=
sqlite3
.
connect
(
database
)
with
conn
:
with
connection
()
as
conn
:
try
:
conn
.
execute
(
'INSERT INTO %s VALUES (%s)'
%
(
table
,
', '
.
join
(
'?'
*
len
(
values
))),
...
...
@@ -29,7 +33,6 @@ def create_table(table, *columns):
except
sqlite3
.
IntegrityError
as
e
:
if
not
str
(
e
).
startswith
(
'UNIQUE constraint failed:'
):
raise
conn
.
close
()
return
insert_unique
...
...
@@ -46,10 +49,8 @@ def get_data(table, columns_to_select='*', conditions={}):
)
if
conditions
:
query
+=
" WHERE "
+
' AND '
.
join
(
k
+
" = :"
+
k
for
k
in
conditions
.
keys
())
conn
=
sqlite3
.
connect
(
database
)
with
conn
:
with
connection
()
as
conn
:
return
conn
.
execute
(
query
,
conditions
).
fetchall
()
conn
.
close
()
def
apply_fixers
(
string
,
name
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment