isidentical / teyit

Formatter for your Python unit tests
MIT License
104 stars 7 forks source link

Bug: `[self.assert(x in y)]` #22

Open spagh-eddie opened 7 months ago

spagh-eddie commented 7 months ago

MRE:

import unittest

class MyTest(unittest.TestCase):
    def test_mre(self):
        """docstring"""
        [self.assertTrue(0 in ())]
$ teyit test.py 
Traceback (most recent call last):
  ...
  File "<unknown>", line 7
    self.assertIn(0, ())
IndentationError: unexpected indent
Failed to refactor file 'test.py'

This is due to the first pass of rewrite_source() turning the line into ' self.assertIn(0, ())\n', indented by 9 spaces. I would instead expect it to output valid python.

https://github.com/isidentical/teyit/blob/4ca1d27f438ccd396cc868b0e598d77b3150f764/teyit.py#L297-L297