Skip to content

Commit 8c6d8b1

Browse files
committed
a few edge cases around comments and trailing slashes in assert statements
1 parent 45e0569 commit 8c6d8b1

4 files changed

Lines changed: 32 additions & 2 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file. This projec
44

55
## [Unreleased]
66

7+
## [1.0.7] - September 16th 2021
8+
9+
- Another edge case involving multi-line comments and trailing slashes
10+
711
## [1.0.6] - September 16th 2021
812

913
- Fix edge case where commas in multiline asserts don't have trailing slashes but should

pytestify/fixes/asserts.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ def add_slashes(call: Call, content_list: List[str]) -> None:
200200
for i in range(call.line, call.end_line):
201201
line = content_list[i]
202202

203-
if line.endswith(',') and comma and comma.line - 1 == i:
203+
if line.endswith(',') and comma and comma.line == i - call.line + 1:
204204
# this is on multiline asserts with an error message
205205
# otherwise, the comma is probably between elements in a sequence
206206
pass

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[metadata]
22
name = pytestify
3-
version = 1.0.6
3+
version = 1.0.7
44
description = Automatically convert unittests to pytest
55
long_description = file: README.md
66
long_description_content_type = text/markdown

tests/fixes/test_asserts.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,32 @@ def test_rewrite_complex_asserts(before, after):
165165
' b, \\\n'
166166
" 'Error'",
167167
),
168+
(
169+
'# some comment\n'
170+
'self.assertEquals(\n'
171+
' a,\n'
172+
' b,\n'
173+
" msg='Error'\n"
174+
')',
175+
'# some comment\n'
176+
'assert a == \\\n'
177+
' b, \\\n'
178+
" 'Error'",
179+
),
180+
(
181+
'# some comment\n'
182+
'# some other comment\n'
183+
'self.assertEquals(\n'
184+
' a,\n'
185+
' b,\n'
186+
" msg='Error'\n"
187+
')',
188+
'# some comment\n'
189+
'# some other comment\n'
190+
'assert a == \\\n'
191+
' b, \\\n'
192+
" 'Error'",
193+
),
168194
(
169195
'self.assertEquals(\n'
170196
' a, # some comment\n'

0 commit comments

Comments
 (0)