Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
improve tests
  • Loading branch information
isidentical committed Mar 27, 2020
commit d99ff0a54950f5d15cbaf297a11cef9c010b5e0f
10 changes: 6 additions & 4 deletions Lib/test/test_ast.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import ast
import dis
import os
import random
import sys
import unittest
import warnings
Expand Down Expand Up @@ -666,12 +667,13 @@ def test_compare_basis(self):
def test_compare_literals(self):
constants = (-20, 20, 20.0, 1, 1.0, True, 0, False, frozenset(), tuple(), "ABCD", "abcd", "中文字", 1e1000, -1e1000)
for next_index, constant in enumerate(constants[:-1], 1):
self.assertEqual(ast.Constant(constant), ast.Constant(constant))
next_constant = constants[next_index]
self.assertNotEqual(ast.Constant(constant), ast.Constant(next_constant))
with self.subTest(literal=constant, next_literal=next_constant):
self.assertEqual(ast.Constant(constant), ast.Constant(constant))
self.assertNotEqual(ast.Constant(constant), ast.Constant(next_constant))

same_looking_literal_cases = [{1, 1.0, True, 1+0j}, {0, 0.0, False, 0+0j}]
for same_looking_literals for same_looking_literal_cases:
for same_looking_literals in same_looking_literal_cases:
for literal in same_looking_literals:
for same_looking_literal in same_looking_literals - {literal}:
self.assertNotEqual(ast.Constant(literal), ast.Constant(same_looking_literal))
Expand All @@ -684,7 +686,7 @@ def test_compare_operators(self):
self.assertNotEqual(ast.Add(), ast.Constant())

def test_compare_stdlib(self):
if test.support.is_resource_enabled("cpu"):
if support.is_resource_enabled("cpu"):
files = STDLIB_FILES
else:
files = random.sample(STDLIB_FILES, 10)
Expand Down
9 changes: 7 additions & 2 deletions Python/Python-ast.c

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.