"""
Test DataAdapter interface.
"""
import os, unittest
import opensim as osim

test_dir = os.path.join(os.path.dirname(os.path.abspath(osim.__file__)),
                        'tests')

class TestDataAdapter(unittest.TestCase):
    def test_TRCFileAdapter(self):
        adapter = osim.TRCFileAdapter()
        table = adapter.read(os.path.join(test_dir, 
                             'futureOrientationInverseKinematics.trc'))
        assert table.getNumRows()    == 1202
        assert table.getNumColumns() == 2

        table = adapter.read(os.path.join(test_dir, 'TRCFileWithNANs.trc'))
        assert table.getNumRows()    == 5
        assert table.getNumColumns() == 14

    def test_STOFileAdapter(self):
        adapter = osim.STOFileAdapter()
        table = adapter.read(os.path.join(test_dir, 'subject02_grf_HiFreq.mot'))
        assert table.getNumRows()    == 439
        assert table.getNumColumns() == 18

        table = adapter.read(os.path.join(test_dir, 
                                          'std_subject01_walk1_ik.mot'))
        assert table.getNumRows()    == 73
        assert table.getNumColumns() == 23

    def test_C3DFileAdapter(self):
        try:
            adapter = osim.C3DFileAdapter()
        except AttributeError:
            # C3D support not available. OpenSim was not compiled with BTK.
            return
        tables = adapter.read(os.path.join(test_dir, 'walking2.c3d'))
        markers = tables['markers']
        forces = tables['forces']
        
        assert markers.getNumRows()    == 1249
        assert markers.getNumColumns() == 44
        assert forces.getNumRows()     == 9992
        assert forces.getNumColumns()  == 6

        tables = adapter.read(os.path.join(test_dir, 'walking5.c3d'))
        markers = tables['markers']
        forces = tables['forces']
        assert markers.getNumRows()    == 1103
        assert markers.getNumColumns() == 40
        assert forces.getNumRows()     == 8824
        assert forces.getNumColumns()  == 6

@@ -1742,32 +1742,33 @@
 walking5.c3d'))%0A
+%0A
         markers 
@@ -1791,42 +1791,8 @@
 s'%5D%0A
-        forces = tables%5B'forces'%5D%0A
     
@@ -1883,95 +1883,1051 @@
  40%0A
-        assert forces.getNumRows()     == 8824%0A        assert forces.getNumColumns()  == 6
+%0A        markersFlat = markers.flatten()%0A        assert markersFlat.getNumRows()    == 1103%0A        assert markersFlat.getNumColumns() == 40 * 3%0A%0A        markersFilename = 'markers.mot'%0A        stoAdapter = osim.STOFileAdapter()%0A        stoAdapter.write(markersFlat, markersFilename)%0A%0A        markersDouble = stoAdapter.read(markersFilename)%0A        assert markersDouble.getNumRows()    == 1103%0A        assert markersDouble.getNumColumns() == 40 * 3%0A        %0A        forces = tables%5B'forces'%5D%0A        assert forces.getNumRows()     == 8824%0A        assert forces.getNumColumns()  == 6%0A%0A        forcesFlat = forces.flatten()%0A        assert forcesFlat.getNumRows()    == 8824%0A        assert forcesFlat.getNumColumns() == 6 * 3%0A%0A        forcesFilename = 'forces.mot'%0A        stoAdapter.write(forcesFlat, forcesFilename)%0A%0A        forcesDouble = stoAdapter.read(forcesFilename)%0A        assert forcesDouble.getNumRows()    == 8824%0A        assert forcesDouble.getNumColumns() == 6 * 3%0A%0A        os.remove(markersFilename)%0A        os.remove(forcesFilename)
 %0A

Add python tests for C3D similar to Java.