1
1
import ast
2
2
import dis
3
3
import os
4
+ import random
4
5
import sys
5
6
import unittest
6
7
import warnings
@@ -666,12 +667,13 @@ def test_compare_basis(self):
666
667
def test_compare_literals (self ):
667
668
constants = (- 20 , 20 , 20.0 , 1 , 1.0 , True , 0 , False , frozenset (), tuple (), "ABCD" , "abcd" , "中文字" , 1e1000 , - 1e1000 )
668
669
for next_index , constant in enumerate (constants [:- 1 ], 1 ):
669
- self .assertEqual (ast .Constant (constant ), ast .Constant (constant ))
670
670
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 ))
672
674
673
675
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 :
675
677
for literal in same_looking_literals :
676
678
for same_looking_literal in same_looking_literals - {literal }:
677
679
self .assertNotEqual (ast .Constant (literal ), ast .Constant (same_looking_literal ))
@@ -684,7 +686,7 @@ def test_compare_operators(self):
684
686
self .assertNotEqual (ast .Add (), ast .Constant ())
685
687
686
688
def test_compare_stdlib (self ):
687
- if test . support .is_resource_enabled ("cpu" ):
689
+ if support .is_resource_enabled ("cpu" ):
688
690
files = STDLIB_FILES
689
691
else :
690
692
files = random .sample (STDLIB_FILES , 10 )
0 commit comments