Skip to content

Commit d99ff0a

Browse files
committed
improve tests
1 parent 4d14244 commit d99ff0a

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

Lib/test/test_ast.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import ast
22
import dis
33
import os
4+
import random
45
import sys
56
import unittest
67
import warnings
@@ -666,12 +667,13 @@ def test_compare_basis(self):
666667
def test_compare_literals(self):
667668
constants = (-20, 20, 20.0, 1, 1.0, True, 0, False, frozenset(), tuple(), "ABCD", "abcd", "中文字", 1e1000, -1e1000)
668669
for next_index, constant in enumerate(constants[:-1], 1):
669-
self.assertEqual(ast.Constant(constant), ast.Constant(constant))
670670
next_constant = constants[next_index]
671-
self.assertNotEqual(ast.Constant(constant), ast.Constant(next_constant))
671+
with self.subTest(literal=constant, next_literal=next_constant):
672+
self.assertEqual(ast.Constant(constant), ast.Constant(constant))
673+
self.assertNotEqual(ast.Constant(constant), ast.Constant(next_constant))
672674

673675
same_looking_literal_cases = [{1, 1.0, True, 1+0j}, {0, 0.0, False, 0+0j}]
674-
for same_looking_literals for same_looking_literal_cases:
676+
for same_looking_literals in same_looking_literal_cases:
675677
for literal in same_looking_literals:
676678
for same_looking_literal in same_looking_literals - {literal}:
677679
self.assertNotEqual(ast.Constant(literal), ast.Constant(same_looking_literal))
@@ -684,7 +686,7 @@ def test_compare_operators(self):
684686
self.assertNotEqual(ast.Add(), ast.Constant())
685687

686688
def test_compare_stdlib(self):
687-
if test.support.is_resource_enabled("cpu"):
689+
if support.is_resource_enabled("cpu"):
688690
files = STDLIB_FILES
689691
else:
690692
files = random.sample(STDLIB_FILES, 10)

Python/Python-ast.c

Lines changed: 7 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)