diff options
Diffstat (limited to 'Tests/misc')
-rw-r--r-- | Tests/misc/arrayTools_test.py | 17 | ||||
-rw-r--r-- | Tests/misc/bezierTools_test.py | 22 | ||||
-rw-r--r-- | Tests/misc/classifyTools_test.py | 1 | ||||
-rw-r--r-- | Tests/misc/eexec_test.py | 1 | ||||
-rw-r--r-- | Tests/misc/encodingTools_test.py | 3 | ||||
-rw-r--r-- | Tests/misc/fixedTools_test.py | 1 | ||||
-rw-r--r-- | Tests/misc/loggingTools_test.py | 2 | ||||
-rw-r--r-- | Tests/misc/macRes_test.py | 2 | ||||
-rw-r--r-- | Tests/misc/plistlib_test.py | 4 | ||||
-rw-r--r-- | Tests/misc/py23_test.py | 32 | ||||
-rw-r--r-- | Tests/misc/testTools_test.py | 2 | ||||
-rw-r--r-- | Tests/misc/textTools_test.py | 1 | ||||
-rw-r--r-- | Tests/misc/timeTools_test.py | 3 | ||||
-rw-r--r-- | Tests/misc/transform_test.py | 1 | ||||
-rw-r--r-- | Tests/misc/vector_test.py | 71 | ||||
-rw-r--r-- | Tests/misc/xmlReader_test.py | 5 | ||||
-rw-r--r-- | Tests/misc/xmlWriter_test.py | 3 |
17 files changed, 105 insertions, 66 deletions
diff --git a/Tests/misc/arrayTools_test.py b/Tests/misc/arrayTools_test.py index 73e0ab17..45b186fe 100644 --- a/Tests/misc/arrayTools_test.py +++ b/Tests/misc/arrayTools_test.py @@ -1,7 +1,5 @@ -from fontTools.misc.py23 import * -from fontTools.misc.py23 import round3 from fontTools.misc.arrayTools import ( - Vector, calcBounds, calcIntBounds, updateBounds, pointInRect, pointsInRect, + calcBounds, calcIntBounds, updateBounds, pointInRect, pointsInRect, vectorLength, asInt16, normRect, scaleRect, offsetRect, insetRect, sectRect, unionRect, rectCenter, intRect) import math @@ -20,7 +18,7 @@ def test_calcIntBounds(): assert calcIntBounds( [(0.1, 40.1), (0.1, 100.1), (49.9, 49.9), (78.5, 9.5)], - round=round3 + round=round ) == (0, 10, 78, 100) @@ -88,14 +86,3 @@ def test_rectCenter(): def test_intRect(): assert intRect((0.9, 2.9, 3.1, 4.1)) == (0, 2, 4, 5) - - -def test_Vector(): - v = Vector([100, 200]) - assert v == Vector([100, 200]) - assert v == [100, 200] - assert v + Vector([1, 2]) == [101, 202] - assert v - Vector([1, 2]) == [99, 198] - assert v * 2 == [200, 400] - assert v * 0.5 == [50, 100] - assert v / 2 == [50, 100] diff --git a/Tests/misc/bezierTools_test.py b/Tests/misc/bezierTools_test.py index 9096f278..c5cd1b73 100644 --- a/Tests/misc/bezierTools_test.py +++ b/Tests/misc/bezierTools_test.py @@ -1,6 +1,5 @@ -from fontTools.misc.py23 import * from fontTools.misc.bezierTools import ( - calcQuadraticBounds, calcCubicBounds, splitLine, splitQuadratic, + calcQuadraticBounds, calcCubicBounds, segmentPointAtT, splitLine, splitQuadratic, splitCubic, splitQuadraticAtT, splitCubicAtT, solveCubic) import pytest @@ -130,3 +129,22 @@ def test_solveCubic(): assert solveCubic(1.0, -4.5, 6.75, -3.375) == [1.5, 1.5, 1.5] assert solveCubic(-12.0, 18.0, -9.0, 1.50023651123) == [0.5, 0.5, 0.5] assert solveCubic(9.0, 0.0, 0.0, -7.62939453125e-05) == [-0.0, -0.0, -0.0] + + +_segmentPointAtT_testData = [ + ([(0, 10), (200, 100)], 0.0, (0, 10)), + ([(0, 10), (200, 100)], 0.5, (100, 55)), + ([(0, 10), (200, 100)], 1.0, (200, 100)), + ([(0, 10), (100, 100), (200, 50)], 0.0, (0, 10)), + ([(0, 10), (100, 100), (200, 50)], 0.5, (100, 65.0)), + ([(0, 10), (100, 100), (200, 50)], 1.0, (200, 50.0)), + ([(0, 10), (100, 100), (200, 100), (300, 0)], 0.0, (0, 10)), + ([(0, 10), (100, 100), (200, 100), (300, 0)], 0.5, (150, 76.25)), + ([(0, 10), (100, 100), (200, 100), (300, 0)], 1.0, (300, 0)), +] + + +@pytest.mark.parametrize("segment, t, expectedPoint", _segmentPointAtT_testData) +def test_segmentPointAtT(segment, t, expectedPoint): + point = segmentPointAtT(segment, t) + assert expectedPoint == point diff --git a/Tests/misc/classifyTools_test.py b/Tests/misc/classifyTools_test.py index 071baec6..72a97523 100644 --- a/Tests/misc/classifyTools_test.py +++ b/Tests/misc/classifyTools_test.py @@ -1,4 +1,3 @@ -from fontTools.misc.py23 import * from fontTools.misc.classifyTools import classify diff --git a/Tests/misc/eexec_test.py b/Tests/misc/eexec_test.py index 4c508dd7..f72760a7 100644 --- a/Tests/misc/eexec_test.py +++ b/Tests/misc/eexec_test.py @@ -1,4 +1,3 @@ -from fontTools.misc.py23 import * from fontTools.misc.eexec import decrypt, encrypt diff --git a/Tests/misc/encodingTools_test.py b/Tests/misc/encodingTools_test.py index 49961d84..1a131f61 100644 --- a/Tests/misc/encodingTools_test.py +++ b/Tests/misc/encodingTools_test.py @@ -1,4 +1,3 @@ -from fontTools.misc.py23 import * import unittest from fontTools.misc.encodingTools import getEncoding @@ -19,7 +18,7 @@ class EncodingTest(unittest.TestCase): def test_extended_mac_encodings(self): encoding = getEncoding(1, 1, 0) # Mac Japanese decoded = b'\xfe'.decode(encoding) - self.assertEqual(decoded, unichr(0x2122)) + self.assertEqual(decoded, chr(0x2122)) def test_extended_unknown(self): self.assertEqual(getEncoding(10, 11, 12), None) diff --git a/Tests/misc/fixedTools_test.py b/Tests/misc/fixedTools_test.py index fe836ea6..dea61b90 100644 --- a/Tests/misc/fixedTools_test.py +++ b/Tests/misc/fixedTools_test.py @@ -1,4 +1,3 @@ -from fontTools.misc.py23 import * from fontTools.misc.fixedTools import ( fixedToFloat, floatToFixed, diff --git a/Tests/misc/loggingTools_test.py b/Tests/misc/loggingTools_test.py index c726d5ee..fd13044c 100644 --- a/Tests/misc/loggingTools_test.py +++ b/Tests/misc/loggingTools_test.py @@ -1,4 +1,3 @@ -from fontTools.misc.py23 import * from fontTools.misc.loggingTools import ( LevelFormatter, Timer, @@ -6,6 +5,7 @@ from fontTools.misc.loggingTools import ( ChannelsFilter, LogMixin, ) +from io import StringIO import logging import textwrap import time diff --git a/Tests/misc/macRes_test.py b/Tests/misc/macRes_test.py index 2c0fd6a4..a6a8e9d4 100644 --- a/Tests/misc/macRes_test.py +++ b/Tests/misc/macRes_test.py @@ -1,4 +1,4 @@ -from fontTools.misc.py23 import * +from io import BytesIO import sys import os import tempfile diff --git a/Tests/misc/plistlib_test.py b/Tests/misc/plistlib_test.py index 7222bd28..b2ce408d 100644 --- a/Tests/misc/plistlib_test.py +++ b/Tests/misc/plistlib_test.py @@ -5,7 +5,7 @@ import codecs import collections from io import BytesIO from numbers import Integral -from fontTools.misc.py23 import tounicode +from fontTools.misc.py23 import tostr from fontTools.misc import etree from fontTools.misc import plistlib from fontTools.ufoLib.plistlib import ( @@ -421,7 +421,7 @@ def test_fromtree(parametrized_pl): def _strip(txt): return ( - "".join(l.strip() for l in tounicode(txt, "utf-8").splitlines()) + "".join(l.strip() for l in tostr(txt, "utf-8").splitlines()) if txt is not None else "" ) diff --git a/Tests/misc/py23_test.py b/Tests/misc/py23_test.py index 1a21d5a7..61274cc2 100644 --- a/Tests/misc/py23_test.py +++ b/Tests/misc/py23_test.py @@ -1,6 +1,7 @@ -from fontTools.misc.py23 import * +from fontTools.misc.py23 import tobytes from fontTools.misc.textTools import deHexStr import filecmp +from io import StringIO import tempfile from subprocess import check_call import sys @@ -389,35 +390,6 @@ class IsCloseTests(unittest.TestCase): self.assertAllNotClose(fraction_examples, rel_tol=1e-9) -@unittest.skipUnless( - (sys.version_info[0] == 2 and sys.maxunicode < 0x10FFFF), - "requires 'narrow' Python 2.7 build") -class NarrowUnicodeBuildTest(unittest.TestCase): - - def test_unichr(self): - from __builtin__ import unichr as narrow_unichr - - self.assertRaises( - ValueError, - narrow_unichr, 0xFFFF + 1) - - self.assertEqual(unichr(1114111), u'\U0010FFFF') - - self.assertRaises( - ValueError, - unichr, 0x10FFFF + 1) - - def test_byteord(self): - from __builtin__ import ord as narrow_ord - - self.assertRaises( - TypeError, - narrow_ord, u'\U00010000') - - self.assertEqual(byteord(u'\U00010000'), 0xFFFF + 1) - self.assertEqual(byteord(u'\U0010FFFF'), 1114111) - - class TestRedirectStream: redirect_stream = None diff --git a/Tests/misc/testTools_test.py b/Tests/misc/testTools_test.py index 82e73a1b..80d4d2ba 100644 --- a/Tests/misc/testTools_test.py +++ b/Tests/misc/testTools_test.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- -from fontTools.misc.py23 import * import fontTools.misc.testTools as testTools import unittest diff --git a/Tests/misc/textTools_test.py b/Tests/misc/textTools_test.py index 44c7cc33..f83abf91 100644 --- a/Tests/misc/textTools_test.py +++ b/Tests/misc/textTools_test.py @@ -1,4 +1,3 @@ -from fontTools.misc.py23 import * from fontTools.misc.textTools import pad diff --git a/Tests/misc/timeTools_test.py b/Tests/misc/timeTools_test.py index 601f357b..4d75ce4e 100644 --- a/Tests/misc/timeTools_test.py +++ b/Tests/misc/timeTools_test.py @@ -1,4 +1,3 @@ -from fontTools.misc.py23 import * from fontTools.misc.timeTools import asctime, timestampNow, timestampToString, timestampFromString, epoch_diff import os import time @@ -7,7 +6,7 @@ import pytest def test_asctime(): - assert isinstance(asctime(), basestring) + assert isinstance(asctime(), str) assert asctime(time.gmtime(0)) == 'Thu Jan 1 00:00:00 1970' diff --git a/Tests/misc/transform_test.py b/Tests/misc/transform_test.py index d679e28a..4efab81f 100644 --- a/Tests/misc/transform_test.py +++ b/Tests/misc/transform_test.py @@ -1,4 +1,3 @@ -from fontTools.misc.py23 import * from fontTools.misc.transform import Transform, Identity, Offset, Scale import math import pytest diff --git a/Tests/misc/vector_test.py b/Tests/misc/vector_test.py new file mode 100644 index 00000000..236a3bad --- /dev/null +++ b/Tests/misc/vector_test.py @@ -0,0 +1,71 @@ +import math +import pytest +from fontTools.misc.arrayTools import Vector as ArrayVector +from fontTools.misc.vector import Vector + + +def test_Vector(): + v = Vector((100, 200)) + assert repr(v) == "Vector((100, 200))" + assert v == Vector((100, 200)) + assert v == Vector([100, 200]) + assert v == (100, 200) + assert (100, 200) == v + assert v == [100, 200] + assert [100, 200] == v + assert v is Vector(v) + assert v + 10 == (110, 210) + assert 10 + v == (110, 210) + assert v + Vector((1, 2)) == (101, 202) + assert v - Vector((1, 2)) == (99, 198) + assert v * 2 == (200, 400) + assert 2 * v == (200, 400) + assert v * 0.5 == (50, 100) + assert v / 2 == (50, 100) + assert 2 / v == (0.02, 0.01) + v = Vector((3, 4)) + assert abs(v) == 5 # length + assert v.length() == 5 + assert v.normalized() == Vector((0.6, 0.8)) + assert abs(Vector((1, 1, 1))) == math.sqrt(3) + assert bool(Vector((0, 0, 1))) + assert not bool(Vector((0, 0, 0))) + v1 = Vector((2, 3)) + v2 = Vector((3, 4)) + assert v1.dot(v2) == 18 + v = Vector((2, 4)) + assert round(v / 3) == (1, 1) + with pytest.raises( + AttributeError, + match="'Vector' object has no attribute 'newAttr'", + ): + v.newAttr = 12 + + +def test_deprecated(): + with pytest.warns( + DeprecationWarning, + match="fontTools.misc.arrayTools.Vector has been deprecated", + ): + ArrayVector((1, 2)) + with pytest.warns( + DeprecationWarning, + match="the 'keep' argument has been deprecated", + ): + Vector((1, 2), keep=True) + v = Vector((1, 2)) + with pytest.warns( + DeprecationWarning, + match="the 'toInt' method has been deprecated", + ): + v.toInt() + with pytest.warns( + DeprecationWarning, + match="the 'values' attribute has been deprecated", + ): + v.values + with pytest.raises( + AttributeError, + match="the 'values' attribute has been deprecated", + ): + v.values = [12, 23] diff --git a/Tests/misc/xmlReader_test.py b/Tests/misc/xmlReader_test.py index afa18218..f6775cbc 100644 --- a/Tests/misc/xmlReader_test.py +++ b/Tests/misc/xmlReader_test.py @@ -1,6 +1,5 @@ -# -*- coding: utf-8 -*- - -from fontTools.misc.py23 import * +from fontTools.misc.py23 import strjoin +from io import BytesIO import os import unittest from fontTools.ttLib import TTFont diff --git a/Tests/misc/xmlWriter_test.py b/Tests/misc/xmlWriter_test.py index fd0ba89a..fd4f2408 100644 --- a/Tests/misc/xmlWriter_test.py +++ b/Tests/misc/xmlWriter_test.py @@ -1,4 +1,5 @@ -from fontTools.misc.py23 import * +from fontTools.misc.py23 import bytesjoin, tobytes +from io import BytesIO import os import unittest from fontTools.misc.xmlWriter import XMLWriter |