|
| 1 | +import unittest |
| 2 | + |
| 3 | +class TagStringTests(unittest.TestCase): |
| 4 | + |
| 5 | + def test_basic(self): |
| 6 | + def tag(*args): |
| 7 | + return "Spam" |
| 8 | + self.assertEqual(tag"ham", "Spam") |
| 9 | + self.assertEqual(tag"...{ham}...{eggs}...", "Spam") |
| 10 | + |
| 11 | + def test_tag_call(self): |
| 12 | + def tag(*args): |
| 13 | + return args |
| 14 | + self.assertEqual(tag"ham", ("ham",)) |
| 15 | + res = tag"... {ham and eggs} ..." |
| 16 | + self.assertEqual(len(res), 3) |
| 17 | + self.assertEqual(res[0], "... ") |
| 18 | + func, string, conv, spec = res[1] |
| 19 | + ham = 42 |
| 20 | + eggs = "delicious" |
| 21 | + self.assertEqual(func(), "delicious") |
| 22 | + self.assertEqual(string, "ham and eggs") |
| 23 | + self.assertEqual(conv, None) |
| 24 | + self.assertEqual(spec, None) |
| 25 | + self.assertEqual(res[2], " ...") |
| 26 | + |
| 27 | + def test_tag_call_with_conversion(self): |
| 28 | + def tag(*args): |
| 29 | + return args |
| 30 | + res = tag"{ham!r:spec}" |
| 31 | + func, string, conv, spec = res[0] |
| 32 | + ham = 42 |
| 33 | + self.assertEqual(func(), 42) |
| 34 | + self.assertEqual(string, "ham") |
| 35 | + self.assertEqual(conv, "r") |
| 36 | + self.assertEqual(spec, "spec") |
| 37 | + |
| 38 | + |
| 39 | +if __name__ == "__main__": |
| 40 | + unittest.main() |
0 commit comments