From 4bd090887e2cb632ae13194c00ff79bca19b7a5c Mon Sep 17 00:00:00 2001 From: Jeong YunWon Date: Mon, 13 Feb 2023 21:10:35 +0900 Subject: [PATCH] Remove completed TODO --- extra_tests/snippets/builtin_str_unicode.py | 2 +- extra_tests/snippets/stdlib_string.py | 10 +++--- extra_tests/snippets/syntax_class.py | 24 +++++++------- extra_tests/snippets/syntax_comprehension.py | 3 +- extra_tests/snippets/syntax_fstring.py | 34 +++++++++----------- extra_tests/snippets/syntax_generator.py | 6 ++-- 6 files changed, 35 insertions(+), 44 deletions(-) diff --git a/extra_tests/snippets/builtin_str_unicode.py b/extra_tests/snippets/builtin_str_unicode.py index 82294697a..f270ee114 100644 --- a/extra_tests/snippets/builtin_str_unicode.py +++ b/extra_tests/snippets/builtin_str_unicode.py @@ -22,7 +22,7 @@ assert unicodedata.normalize('NFC', 'bla') == 'bla' # testing unicodedata.ucd_3_2_0 for idna assert "abcСĤ".encode("idna") == b'xn--abc-7sa390b' -# TODO: fix: assert "abc䄣IJ".encode("idna") == b'xn--abcij-zb5f' +assert "abc䄣IJ".encode("idna") == b'xn--abcij-zb5f' # from CPython tests assert "python.org".encode("idna") == b"python.org" diff --git a/extra_tests/snippets/stdlib_string.py b/extra_tests/snippets/stdlib_string.py index 4435f6633..9151d2f59 100644 --- a/extra_tests/snippets/stdlib_string.py +++ b/extra_tests/snippets/stdlib_string.py @@ -8,17 +8,15 @@ assert string.digits == '0123456789' assert string.hexdigits == '0123456789abcdefABCDEF' assert string.octdigits == '01234567' assert string.punctuation == '!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~' -# FIXME -#assert string.whitespace == ' \t\n\r\x0b\x0c', string.whitespace -#assert string.printable == '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~ \t\n\r\x0b\x0c' +assert string.whitespace == ' \t\n\r\x0b\x0c', string.whitespace +assert string.printable == '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~ \t\n\r\x0b\x0c' assert string.capwords('bla bla', ' ') == 'Bla Bla' from string import Template s = Template('$who likes $what') -# TODO: -# r = s.substitute(who='tim', what='kung pow') -# print(r) +r = s.substitute(who='tim', what='kung pow') +assert r == 'tim likes kung pow' from string import Formatter diff --git a/extra_tests/snippets/syntax_class.py b/extra_tests/snippets/syntax_class.py index d0ae4ef26..e0dc60723 100644 --- a/extra_tests/snippets/syntax_class.py +++ b/extra_tests/snippets/syntax_class.py @@ -193,22 +193,20 @@ class B: assert B.__doc__ == "Docstring" -# TODO: uncomment once free vars/cells are working # The symboltable sees that b() is referring to a in the nested scope, # so it marks it as non local. When it's executed, it walks up the scopes # and still finds the a from the class scope. -# a = 1 -# def nested_scope(): -# a = 2 -# class A: -# a = 3 -# def b(): -# assert a == 2 -# b() -# assert a == 3 -# A.b() -# nested_scope() - +a = 1 +def nested_scope(): + a = 2 + class A: + a = 3 + def b(): + assert a == 2 + b() + assert a == 3 + A.b() +nested_scope() # Multiple inheritance and mro tests. diff --git a/extra_tests/snippets/syntax_comprehension.py b/extra_tests/snippets/syntax_comprehension.py index f8b4cec5e..41bd1ec85 100644 --- a/extra_tests/snippets/syntax_comprehension.py +++ b/extra_tests/snippets/syntax_comprehension.py @@ -12,8 +12,7 @@ assert z == [ (3, 2), (3, 5), (3, 10)] v = {b * 2 for b in x} -# TODO: how to check set equality? -# assert v == {2, 6, 4} +assert v == {2, 6, 4} u = {str(b): b-2 for b in x} assert u['3'] == 1 diff --git a/extra_tests/snippets/syntax_fstring.py b/extra_tests/snippets/syntax_fstring.py index 4ea79795a..cf8ec8994 100644 --- a/extra_tests/snippets/syntax_fstring.py +++ b/extra_tests/snippets/syntax_fstring.py @@ -60,14 +60,13 @@ assert f'{10:{"#"}1{0}{"x"}}' == ' 0xa' assert f'{-10:-{"#"}1{0}x}' == ' -0xa' assert f'{-10:{"-"}#{1}0{"x"}}' == ' -0xa' -# TODO: -# spec = "bla" -# assert_raises(ValueError, lambda: f"{16:{spec}}") +spec = "bla" +assert_raises(ValueError, lambda: f"{16:{spec}}") # Normally `!` cannot appear outside of delimiters in the expression but # cpython makes an exception for `!=`, so we should too. -# assert f'{1 != 2}' == 'True' +assert f'{1 != 2}' == 'True' # conversion flags @@ -103,19 +102,17 @@ assert f'>{v!s}' == '>\u262e' assert f'>{v!a}' == r">'\u262e'" - # Test format specifier after conversion flag -#assert f'{"42"!s:<5}' == '42 ', '#' + f'{"42"!s:5}' +'#' # TODO: default alignment in cpython is left +assert f'{"42"!s:<5}' == '42 ', '#' + f'{"42"!s:5}' +'#' assert f'{"42"!s:<5}' == '42 ', '#' + f'{"42"!s:<5}' +'#' assert f'{"42"!s:>5}' == ' 42', '#' + f'{"42"!s:>5}' +'#' -#assert f'{"42"=!s:5}' == '"42"=42 ', '#'+ f'{"42"=!s:5}' +'#' # TODO default alingment in cpython is left +assert f'{"42"=!s:5}' == '"42"=42 ', '#'+ f'{"42"=!s:5}' +'#' assert f'{"42"=!s:<5}' == '"42"=42 ', '#'+ f'{"42"=!s:<5}' +'#' assert f'{"42"=!s:>5}' == '"42"= 42', '#'+ f'{"42"=!s:>5}' +'#' - ### Tests for fstring selfdocumenting form CPython class C: @@ -126,16 +123,16 @@ self=C() x = 'A string' self.assertEqual(f'{10=}', '10=10') -# self.assertEqual(f'{x=}', 'x=' + x )#repr(x)) # TODO: add ' when printing strings -# self.assertEqual(f'{x =}', 'x =' + x )# + repr(x)) # TODO: implement ' handling +self.assertEqual(f'{x=}', 'x=' + repr(x)) +self.assertEqual(f'{x =}', 'x =' + repr(x)) self.assertEqual(f'{x=!s}', 'x=' + str(x)) -# # self.assertEqual(f'{x=!r}', 'x=' + x) #repr(x)) # !r not supported -# self.assertEqual(f'{x=!a}', 'x=' + ascii(x)) +self.assertEqual(f'{x=!r}', 'x=' + repr(x)) +self.assertEqual(f'{x=!a}', 'x=' + ascii(x)) x = 2.71828 self.assertEqual(f'{x=:.2f}', 'x=' + format(x, '.2f')) self.assertEqual(f'{x=:}', 'x=' + format(x, '')) -self.assertEqual(f'{x=!r:^20}', 'x=' + format(repr(x), '^20')) # TODO formatspecifier after conversion flsg is currently not supported (also for classical fstrings) +self.assertEqual(f'{x=!r:^20}', 'x=' + format(repr(x), '^20')) self.assertEqual(f'{x=!s:^20}', 'x=' + format(str(x), '^20')) self.assertEqual(f'{x=!a:^20}', 'x=' + format(ascii(x), '^20')) @@ -170,14 +167,13 @@ self.assertEqual(f'{0<=1}', 'True') self.assertEqual(f'{0>=1}', 'False') # Make sure leading and following text works. -# x = 'foo' -#self.assertEqual(f'X{x=}Y', 'Xx='+repr(x)+'Y') # TODO ' -# self.assertEqual(f'X{x=}Y', 'Xx='+x+'Y') # just for the moment +x = 'foo' +self.assertEqual(f'X{x=}Y', 'Xx='+repr(x)+'Y') # Make sure whitespace around the = works. -# self.assertEqual(f'X{x =}Y', 'Xx ='+repr(x)+'Y') # TODO ' -# self.assertEqual(f'X{x= }Y', 'Xx= '+repr(x)+'Y') # TODO ' -# self.assertEqual(f'X{x = }Y', 'Xx = '+repr(x)+'Y') # TODO ' +self.assertEqual(f'X{x =}Y', 'Xx ='+repr(x)+'Y') +self.assertEqual(f'X{x= }Y', 'Xx= '+repr(x)+'Y') +self.assertEqual(f'X{x = }Y', 'Xx = '+repr(x)+'Y') # self.assertEqual(f'X{x =}Y', 'Xx ='+x+'Y') # self.assertEqual(f'X{x= }Y', 'Xx= '+x+'Y') diff --git a/extra_tests/snippets/syntax_generator.py b/extra_tests/snippets/syntax_generator.py index 09791f1b0..9f087dde7 100644 --- a/extra_tests/snippets/syntax_generator.py +++ b/extra_tests/snippets/syntax_generator.py @@ -102,9 +102,9 @@ def binary(n): with assert_raises(StopIteration): try: next(binary(5)) - except StopIteration as stopiter: - # TODO: StopIteration.value - assert stopiter.args[0] == 31 + except StopIteration as stop_iter: + assert stop_iter.value == 31 + assert stop_iter.args[0] == 31 raise class SpamException(Exception):