Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

teyit ignores assertRaisesRegexp #21

Open
nega0 opened this issue Aug 17, 2023 · 0 comments
Open

teyit ignores assertRaisesRegexp #21

nega0 opened this issue Aug 17, 2023 · 0 comments

Comments

@nega0
Copy link

nega0 commented Aug 17, 2023

assertRaisesRegexp was renamed to assertRaisesRregex in Python 3.2, and is going away in 3.12. Unfortunately merely adding it to DEPRECATED_ALIASES breaks its use as a context manager

Given:

diff --git a/teyit.py b/teyit.py
index 60f87ad..5798e4c 100644
--- a/teyit.py
+++ b/teyit.py
@@ -44,6 +44,7 @@ DEPRECATED_ALIASES = {
     "assertNotAlmostEquals": "assertNotAlmostEqual",
     "assertRegexpMatches": "assertRegex",
     "assertNotRegexpMatches": "assertNotRegex",
+    "assertRaisesRegexp": "assertRaisesRegex",
 }

and:

import unittest

class foo(unittest.TestCase):
    def testBar(self):
        with self.assertRaisesRegexp(Exception, "message"):
            pass

teyit will wipe out the context manager, and fail with an indentation error:

$ teyit --show-stats t.py
iteration=0
import unittest

class foo(unittest.TestCase):
    def testBar(self):
        with self.assertRaisesRegexp(Exception, "message"):
            pass

calling astparse()
iteration=1
import unittest

class foo(unittest.TestCase):
    def testBar(self):
             self.assertRaisesRegex(Exception, "message")
            pass

calling astparse()
Traceback (most recent call last):
  File "/opt/homebrew/bin/teyit", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/teyit.py", line 401, in main
    raise SystemExit(_refactor_files(**vars(options)))
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/teyit.py", line 358, in _refactor_files
    if len(refactors := _refactor_file(path)) > 0:
                        ^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/teyit.py", line 346, in _refactor_file
    refactored_source, refactors = refactor_until_deterministic(
                                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/teyit.py", line 305, in refactor_until_deterministic
    source, _refactors = rewrite_source(source, blacklist=blacklist)
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/teyit.py", line 273, in rewrite_source
    tree = ast.parse(source)
           ^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/[email protected]/3.11.4_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/ast.py", line 50, in parse
    return compile(source, filename, mode, flags,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<unknown>", line 6
    pass
        ^
IndentationError: unindent does not match any outer indentation level
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant