FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Update test_string.py from Cpython v3.11.2 by jiwahn · Pull Request #4751 · RustPython/RustPython · GitHub

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (1) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
55 changes: 55 additions & 0 deletions Lib/test/test_string.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,61 @@ class PieDelims(Template):
self.assertEqual(s.substitute(dict(who='tim', what='ham')),
'tim likes to eat a bag of ham worth $100')

# TODO: RUSTPYTHON
@unittest.expectedFailure
Comment on lines +478 to +479

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

@youknowone This should have been broken out into a separate commit.

def test_is_valid(self):
eq = self.assertEqual
s = Template('$who likes to eat a bag of ${what} worth $$100')
self.assertTrue(s.is_valid())

s = Template('$who likes to eat a bag of ${what} worth $100')
self.assertFalse(s.is_valid())

# if the pattern has an unrecognized capture group,
# it should raise ValueError like substitute and safe_substitute do
class BadPattern(Template):
pattern = r"""
(?P<badname>.*) |
(?P<escaped>@{2}) |
@(?P<named>[_a-z][._a-z0-9]*) |
@{(?P<braced>[_a-z][._a-z0-9]*)} |
(?P<invalid>@) |
"""
s = BadPattern('@bag.foo.who likes to eat a bag of @bag.what')
self.assertRaises(ValueError, s.is_valid)

# TODO: RUSTPYTHON
@unittest.expectedFailure
Comment on lines +501 to +502

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

@youknowone This should have been broken out into a separate commit.

def test_get_identifiers(self):
eq = self.assertEqual
raises = self.assertRaises
s = Template('$who likes to eat a bag of ${what} worth $$100')
ids = s.get_identifiers()
eq(ids, ['who', 'what'])

# repeated identifiers only included once
s = Template('$who likes to eat a bag of ${what} worth $$100; ${who} likes to eat a bag of $what worth $$100')
ids = s.get_identifiers()
eq(ids, ['who', 'what'])

# invalid identifiers are ignored
s = Template('$who likes to eat a bag of ${what} worth $100')
ids = s.get_identifiers()
eq(ids, ['who', 'what'])

# if the pattern has an unrecognized capture group,
# it should raise ValueError like substitute and safe_substitute do
class BadPattern(Template):
pattern = r"""
(?P<badname>.*) |
(?P<escaped>@{2}) |
@(?P<named>[_a-z][._a-z0-9]*) |
@{(?P<braced>[_a-z][._a-z0-9]*)} |
(?P<invalid>@) |
"""
s = BadPattern('@bag.foo.who likes to eat a bag of @bag.what')
self.assertRaises(ValueError, s.get_identifiers)


if __name__ == '__main__':
unittest.main()

Back | FazBrowse Home | New Git URL