Fix fileio for test compatibility with python2.7

pull/176/head
FlyingSamson 2022-05-22 16:17:43 +02:00
parent 68e0d1f30d
commit 02a223c220
2 changed files with 14 additions and 7 deletions

View File

@ -2,6 +2,7 @@ from __future__ import division, absolute_import, print_function
import unittest import unittest
from svgpathtools import * from svgpathtools import *
from io import StringIO from io import StringIO
from io import open # overrides build-in open for compatibility with python2
from os.path import join, dirname from os.path import join, dirname
class TestDocument(unittest.TestCase): class TestDocument(unittest.TestCase):
@ -20,7 +21,8 @@ class TestDocument(unittest.TestCase):
def test_from_stringio(self): def test_from_stringio(self):
""" Test reading svg object contained in a StringIO object """ """ 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 # read entire file into string
file_content = file.read() file_content = file.read()
# prepare stringio object # prepare stringio object
@ -34,9 +36,10 @@ class TestDocument(unittest.TestCase):
self.assertEqual(len(doc.paths()), 2) self.assertEqual(len(doc.paths()), 2)
def test_from_string_without_svg_attrs(self): def test_from_string(self):
""" Test reading svg object contained in a string without svg attributes""" """ Test reading svg object contained in a string"""
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 # read entire file into string
file_content = file.read() file_content = file.read()

View File

@ -2,6 +2,7 @@ from __future__ import division, absolute_import, print_function
import unittest import unittest
from svgpathtools import * from svgpathtools import *
from io import StringIO from io import StringIO
from io import open # overrides build-in open for compatibility with python2
from os.path import join, dirname from os.path import join, dirname
from svgpathtools.svg_to_paths import rect2pathd from svgpathtools.svg_to_paths import rect2pathd
@ -75,7 +76,8 @@ class TestSVG2Paths(unittest.TestCase):
def test_from_stringio(self): def test_from_stringio(self):
""" Test reading svg object contained in a StringIO object """ """ 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 # read entire file into string
file_content = file.read() file_content = file.read()
# prepare stringio object # prepare stringio object
@ -91,7 +93,8 @@ class TestSVG2Paths(unittest.TestCase):
def test_from_string_without_svg_attrs(self): def test_from_string_without_svg_attrs(self):
""" Test reading svg object contained in a string without svg attributes""" """ 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 # read entire file into string
file_content = file.read() file_content = file.read()
@ -101,7 +104,8 @@ class TestSVG2Paths(unittest.TestCase):
def test_from_string_with_svg_attrs(self): def test_from_string_with_svg_attrs(self):
""" Test reading svg object contained in a string with svg attributes""" """ 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 # read entire file into string
file_content = file.read() file_content = file.read()