From 02a223c2202284456eccb74ddea6f760e24a24ed Mon Sep 17 00:00:00 2001 From: FlyingSamson Date: Sun, 22 May 2022 16:17:43 +0200 Subject: [PATCH] Fix fileio for test compatibility with python2.7 --- test/test_document.py | 11 +++++++---- test/test_svg2paths.py | 10 +++++++--- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/test/test_document.py b/test/test_document.py index 6b4a795..8837e8b 100644 --- a/test/test_document.py +++ b/test/test_document.py @@ -2,6 +2,7 @@ from __future__ import division, absolute_import, print_function import unittest from svgpathtools import * from io import StringIO +from io import open # overrides build-in open for compatibility with python2 from os.path import join, dirname class TestDocument(unittest.TestCase): @@ -20,7 +21,8 @@ class TestDocument(unittest.TestCase): def test_from_stringio(self): """ Test reading svg object contained in a StringIO object """ - with open(join(dirname(__file__), 'polygons.svg'), 'r') as file: + with open(join(dirname(__file__), 'polygons.svg'), + 'r', encoding='utf-8') as file: # read entire file into string file_content = file.read() # prepare stringio object @@ -34,9 +36,10 @@ class TestDocument(unittest.TestCase): self.assertEqual(len(doc.paths()), 2) - def test_from_string_without_svg_attrs(self): - """ Test reading svg object contained in a string without svg attributes""" - with open(join(dirname(__file__), 'polygons.svg'), 'r') as file: + def test_from_string(self): + """ Test reading svg object contained in a string""" + with open(join(dirname(__file__), 'polygons.svg'), + 'r', encoding='utf-8') as file: # read entire file into string file_content = file.read() diff --git a/test/test_svg2paths.py b/test/test_svg2paths.py index 8944586..1a48bd7 100644 --- a/test/test_svg2paths.py +++ b/test/test_svg2paths.py @@ -2,6 +2,7 @@ from __future__ import division, absolute_import, print_function import unittest from svgpathtools import * from io import StringIO +from io import open # overrides build-in open for compatibility with python2 from os.path import join, dirname from svgpathtools.svg_to_paths import rect2pathd @@ -75,7 +76,8 @@ class TestSVG2Paths(unittest.TestCase): def test_from_stringio(self): """ Test reading svg object contained in a StringIO object """ - with open(join(dirname(__file__), 'polygons.svg'), 'r') as file: + with open(join(dirname(__file__), 'polygons.svg'), + 'r', encoding='utf-8') as file: # read entire file into string file_content = file.read() # prepare stringio object @@ -91,7 +93,8 @@ class TestSVG2Paths(unittest.TestCase): def test_from_string_without_svg_attrs(self): """ Test reading svg object contained in a string without svg attributes""" - with open(join(dirname(__file__), 'polygons.svg'), 'r') as file: + with open(join(dirname(__file__), 'polygons.svg'), + 'r', encoding='utf-8') as file: # read entire file into string file_content = file.read() @@ -101,7 +104,8 @@ class TestSVG2Paths(unittest.TestCase): def test_from_string_with_svg_attrs(self): """ Test reading svg object contained in a string with svg attributes""" - with open(join(dirname(__file__), 'polygons.svg'), 'r') as file: + with open(join(dirname(__file__), 'polygons.svg'), + 'r', encoding='utf-8') as file: # read entire file into string file_content = file.read()