F5OEO-tstools/python/test.txt

174 wiersze
4.8 KiB
ReStructuredText
Czysty Wina Historia

This file contains invisible Unicode characters!

This file contains invisible Unicode characters that may be processed differently from what appears below. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to reveal hidden characters.

Some tests for the Python binding of the TS tools
=================================================
It's difficult to find example data files that are generally available. For
the moment, I'm going to use a file I have locally, and unfortunately others
will have to manage without. This is still better than no testing...
>>> test_es_file = '/Users/tibs/sw/tstools/data/aladdin.es'
First, check we've got the basics working:
>>> from tstools import ESFile
>>> try:
... stream = ESFile(test_es_file)
... except:
... test_es_file = '/home/tibs/Videos/aladdin.es'
... stream = ESFile(test_es_file)
The filename is available as a "readonly" value:
>>> stream.name == test_es_file
True
We've opened it for read:
>>> stream.is_readable() == True
True
>>> stream.is_writable() == False
True
>>> stream.mode
'r'
We should be able to iterate over its ES units:
>>> count = 0
>>> es_unit_list = []
>>> for unit in stream:
... count += 1
... print unit
... es_unit_list.append(unit)
... if count > 5:
... break
ES unit: start code 00, len 14: 00 00 01 00 01 1a 01 02
ES unit: start code 01, len 972: 00 00 01 01 1a 10 73 10
ES unit: start code 02, len 515: 00 00 01 02 1a 10 b3 05
ES unit: start code 03, len 372: 00 00 01 03 2a 11 31 41
ES unit: start code 04, len 347: 00 00 01 04 32 11 75 8f
ES unit: start code 05, len 335: 00 00 01 05 32 11 70 8b
From hexdump I get (something that can be written out as)::
00 00 01 00 01 1a 01 02 20 00 00 00 00 00
00 00 01 01 1a 10 73 10 1e 67 08 53 75 65 bf 1d 00 6d ...
which tends to support those results (applying the rule "split before
00 00 01")..
Confusingly ('cos it confuses me, who am easily confused), ``esreport -es -v``
gives me something that translates as::
ES unit: start code 00, len 12: 00 00 01 00 00 4a 0c 98
ES unit: start code 01, len 1717: 00 00 01 01 1a 87 e2 40
ES unit: start code 02, len 988: 00 00 01 02 1b f8 90 69
ES unit: start code 03, len 865: 00 00 01 03 2a 93 e2 45
ES unit: start code 04, len 803: 00 00 01 04 2a 93 e2 45
ES unit: start code 05, len 685: 00 00 01 05 32 93 e2 65
(which suggests I'm misremembering how that works).
And close it:
>>> stream.close()
>>> stream.is_writable() == False
True
>>> stream.is_readable() == False
True
>>> stream.mode is None
True
We can ask an ES unit about itself:
>>> unit = es_unit_list[0]
>>> unit.start_posn
(0, 0)
>>> unit.start_code
0
>>> unit.PES_had_PTS
0
>>> data = unit.data
>>> len(data)
14
>>> data[0]
'\x00'
>>> text = 'data:'
>>> for ii in range(8):
... text += ' %02x'%ord(data[ii])
>>> print text
data: 00 00 01 00 01 1a 01 02
>>> unit.fred
Traceback (most recent call last):
...
AttributeError
ES units can be compared for equality (but not order):
>>> es_unit_list[0] == es_unit_list[0]
1
>>> es_unit_list[0] == es_unit_list[1]
0
>>> es_unit_list[0] != es_unit_list[1]
1
>>> es_unit_list[0] != es_unit_list[0]
0
>>> es_unit_list[0] < es_unit_list[1]
Traceback (most recent call last):
...
TypeError: ESUnit only supports == and != comparisons
We can create an ES unit from a Python 'string':
>>> from tstools import ESUnit
>>> print 'old ',repr(es_unit_list[0])
old ES unit: start code 00, len 14: 00 00 01 00 01 1a 01 02
>>> new = ESUnit(es_unit_list[0].data)
>>> print 'new ',repr(new)
new ES unit: start code 00, len 14: 00 00 01 00 01 1a 01 02
>>> print 'old ',repr(es_unit_list[0])
old ES unit: start code 00, len 14: 00 00 01 00 01 1a 01 02
>>> new == es_unit_list[0]
True
And write another file...
>>> import tempfile
>>> import os
>>> directory = tempfile.mkdtemp()
>>> filename = os.path.join(directory,'tstools_test_1.es')
>>> out = ESFile(filename,'w')
>>> out.name == filename
True
>>> out.is_readable() == False
True
>>> out.is_writable() == True
True
>>> out.mode
'w'
>>> for unit in es_unit_list:
... out.write(unit)
>>> out.close()
Did that do the right thing? Check that we can read the units back (one by
one, to test the ``read`` method), and that the units we read back are
identical to those we wrote.
>>> infile = ESFile(filename,'r')
>>> other_units = []
>>> for ii in range(0,6):
... other_units.append(infile.read())
>>>
>>> for ii in range(0,6):
... if es_unit_list[ii] != other_units[ii]:
... print 'Error: unit %d does not match'%ii
... break
// Local Variables:
// tab-width: 8
// indent-tabs-mode: nil
// c-basic-offset: 2
// End:
// vim: set filetype=rst tabstop=8 shiftwidth=2 expandtab: