diff --git a/rdkit/CMakeLists.txt b/rdkit/CMakeLists.txt index fc428fc00..fb6189135 100644 --- a/rdkit/CMakeLists.txt +++ b/rdkit/CMakeLists.txt @@ -24,4 +24,6 @@ add_pytest(pythonTestDirVLib ${CMAKE_CURRENT_SOURCE_DIR}/VLib/test_list.py --testDir ${CMAKE_CURRENT_SOURCE_DIR}/VLib ) add_pytest(pythonTestDirChem ${CMAKE_CURRENT_SOURCE_DIR}/Chem/test_list.py --testDir ${CMAKE_CURRENT_SOURCE_DIR}/Chem ) +add_pytest(pythonTestSping + ${CMAKE_CURRENT_SOURCE_DIR}/Chem/test_list.py --testDir ${CMAKE_CURRENT_SOURCE_DIR}/sping ) diff --git a/rdkit/sping/PDF/pdfdoc.py b/rdkit/sping/PDF/pdfdoc.py index c0c870c86..4cfc305f2 100755 --- a/rdkit/sping/PDF/pdfdoc.py +++ b/rdkit/sping/PDF/pdfdoc.py @@ -427,7 +427,7 @@ class PDFPage(PDFObject): def setStream(self, data): if isinstance(data, (list, tuple)): - data = LINEEND.join(data, LINEEND) + data = LINEEND.join(data) self.stream.setStream(data) diff --git a/rdkit/sping/PS/pidPS.py b/rdkit/sping/PS/pidPS.py index 979ff341b..1de6b8935 100755 --- a/rdkit/sping/PS/pidPS.py +++ b/rdkit/sping/PS/pidPS.py @@ -456,8 +456,8 @@ translate # save() will now become part of the spec. file = file or self.filename - fileobj = getFileObject(file) - fileobj.write(self.code.join(linesep)) + fileobj = getFileObject(file, 'w') + fileobj.write(linesep.join(self.code)) # here's a hack. we might want to be able to add more after saving so # preserve the current code ??? preserveCode = self.code @@ -475,7 +475,7 @@ translate self.psEndDocument() # depends on _inDocumentFlag :( - fileobj.write(finalizationCode.join(linesep)) + fileobj.write(linesep.join(finalizationCode)) # fileobj.close() ### avoid this for now ## clean up my mess: This is not a good way to do things FIXME!!! ??? self.code = preserveCode diff --git a/rdkit/sping/PS/psmetrics.py b/rdkit/sping/PS/psmetrics.py index 8caebcda4..d6c94e2e3 100755 --- a/rdkit/sping/PS/psmetrics.py +++ b/rdkit/sping/PS/psmetrics.py @@ -226,5 +226,10 @@ def stringwidth(text, font, encoding): raise KeyError("Improper encoding {0} or font name {1}".format(encoding, font)) w = 0 for char in text: - w = w + widths[ord(char)] + chr_idx = ord(char) + if chr_idx < len(widths): + chr_width = widths[chr_idx] + else: + chr_width = max(widths) + w = w + chr_width return w diff --git a/rdkit/sping/colors.py b/rdkit/sping/colors.py index a1ce2be73..ec186006b 100755 --- a/rdkit/sping/colors.py +++ b/rdkit/sping/colors.py @@ -25,6 +25,9 @@ class Color: def __rmul__(self, x): return Color(self.red * x, self.green * x, self.blue * x) + def __truediv__(self, x): + return Color(self.red / x, self.green / x, self.blue / x) + def __div__(self, x): return Color(self.red / x, self.green / x, self.blue / x) diff --git a/rdkit/sping/test_list.py b/rdkit/sping/test_list.py new file mode 100755 index 000000000..f8e2f4b15 --- /dev/null +++ b/rdkit/sping/test_list.py @@ -0,0 +1,12 @@ +tests = [ + ("python", "test_list.py", {'dir': 'tests'}), +] + + +longTests = [] + +if __name__ == '__main__': + import sys + from rdkit import TestRunner + failed, tests = TestRunner.RunScript('test_list.py', 0, 1) + sys.exit(len(failed)) diff --git a/rdkit/sping/tests/pstests.py b/rdkit/sping/tests/pstests.py index 9af550b4b..dfce57c1f 100755 --- a/rdkit/sping/tests/pstests.py +++ b/rdkit/sping/tests/pstests.py @@ -1,8 +1,8 @@ -# $Id$ +# -*- coding: utf-8 -*- + from __future__ import print_function import pidtest - def testLatin1Chars(can): curx, cury = 10, 20 can.drawString("hola M�laga amigos ni�os", curx, cury) diff --git a/rdkit/sping/tests/test_list.py b/rdkit/sping/tests/test_list.py new file mode 100644 index 000000000..f8c4f180a --- /dev/null +++ b/rdkit/sping/tests/test_list.py @@ -0,0 +1,12 @@ +tests = [ + ("python", "testallps.py", {}), +] + + +longTests = [] + +if __name__ == '__main__': + import sys + from rdkit import TestRunner + failed, tests = TestRunner.RunScript('test_list.py', 0, 1) + sys.exit(len(failed)) diff --git a/rdkit/sping/tests/testallps.py b/rdkit/sping/tests/testallps.py index 7ef95724f..7da924391 100755 --- a/rdkit/sping/tests/testallps.py +++ b/rdkit/sping/tests/testallps.py @@ -1,31 +1,42 @@ #!/usr/bin/env python +import unittest import pidtest -import sping.PS.pidPS +from rdkit.sping.PS import pidPS -canvas = sping.PS.pidPS.PSCanvas(name="testallps.ps", size=(400, 500)) +class TestCase(unittest.TestCase): + def test_all(self): + canvas = pidPS.PSCanvas(name="testallps.ps", size=(400, 500)) -pidtest.drawStrings(canvas) + pidtest.drawStrings(canvas) -canvas.flush() -canvas.clear() # resets the canvas + canvas.flush() + canvas.clear() # resets the canvas -pidtest.drawRotstring(canvas) -canvas.flush() -canvas.clear() + pidtest.drawRotstring(canvas) + canvas.flush() + canvas.clear() -x1 = 100 -y1 = 100 -radius = 20 -canvas.drawString("Test", 100, 250) -canvas.drawEllipse(x1, y1 - radius, x1 + 2 * radius, y1 + radius, edgeWidth=1) -canvas.flush() -canvas.clear() + x1 = 100 + y1 = 100 + radius = 20 + canvas.drawString("Test", 100, 250) + canvas.drawEllipse(x1, y1 - radius, x1 + 2 * radius, y1 + radius, edgeWidth=1) + canvas.flush() + canvas.clear() -pidtest.drawBasics(canvas) -canvas.flush() -canvas.clear() + pidtest.drawBasics(canvas) + canvas.flush() + canvas.clear() -import pstests -pstests.testLatin1Chars(canvas) + import pstests + pstests.testLatin1Chars(canvas) -canvas.save() + canvas.save() + + def test_pdf_canvas_works(self): + from rdkit.Chem.Draw.spingCanvas import Canvas + canvas = Canvas((200, 400), 'test.pdf', imageType="pdf") + canvas.canvas.showPage() + +if __name__ == '__main__': # pragma: nocover + unittest.main() diff --git a/rdkit/test_list.py b/rdkit/test_list.py index 8aac37926..df1718de3 100755 --- a/rdkit/test_list.py +++ b/rdkit/test_list.py @@ -6,6 +6,7 @@ tests = [ ("python", "test_list.py", {'dir': 'SimDivFilters'}), ("python", "test_list.py", {'dir': 'VLib'}), ("python", "test_list.py", {'dir': 'utils'}), + ("python", "test_list.py", {'dir': 'sping'}), ] longTests = []