F5OEO-tstools/python/test.txt

136 wiersze
3.2 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
ES unit: start code 01
ES unit: start code 02
ES unit: start code 03
ES unit: start code 04
ES unit: start code 05
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'
>>> 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
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: