|
12 | 12 | import textwrap |
13 | 13 | import unittest |
14 | 14 | from test import support |
15 | | -from test.support import os_helper |
16 | 15 | from test.support.script_helper import assert_python_ok |
17 | 16 |
|
18 | 17 | from . import tomllib |
@@ -128,54 +127,19 @@ def test_types_import(self): |
128 | 127 | """ |
129 | 128 | importlib.import_module(f"{tomllib.__name__}._types") |
130 | 129 |
|
131 | | - def test_try_simple_decimal(self): |
132 | | - try_simple_decimal = tomllib._parser.try_simple_decimal |
133 | | - self.assertEqual(try_simple_decimal("123", 0), (3, 123)) |
134 | | - self.assertEqual(try_simple_decimal("123\n", 0), (3, 123)) |
135 | | - self.assertEqual(try_simple_decimal("123 456", 0), (3, 123)) |
136 | | - self.assertEqual(try_simple_decimal("+123\n", 0), (4, 123)) |
137 | | - self.assertEqual(try_simple_decimal("-123\n", 0), (4, -123)) |
138 | | - self.assertEqual(try_simple_decimal("0\n", 0), (1, 0)) |
139 | | - self.assertEqual(try_simple_decimal("+0\n", 0), (2, 0)) |
140 | | - self.assertEqual(try_simple_decimal("-0\n", 0), (2, 0)) |
141 | | - self.assertEqual(try_simple_decimal("[23]\n", 1), (3, 23)) |
142 | | - self.assertEqual(try_simple_decimal("[23, 24]\n", 1), (3, 23)) |
143 | | - self.assertEqual(try_simple_decimal("{x = 42}\n", 5), (7, 42)) |
144 | | - |
145 | | - self.assertIsNone(try_simple_decimal("+", 0), None) |
146 | | - self.assertIsNone(try_simple_decimal("-", 0), None) |
147 | | - self.assertIsNone(try_simple_decimal("+\n", 0), None) |
148 | | - self.assertIsNone(try_simple_decimal("-\n", 0), None) |
149 | | - self.assertIsNone(try_simple_decimal("+inf\n", 0), None) |
150 | | - self.assertIsNone(try_simple_decimal("-nan\n", 0), None) |
151 | | - self.assertIsNone(try_simple_decimal("0123\n", 0)) |
152 | | - self.assertIsNone(try_simple_decimal("1979-05-27\n", 0)) |
153 | | - self.assertIsNone(try_simple_decimal("12:32:00\n", 0)) |
154 | | - self.assertIsNone(try_simple_decimal("1.0\n", 0)) |
155 | | - self.assertIsNone(try_simple_decimal("1_000\n", 0)) |
156 | | - self.assertIsNone(try_simple_decimal("0x123\n", 0)) |
157 | | - self.assertIsNone(try_simple_decimal("0o123\n", 0)) |
158 | | - self.assertIsNone(try_simple_decimal("0b100\n", 0)) |
159 | | - |
160 | 130 | def test_lazy_import(self): |
161 | | - # Test that try_simple_decimal() can parse the TOML file without |
162 | | - # importing regular expressions (tomllib._re) |
163 | | - filename = os_helper.TESTFN |
164 | | - self.addCleanup(os_helper.unlink, filename) |
165 | | - toml = textwrap.dedent(""" |
166 | | - [metadata] |
167 | | - int = 123 |
168 | | - list = [+1, -2, 3] |
169 | | - table = {x=1, y=2} |
170 | | - """) |
171 | | - with open(filename, "w") as fp: |
172 | | - fp.write(toml) |
173 | | - |
174 | | - code = textwrap.dedent(f""" |
175 | | - import sys, tomllib |
176 | | - with open({filename!a}, "rb") as fp: |
177 | | - tomllib.load(fp) |
| 131 | + # Test the TOML file can be parsed without importing regular |
| 132 | + # expressions (tomllib._re) |
| 133 | + code = textwrap.dedent(""" |
| 134 | + import sys, tomllib, textwrap |
| 135 | + document = textwrap.dedent(''' |
| 136 | + [metadata] |
| 137 | + key = "text" |
| 138 | + array = ["array", "of", "text"] |
| 139 | + booleans = [true, false] |
| 140 | + ''') |
| 141 | + tomllib.loads(document) |
178 | 142 | print("lazy import?", 'tomllib._re' not in sys.modules) |
179 | 143 | """) |
180 | | - proc = assert_python_ok('-c', code) |
181 | | - self.assertIn(b'lazy import? True', proc.out) |
| 144 | + proc = assert_python_ok("-c", code) |
| 145 | + self.assertIn(b"lazy import? True", proc.out) |
0 commit comments