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

gh-94808: Coverage: Test uppercase string literal prefixes #95925

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Lib/test/test_string_literals.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,13 @@ def test_eval_str_u(self):
self.assertRaises(SyntaxError, eval, """ bu'' """)
self.assertRaises(SyntaxError, eval, """ ub'' """)

def test_uppercase_prefixes(self):
self.assertEqual(eval(""" B'x' """), b'x')
self.assertEqual(eval(r""" R'\x01' """), '\\x01')
self.assertEqual(eval(r""" BR'\x01' """), b'\\' + b'x01')
self.assertEqual(eval(""" F'{1+1}' """), '2')
self.assertEqual(eval(""" U'\U0001d120' """), '\U0001d120')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Presumably the lowercase versions are covered by other tests (right?)

Would it be simpler here to just assert in each case that the lowercase and upper case prefixes generate the same thing? For instance, self.assertEqual(eval(""" F'{1+1}' """), eval(""" f'{1+1}' """)).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good idea. Updated.


def check_encoding(self, encoding, extra=""):
modname = "xx_" + encoding.replace("-", "_")
fn = os.path.join(self.tmpdir, modname + ".py")
Expand Down