update testing
Move testing from 'unittest' module to py.test. Add some api testing.
This commit is contained in:
parent
3b889c89af
commit
5d14c24552
|
@ -13,11 +13,15 @@ config.log
|
|||
config.status
|
||||
configure
|
||||
configure.scan
|
||||
depcomp
|
||||
doltcompile
|
||||
doltlibtool
|
||||
install-sh
|
||||
libtool
|
||||
Makefile
|
||||
Makefile.in
|
||||
missing
|
||||
py-compile
|
||||
pycairo.pc
|
||||
releases
|
||||
stamp-h
|
||||
|
|
9
INSTALL
9
INSTALL
|
@ -21,3 +21,12 @@ Install method2 - alternative install method
|
|||
1. Untar the .tar.gz file
|
||||
2. cd into the resulting directory
|
||||
3. python setup.py install
|
||||
|
||||
|
||||
Testing
|
||||
-------
|
||||
testing uses py.test from pylib
|
||||
http://codespeak.net/py/dist/
|
||||
|
||||
$ cd test
|
||||
$ py.test
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
SUBDIRS = cairo examples test doc
|
||||
SUBDIRS = src examples test doc
|
||||
|
||||
EXTRA_DIST = \
|
||||
COPYING \
|
||||
|
|
|
@ -20,7 +20,7 @@ AC_SUBST(PYCAIRO_VERSION_MICRO, [pycairo_version_micro])
|
|||
AC_SUBST(VERSION_INFO,
|
||||
[pycairo_version_major,pycairo_version_minor,pycairo_version_micro])
|
||||
|
||||
AC_CONFIG_SRCDIR([cairo/pycairo.h])
|
||||
AC_CONFIG_SRCDIR([src/pycairo.h])
|
||||
AC_CONFIG_HEADERS(config.h)
|
||||
|
||||
AM_INIT_AUTOMAKE([1.9.6 -Wall])
|
||||
|
@ -96,7 +96,7 @@ esac
|
|||
AC_CONFIG_FILES([
|
||||
Makefile
|
||||
pycairo.pc
|
||||
cairo/Makefile
|
||||
src/Makefile
|
||||
doc/Makefile
|
||||
examples/Makefile
|
||||
test/Makefile
|
||||
|
|
|
@ -47,7 +47,7 @@ cairo.HAS
|
|||
HAS_FT_FONT
|
||||
HAS_GLITZ_SURFACE
|
||||
HAS_IMAGE_SURFACE
|
||||
HAS_HAS_PDF_SURFACE
|
||||
HAS_PDF_SURFACE
|
||||
HAS_PNG_FUNCTIONS
|
||||
HAS_PS_SURFACE
|
||||
HAS_SVG_SURFACE
|
||||
|
|
|
@ -19,3 +19,4 @@ cr.line_to (xc, yc)
|
|||
cr.arc (xc, yc, radius, angle2, angle2)
|
||||
cr.line_to (xc, yc)
|
||||
cr.stroke ()
|
||||
#cr.stroke (10)
|
||||
|
|
|
@ -27,8 +27,9 @@ def do_snippet (snippet):
|
|||
try:
|
||||
execfile ('snippets/%s.py' % snippet, globals(), locals())
|
||||
except:
|
||||
exc_type, exc_value = sys.exc_info()[:2]
|
||||
print >> sys.stderr, exc_type, exc_value
|
||||
# exc_type, exc_value = sys.exc_info()[:2]
|
||||
# print >> sys.stderr, exc_type, exc_value
|
||||
raise
|
||||
else:
|
||||
cr.restore()
|
||||
surface.write_to_png ('snippets/%s.png' % snippet)
|
||||
|
|
|
@ -30,3 +30,4 @@ ctx.arc (0.5, 0.5, 0.3, 0, 2 * math.pi)
|
|||
ctx.fill ()
|
||||
|
||||
surface.write_to_png('gradient.png')
|
||||
#surface.write_to_png(10)
|
||||
|
|
|
@ -712,7 +712,7 @@ pdf_surface_new (PyTypeObject *type, PyObject *args, PyObject *kwds)
|
|||
sfc = cairo_pdf_surface_create (PyString_AsString(file),
|
||||
width_in_points, height_in_points);
|
||||
Py_END_ALLOW_THREADS
|
||||
return PycairoSurface_FromSurface (sfc, NULL);
|
||||
return PycairoSurface_FromSurface (sfc, NULL);
|
||||
}
|
||||
/* file or file-like object argument */
|
||||
writer = PyObject_GetAttrString (file, "write");
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
EXTRA_DIST = \
|
||||
examples_test.py
|
||||
isurface_create_for_data1.py \
|
||||
isurface_create_for_data2.py \
|
||||
isurface_create_from_png.py \
|
||||
|
@ -6,6 +7,5 @@ EXTRA_DIST = \
|
|||
pygame-test1.py \
|
||||
pygame-test2.py \
|
||||
surface_create_for_stream.py \
|
||||
surface_write_to_png.py \
|
||||
test.py \
|
||||
test.test
|
||||
surface_write_to_png.py
|
||||
|
||||
|
|
|
@ -1,23 +0,0 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
import cairo
|
||||
|
||||
surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, 100, 100)
|
||||
ctx = cairo.Context(surface)
|
||||
|
||||
print "default clip"
|
||||
print ctx.copy_clip_rectangles(), "\n"
|
||||
|
||||
print "custom path" # 2 rectangles
|
||||
ctx.move_to(0, 0)
|
||||
ctx.line_to(50,0)
|
||||
ctx.line_to(50,30)
|
||||
ctx.line_to(60,30)
|
||||
ctx.line_to(60,60)
|
||||
ctx.line_to(30,60)
|
||||
ctx.line_to(0, 60)
|
||||
ctx.close_path()
|
||||
ctx.clip()
|
||||
print ctx.copy_clip_rectangles(), "\n"
|
||||
|
||||
|
|
@ -9,23 +9,23 @@ import numpy
|
|||
dir_ = "/tmp/"
|
||||
w, h = 128, 128
|
||||
|
||||
surface = cairo.ImageSurface (cairo.FORMAT_ARGB32, w, h)
|
||||
ctx = cairo.Context (surface)
|
||||
surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, w, h)
|
||||
ctx = cairo.Context(surface)
|
||||
|
||||
ctx.set_source_rgb (1, 1, 1) # white
|
||||
ctx.set_operator (cairo.OPERATOR_SOURCE)
|
||||
ctx.set_source_rgb(1, 1, 1) # white
|
||||
ctx.set_operator(cairo.OPERATOR_SOURCE)
|
||||
ctx.paint()
|
||||
|
||||
# Draw out the triangle using absolute coordinates
|
||||
ctx.move_to (w/2, h/3)
|
||||
ctx.line_to (2*w/3, 2*h/3)
|
||||
ctx.rel_line_to (-1*w/3, 0)
|
||||
ctx.move_to(w/2, h/3)
|
||||
ctx.line_to(2*w/3, 2*h/3)
|
||||
ctx.rel_line_to(-1*w/3, 0)
|
||||
ctx.close_path()
|
||||
|
||||
ctx.set_source_rgb (0, 0, 0) # black
|
||||
ctx.set_source_rgb(0, 0, 0) # black
|
||||
ctx.set_line_width(15)
|
||||
ctx.stroke()
|
||||
surface.write_to_png (dir_ + "get_data_test1.png")
|
||||
surface.write_to_png(dir_ + "get_data_test1.png")
|
||||
|
||||
# modify surface using numpy
|
||||
buf = surface.get_data()
|
||||
|
@ -34,10 +34,10 @@ buf = surface.get_data()
|
|||
# - is a Python bug?
|
||||
#buf = buffer (surface1)
|
||||
|
||||
a = numpy.ndarray (shape=(w,h,4), dtype=numpy.uint8, buffer=buf)
|
||||
a = numpy.ndarray(shape=(w,h,4), dtype=numpy.uint8, buffer=buf)
|
||||
|
||||
# draw a vertical line
|
||||
a[:,40,0] = 255 # byte 0 is blue on little-endian systems
|
||||
a[:,40,1] = 0
|
||||
a[:,40,2] = 0
|
||||
surface.write_to_png (dir_ + "get_data_test2.png")
|
||||
surface.write_to_png(dir_ + "get_data_test2.png")
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#!/usr/bin/env python
|
||||
"""demonstrate pycairo and pygame
|
||||
method1: use a pycairo and pygame directly
|
||||
method1: use pycairo and pygame directly
|
||||
"""
|
||||
|
||||
import array
|
||||
|
|
|
@ -14,14 +14,14 @@ import cairo
|
|||
class C(object):
|
||||
"""a file-like object (for testing), it simulates sys.stdout
|
||||
"""
|
||||
def __init__ (self):
|
||||
def __init__(self):
|
||||
self.closed = False
|
||||
|
||||
def write(self, s):
|
||||
"""just echo to stdout, without newlines"""
|
||||
if self.closed:
|
||||
raise ValueError ("I/O operation on closed file")
|
||||
sys.stdout.write (s)
|
||||
raise ValueError("I/O operation on closed file")
|
||||
sys.stdout.write(s)
|
||||
|
||||
def close(self):
|
||||
self.closed = True
|
||||
|
@ -29,27 +29,27 @@ class C(object):
|
|||
|
||||
WIDTH, HEIGHT = 256, 256
|
||||
|
||||
surface = cairo.ImageSurface (cairo.FORMAT_ARGB32, WIDTH, HEIGHT)
|
||||
ctx = cairo.Context (surface)
|
||||
surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, WIDTH, HEIGHT)
|
||||
ctx = cairo.Context(surface)
|
||||
|
||||
ctx.scale (WIDTH/1.0, HEIGHT/1.0)
|
||||
ctx.scale(WIDTH/1.0, HEIGHT/1.0)
|
||||
|
||||
pat = cairo.LinearGradient (0.0, 0.0, 0.0, 1.0)
|
||||
pat.add_color_stop_rgba (1, 0, 0, 0, 1)
|
||||
pat.add_color_stop_rgba (0, 1, 1, 1, 1)
|
||||
pat = cairo.LinearGradient(0.0, 0.0, 0.0, 1.0)
|
||||
pat.add_color_stop_rgba(1, 0, 0, 0, 1)
|
||||
pat.add_color_stop_rgba(0, 1, 1, 1, 1)
|
||||
|
||||
ctx.rectangle (0,0,1,1)
|
||||
ctx.set_source (pat)
|
||||
ctx.fill ()
|
||||
ctx.rectangle(0,0,1,1)
|
||||
ctx.set_source(pat)
|
||||
ctx.fill()
|
||||
|
||||
pat = cairo.RadialGradient (0.45, 0.4, 0.1,
|
||||
pat = cairo.RadialGradient(0.45, 0.4, 0.1,
|
||||
0.4, 0.4, 0.5)
|
||||
pat.add_color_stop_rgba (0, 1, 1, 1, 1)
|
||||
pat.add_color_stop_rgba (1, 0, 0, 0, 1)
|
||||
pat.add_color_stop_rgba(0, 1, 1, 1, 1)
|
||||
pat.add_color_stop_rgba(1, 0, 0, 0, 1)
|
||||
|
||||
ctx.set_source (pat)
|
||||
ctx.arc (0.5, 0.5, 0.3, 0, 2 * math.pi)
|
||||
ctx.fill ()
|
||||
ctx.set_source(pat)
|
||||
ctx.arc(0.5, 0.5, 0.3, 0, 2 * math.pi)
|
||||
ctx.fill()
|
||||
|
||||
# a selection of possible args to surface.write_to_png()
|
||||
#fo = '/tmp/f.png'
|
||||
|
@ -60,7 +60,7 @@ fo = file('/tmp/f.png', 'w')
|
|||
#fo = C()
|
||||
|
||||
fo.close() # this should cause: ValueError: I/O operation on closed file
|
||||
surface.write_to_png (fo)
|
||||
surface.write_to_png(fo)
|
||||
|
||||
# for testing StringIO: get data and write to file
|
||||
#string = fo.getvalue()
|
||||
|
|
18
test/test.py
18
test/test.py
|
@ -1,18 +0,0 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
import os
|
||||
import sys
|
||||
import doctest
|
||||
import unittest
|
||||
|
||||
def _test():
|
||||
# check we are running from the test dir
|
||||
assert os.getcwd().endswith('/test'), "test.py must be run from the 'test' directory"
|
||||
|
||||
runner = unittest.TextTestRunner()
|
||||
suite = doctest.DocFileSuite (__file__.replace ('.py', '.test'))
|
||||
runner.run(suite)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
_test()
|
|
@ -1,23 +0,0 @@
|
|||
# doctest text file
|
||||
|
||||
>>> import os, os.path, sys
|
||||
>>> cwd = os.getcwd()
|
||||
|
||||
# run non-gui example scripts, check they run and produce no output (error messages)
|
||||
# and exit successfully
|
||||
>>> _dir = os.path.join(cwd, '..', 'examples')
|
||||
>>> os.chdir (_dir)
|
||||
>>> files = [f for f in os.listdir('.') if f.endswith('.py')]
|
||||
>>> for f in files:
|
||||
... ret = os.system ('python %s' % f) # return value is system dependent
|
||||
... if ret != 0 and sys.platform.startswith('linux'):
|
||||
... print 'Error:', f, 'returned', ret
|
||||
|
||||
# run png snippets
|
||||
>>> cmd = 'python snippets_png.py -s'
|
||||
>>> _dir = os.path.join(cwd, '..', 'examples', 'cairo_snippets')
|
||||
>>> os.chdir (_dir)
|
||||
>>> ret = os.system (cmd)
|
||||
>>> if ret != 0 and sys.platform.startswith('linux'):
|
||||
... print 'Error:', cmd, 'returned', ret
|
||||
|
Loading…
Reference in New Issue