Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Backend
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container Registry
Analyze
Contributor analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Arkindex
Backend
Commits
cf83bed8
Commit
cf83bed8
authored
4 years ago
by
Erwan Rouchet
Committed by
Bastien Abadie
4 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Ignore comments in assertExactQueries
parent
bdfeff47
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!1308
Ignore comments in assertExactQueries
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
arkindex/project/tests/__init__.py
+21
-7
21 additions, 7 deletions
arkindex/project/tests/__init__.py
with
21 additions
and
7 deletions
arkindex/project/tests/__init__.py
+
21
−
7
View file @
cf83bed8
import
re
from
pathlib
import
Path
from
typing
import
Any
,
Callable
,
Iterable
,
Mapping
,
Optional
,
Union
...
...
@@ -29,12 +30,25 @@ class _AssertExactQueriesContext(CaptureQueriesContext):
super
().
__init__
(
connection
)
def
_format
(
self
,
query
:
str
)
->
str
:
return
sqlparse
.
format
(
query
,
reindent
=
True
,
use_space_around_operators
=
True
,
indent_width
=
4
,
).
strip
()
"""
Format one or more SQL queries.
Does not allow more than two newlines at once (at most one empty line).
This still allows separating with empty lines in the expected SQL file,
but prevents duplicate empty lines from appearing;
sqlparse.format duplicates an empty line when it encounters one, causing assertion errors.
"""
return
re
.
sub
(
r
'
\n\n+
'
,
'
\n\n
'
,
sqlparse
.
format
(
query
,
reindent
=
True
,
strip_comments
=
True
,
use_space_around_operators
=
True
,
indent_width
=
4
,
).
strip
()
)
def
__exit__
(
self
,
exc_type
,
exc_value
,
traceback
):
super
().
__exit__
(
exc_type
,
exc_value
,
traceback
)
...
...
@@ -64,7 +78,7 @@ class _AssertExactQueriesContext(CaptureQueriesContext):
)
# Ignore newlines in the expected SQL, otherwise the reformatting might have duplicate line breaks
expected_sql
=
self
.
path
.
read_text
().
strip
()
.
replace
(
'
\n
'
,
'
'
)
expected_sql
=
self
.
path
.
read_text
().
strip
()
# Apply str.format on the SQL when needed to handle variable IDs
if
self
.
params
:
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment