예제 #1
0
 def test_serialization(self):
     #serialize and de-serialize
     self.assertEqual(self.ser, cp.serialize_mumodo(self.build))
     #de-serialize from file
     self.assertEqual(self.ser, cp.serialize_mumodo(self.from_file))
     #de-serialize from file with non-default encoding
     self.assertEqual(self.ser, cp.serialize_mumodo(self.from_file_enc))
     #de-serialize from file with many mumodos
     self.assertEqual(self.ser, cp.serialize_mumodo(self.from_many))
예제 #2
0
    def setUp(self):
        path_to_player = 'python test_player.py'
        self.test_mumodo = cp.Mumodo(name='A test mumodo object',
                                     description='A test mumodo object',
                                     url='[a.text.url]',
                                     localpath='data')
        self.VideoResource = cp.VideoResource(name='the_video',
                                         description='a test video resource',
                                            filename='testvideoresource.mp4',
                                              player=path_to_player,
                                              units='seconds',
                                              channel=0)
        self.AudioResource = cp.AudioResource(name='the_audio',
                                          description='a test audio resource',
                                             filename='testaudioresource.wav',
                                               player=path_to_player,
                                               units='seconds',
                                               channel=0)
        self.XIOStreamResource = cp.XIOStreamResource(name='tracked_xio',
                                     description='a test XIO stream resource',
                                            filename='testxioresource.xio.gz',
                                                      units='ms',
                                    sensorname='VeniceHubReplay/Venice/Body1',
                                            kwargs={'timestamp_offset': 10025})
        self.CSVStreamResource = cp.CSVStreamResource(name='tracked_csv',
                                                       units='ms',
                                     description='a test CSV stream resource',
                                                  filename='testxioascsv.csv',
                                     sensorname='VeniceHubReplay/Venice/Body1')
        self.PickledStreamResource = cp.PickledStreamResource(name='tracked_p',
                                                               units='ms',
                                  description='a test pickled stream resource',
                                                     filename='testpickledxio',
                                      sensorname='VeniceHubReplay/Venice/Body1')
        self.IntervalResource = cp.TextGridTierResource(name='interval_tgt',
                                                        units='seconds',
                                                  filename='testres.TextGrid',
                                                        tiername='S')
        self.PointResource = cp.TextGridTierResource(name='point_tgt',
                                                     units='seconds',
                                                  filename='testres.TextGrid',
                                                     tiername='CLAPS')
        self.IntervalCSVResource = cp.CSVTierResource(name='interval_csv',
                                                      units='seconds',
                                             filename='testintervalascsv.csv')
        self.PointCSVResource = cp.CSVTierResource(name='point_csv',
                                                   units='seconds',
                                               filename='testpointsascsv.csv')
        self.IntervalPickledResource = cp.PickledTierResource(name='interval_p',
                                                              units='seconds',
                                                  filename='testintervalpickle')
        self.PointPickledResource = cp.PickledTierResource(name='point_p',
                                                           units='seconds',
                                                     filename='testpointpickle')
        self.ImageResource = cp.ImageResource(name='image',
                                              filename='testimage.png')
        self.TextResource = cp.TextResource(name='text',
                                            filename='testres.txt',
                                            encoding='utf-16')

        self.CSVResource = cp.CSVResource(name='CSV',
                                          filename='testcsv.csv',
                                          kwargs={'sep': '\t'})

        self.BinaryResource = cp.BinaryResource(name='binary',
                                              filename='testaudioresource.wav')

        self.Resource = cp.Resource(name="generic", filename="test.eaf")

        self.test_mumodo.add_resource(self.VideoResource)
        self.test_mumodo.add_resource(self.AudioResource)
        self.test_mumodo.add_resource(self.XIOStreamResource)
        self.test_mumodo.add_resource(self.CSVStreamResource)
        self.test_mumodo.add_resource(self.PickledStreamResource)
        self.test_mumodo.add_resource(self.PointResource)
        self.test_mumodo.add_resource(self.IntervalResource)
        self.test_mumodo.add_resource(self.IntervalCSVResource)
        self.test_mumodo.add_resource(self.PointCSVResource)
        self.test_mumodo.add_resource(self.IntervalPickledResource)
        self.test_mumodo.add_resource(self.PointPickledResource)
        self.test_mumodo.add_resource(self.ImageResource)
        self.test_mumodo.add_resource(self.TextResource)
        self.test_mumodo.add_resource(self.CSVResource)
        self.test_mumodo.add_resource(self.BinaryResource)
        self.test_mumodo.add_resource(self.Resource)

        self.ser = cp.serialize_mumodo(self.test_mumodo)
        self.build = cp.build_mumodo(self.ser)[0]

        cp.write_mumodo_to_file([self.test_mumodo], "test_mumodo.mmd")
        self.from_file = cp.read_mumodo_from_file('test_mumodo.mmd')[0]

        cp.write_mumodo_to_file([self.test_mumodo],
                                "test_mumodo_enc.mmd",
                                encoding='utf-16')
        self.from_file_enc = cp.read_mumodo_from_file('test_mumodo_enc.mmd',
                                                      encoding='utf-16')[0]

        cp.write_mumodo_to_file([cp.Mumodo(), cp.Mumodo(), self.test_mumodo],
                                "many_mumodos.mmd")
        self.from_many = cp.read_mumodo_from_file('many_mumodos.mmd')[2]

        self.other_localpath = cp.read_mumodo_from_file('test_mumodo.mmd')[0]
        self.other_localpath.set_localpath("otherpath")