From f886c03e47092d1fad1998df0ddfcffa9e8c3d48 Mon Sep 17 00:00:00 2001 From: Serge Guelton Date: Thu, 3 Jan 2019 14:26:56 +0000 Subject: Portable Python script across Python version StringIO is obsoleted in Python3, replaced by io.BytesIO or io.StringIO depending on the use. Differential Revision: https://reviews.llvm.org/D55196 llvm-svn: 350318 --- clang/bindings/python/tests/cindex/test_translation_unit.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'clang/bindings/python') diff --git a/clang/bindings/python/tests/cindex/test_translation_unit.py b/clang/bindings/python/tests/cindex/test_translation_unit.py index b3075eb85de..f3e770a9361 100644 --- a/clang/bindings/python/tests/cindex/test_translation_unit.py +++ b/clang/bindings/python/tests/cindex/test_translation_unit.py @@ -6,6 +6,7 @@ if 'CLANG_LIBRARY_PATH' in os.environ: from contextlib import contextmanager import gc import os +import sys import tempfile import unittest @@ -93,10 +94,10 @@ int SOME_DEFINE; self.assertEqual(spellings[-1], 'y') def test_unsaved_files_2(self): - try: - from StringIO import StringIO - except: + if sys.version_info.major >= 3: from io import StringIO + else: + from io import BytesIO as StringIO tu = TranslationUnit.from_source('fake.c', unsaved_files = [ ('fake.c', StringIO('int x;'))]) spellings = [c.spelling for c in tu.cursor.get_children()] -- cgit v1.2.3