# HG changeset patch # User Franz Glasner # Date 1651220367 -7200 # Node ID 83dd2506f8f850554b41571c0169ad823863a570 # Parent 5de499711a92f41c107d0d1fced6e77b9cf4a29e FIX: Make tests work on Python 2 diff -r 5de499711a92 -r 83dd2506f8f8 tests/test_shasum.py --- a/tests/test_shasum.py Fri Apr 29 09:27:05 2022 +0200 +++ b/tests/test_shasum.py Fri Apr 29 10:19:27 2022 +0200 @@ -9,6 +9,10 @@ import os import sys import unittest +try: + from StringIO import StringIO +except ImportError: + StringIO = None from _test_setup import DATADIR @@ -18,6 +22,13 @@ PY2 = sys.version_info[0] <= 2 +def _memfile(): + if StringIO: + return StringIO() + else: + return io.StringIO() + + class ChangedDir(object): """Context manager to temporarily change the directory""" @@ -39,7 +50,7 @@ class SignifyTests(unittest.TestCase): def test_empty(self): - destfile = io.StringIO() + destfile = _memfile() opts = shasum.gen_opts(algorithm="SHA256", dest=destfile, files=[os.path.join(DATADIR, "empty")]) @@ -49,7 +60,7 @@ "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 *")) def test_empty_mmap(self): - destfile = io.StringIO() + destfile = _memfile() opts = shasum.gen_opts(algorithm="SHA256", dest=destfile, files=[os.path.join(DATADIR, "empty")], @@ -60,7 +71,7 @@ "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 *")) def test_empty_no_mmap(self): - destfile = io.StringIO() + destfile = _memfile() opts = shasum.gen_opts(algorithm="SHA256", dest=destfile, files=[os.path.join(DATADIR, "empty")],