Closed hugovk closed 3 years ago
Wow, thanks for the patch and the detailed write-up! Regarding the stuff that requires extra argument-juggling, if you'd like you can try to play with an AST-based transformation by implementing visit_assertDictContainsSubset
to the _AssertRewriter
.
Thanks, I've had a go in another branch:
https://github.com/hugovk/teyit/commit/b3dc017f2e40546f748829a3f652364b2e0533b5 has args = [right, left, *args]
but we'd need that left
to contain something that will end up as {**y, **x}
E AssertionError: 'self.assertEqual(y, x, msg=msg)' != 'self.assertEqual(y, {**y, **x}, msg=msg)'
E - self.assertEqual(y, x, msg=msg)
E + self.assertEqual(y, {**y, **x}, msg=msg)
E ? ++++++++ +
https://github.com/hugovk/teyit/runs/3995628461?check_suite_focus=true
How can we make put {**y, **x}
in the second arg?
You can create a new AST node ast.Dict(keys=[None, None], values=[right, left])
;
def visit_assertDictContainsSubset(self, node):
left, right, *args = node.args
func = "assertEqual"
args = [ast.Dict(keys=[None, None], values=[right, left]), *args]
return Rewrite(node, func, args)
and this should automatically work. Since it is on another branch, I'm merging this as is. Feel free to create a PR for that as well, if you have time to do so.
Thanks a lot for this PR!
Thanks! Please see PR https://github.com/isidentical/teyit/pull/5.
Deprecated since Python 3.2:
assertRegexpMatches
assertNotRegexpMatches
Removed in Python 3.11:
These are also removed in 3.11 but not part of this PR:
Deprecated since 3.1:
failUnlessRaises
And since 3.2:
assertRaisesRegexp
assertDictContainsSubset
I wasn't sure if they can be included?
*Raises*
are usually called with a context manager. AndassertDictContainsSubset
needs some argument juggling: https://stackoverflow.com/a/59777678/724176.