Printing and doctests: and yet it still doesn't do what I want.

(Learning experience)

--HG--
extra : convert_revision : svn%3Aeff31bef-be4a-0410-a8fe-e47997df2690/trunk%40120
issue20
tibs 2009-02-18 13:35:31 +00:00
rodzic be29f14a88
commit cf83dcabe0
4 zmienionych plików z 64 dodań i 8 usunięć

Wyświetl plik

@ -1,6 +1,34 @@
Some tests for the Python binding of the TS tools
=================================================
We'd like the tstools C messages to get captured by doctest, so we can see
them in our tests, so:
>>> from tstools import printing
>>> printing.setup_printing_for_doctest()
Printing redirected for doctest
>>> printing.test_printing()
YY Message
YY Error
XX Message "Fred"
XX Error "Fred"
and again:
>>> printing.test_printing()
YY Message
YY Error
XX Message "Fred"
XX Error "Fred"
and even:
>>> printing.test_c_printing()
YY C Message
YY C Error
XX C Message Fred
XX C Error Fred
Elementary streams -- basic functionality
-----------------------------------------
In this context, we take an elementary stream to be MPEG-1, MPEG-2 or H.264
@ -239,6 +267,11 @@ be overkill, but all seemed sensible at the time):
Traceback (most recent call last):
...
TSToolsException: Error seeking to (-1,) in file '../data/ed24p_11.video.es'
>>> printing.test_c_printing()
YY C Message
YY C Error
XX C Message Fred
XX C Error Fred
Let's try proper seeking, though:

Wyświetl plik

@ -38,3 +38,7 @@ I can test most easily!
# imported to tsools, so is probably not the best way to do it. Ho hum.
from ts import *
from es import *
# Make tstools messages (normal and error) redirect to Python stdout
import printing
printing.setup_printing()

Wyświetl plik

@ -34,8 +34,7 @@ I can test most easily!
#
# ***** END LICENSE BLOCK *****
import sys
import array
from ts import TSToolsException
cdef extern from *:
ctypedef char* const_char_ptr "const char*"
@ -93,17 +92,38 @@ def setup_printing():
cdef int err
err = redirect_output(our_print_msg, our_print_msg,
our_format_msg, our_format_msg)
if err == 0:
print 'Setting output redirection OK'
if err:
raise TSToolsException, 'Setting output redirection FAILED'
cdef void our_doctest_print_msg(const_char_ptr text):
print 'YY ' + text,
cdef void our_doctest_format_msg(const_char_ptr format, va_list arg_ptr):
cdef int err
cdef char buffer[1000]
PyOS_vsnprintf(buffer, 1000, format, arg_ptr)
print 'XX ' + buffer,
def setup_printing_for_doctest():
cdef int err
err = redirect_output(our_doctest_print_msg, our_doctest_print_msg,
our_doctest_format_msg, our_doctest_format_msg)
if err:
raise TSToolsException, 'Setting doctest output redirection FAILED'
else:
print 'Setting output redirection FAILED'
print 'Printing redirected for doctest'
def test_printing():
setup_printing()
print_msg('Message\n')
print_err('Error\n')
fprint_msg('Message "%s"\n','Fred')
fprint_msg('Error "%s"\n','Fred')
fprint_err('Error "%s"\n','Fred')
cdef extern from *:
void test_C_printing()
def test_c_printing():
test_C_printing()
# ----------------------------------------------------------------------
# vim: set filetype=python expandtab shiftwidth=4:

Wyświetl plik

@ -46,7 +46,6 @@ from common cimport uint8_t, uint16_t, uint32_t, uint64_t
from common cimport int8_t, int16_t, int32_t, int64_t
from common cimport PID, offset_t, byte
# Is this the best thing to do?
class TSToolsException(Exception):
pass