def testSubclassFiles(self):
        sampleInstanceFile = self.testDirectory + '/test_files/sample_instance.xml'
        instanceFileHandler = InstanceFileHandler(sampleInstanceFile)

        ankleLinearCoeffs = instanceFileHandler.gatherCoeffs(
            '/left_leg/ankle/actuator0')
        torsoLinearCoeffs = instanceFileHandler.gatherCoeffs(
            '/trunk/left_actuator')

        assert (torsoLinearCoeffs['ForceControl_SensorFeedback'] == 0)
        assert (ankleLinearCoeffs['ForceControl_SensorFeedback'] == 1)

        assert (torsoLinearCoeffs['ForceControl_Kp'] == 1)
        assert (torsoLinearCoeffs['ForceControl_Kd'] == 2)

        assert (ankleLinearCoeffs['ForceControl_Kp'] == 3)
        assert (ankleLinearCoeffs['ForceControl_Kd'] == 4)

        assert (torsoLinearCoeffs['EffortControl_Alpha'] == 0.99)
        assert (torsoLinearCoeffs['EffortControl_AlphaDot'] == 0.9)

        assert (ankleLinearCoeffs['EffortControl_Alpha'] == 0.93)
        assert (ankleLinearCoeffs['EffortControl_AlphaDot'] == 0.45)

        assert (torsoLinearCoeffs['SpringStiffness'] == 714000.0)

        assert (ankleLinearCoeffs['SpringStiffness'] == 1.6085e6)
    def testSubclassFiles(self):
        sampleInstanceFile = self.testDirectory + '/test_files/sample_instance.xml'
        instanceFileHandler = InstanceFileHandler(sampleInstanceFile)

        ankleLinearCoeffs = instanceFileHandler.gatherCoeffs('/left_leg/ankle/actuator0')
        torsoLinearCoeffs = instanceFileHandler.gatherCoeffs('/trunk/left_actuator')

        assert(torsoLinearCoeffs['ForceControl_SensorFeedback'] == 0)
        assert(ankleLinearCoeffs['ForceControl_SensorFeedback'] == 1)

        assert(torsoLinearCoeffs['ForceControl_Kp'] == 1)
        assert(torsoLinearCoeffs['ForceControl_Kd'] == 2)

        assert(ankleLinearCoeffs['ForceControl_Kp'] == 3)
        assert(ankleLinearCoeffs['ForceControl_Kd'] == 4)

        assert(torsoLinearCoeffs['EffortControl_Alpha'] == 0.99)
        assert(torsoLinearCoeffs['EffortControl_AlphaDot'] == 0.9)

        assert(ankleLinearCoeffs['EffortControl_Alpha'] == 0.93)
        assert(ankleLinearCoeffs['EffortControl_AlphaDot'] == 0.45)

        assert(torsoLinearCoeffs['SpringStiffness'] == 714000.0)

        assert(ankleLinearCoeffs['SpringStiffness'] == 1.6085e6)
    def testGatherCoeffsHandleKeyError(self):
        sampleInstanceFile = self.testDirectory + \
            '/test_files/sample_instance.xml'
        instanceFileHandler = InstanceFileHandler(sampleInstanceFile)

        # This next line should NOT raise a key error!
        coeffs = instanceFileHandler.gatherCoeffs("/bum_leg/j1")
    def testGatherCoeffsHandleKeyError(self):
        sampleInstanceFile = self.testDirectory + \
            '/test_files/sample_instance.xml'
        instanceFileHandler = InstanceFileHandler(sampleInstanceFile)

    # This next line should NOT raise a key error!
        coeffs = instanceFileHandler.gatherCoeffs("/bum_leg/j1")
    def testGatherCoeffs(self):
        sampleInstanceFile = self.testDirectory + \
            '/test_files/sample_instance.xml'
        instanceFileHandler = InstanceFileHandler(sampleInstanceFile)

        coeffs = instanceFileHandler.gatherCoeffs("/left_leg/j1")

        expectedCoeffs = {'TemperatureSensor_SensorLoc2': 2.0, 'TemperatureSensor_SensorLoc1': 1.0, 'JointSensors_OutputPosition': 2.0,
                          'IGainAmpsPerBit': 0.018928, 'DeltaAPSSafeLimit': 9999.0, 'TorqueControl_enablePID': 1.0,
                          'TorqueControl_FFd_fc_Hz': 25.0, 'APS1DriftSafeLimit': 9999.0, 'PositionControl_MotorTorqueDirection': 1.0,
                          'TorqueControl_Kd_fc_Hz': 50.0, 'VelocitySafeLimit': 9999.0, 'WindingResistance': 2.112, 'JointOutputAPS_MountingGain': 1.0,
                          'JointSafety_LowerLimit_Rad': -3.15, 'CommTimeoutMs': 80.0, 'PhaseACurOffset': 2048.0, 'JerkSafeLimit': 9999.0,
                          'BusVoltage_SensorGain': 0.163412, 'PositionOffset_Rad': -1.6651, 'EncMountingDir': 1.0, 'TorqueControl_TdobWindupLimit_Nm': 80.0,
                          'MotorAccFilter_fc_Hz': 50.0, 'JointOutputAPS_CountsToRad': 0.00076699038, 'PhaseCCurOffset': 2045.0, 'SpaceVector_MaxNormVoltage': 0.666,
                          'MotorWindingType': 0.0, 'TorqueControl_Tdob_fc_Hz': 50.0, 'JointSensors_OutputVelocity': 1.0, 'Renishaw_CountsToRad': 5.8516723e-09,
                          'TorqueControl_m': 1.2, 'EncoderIndexOffset': 1.16973095726, 'BusVoltage_BitOffset': 2048.0, 'SpringStiffness': 2750.0,
                          'Inductance_DAxis': 0.0009, 'MotorVelFilter_fc_Hz': 800.0, 'JointKinematicDir': -1.0, 'TorqueOffset_Nm': -9.39, 'TemperatureSensor_MaxTemp1': 125.0,
                          'TorqueControl_MotorTorqueDirection': 1.0, 'TemperatureSensor_MaxTemp2': 110.0, 'PositionControl_Kd': 1.0, 'TorqueControl_Current2MotorTorque': 0.0375,
                          'PhaseBCurOffset': 2048.0, 'TorqueControl_PD_damp': 0.95, 'EncDriftSafeLimit': 9999.0, 'DeadTimeCompensation': 0.02, 'TorqueControl_b': 70.0, 'TorqueControl_enableDOB': 0.0,
                          'SpringAPS_MountingGain': -1.0, 'PositionControl_Kd_fc_Hz': 50.0, 'Inductance_QAxis': 0.00139, 'JointVelFilter_fc_Hz': 30.0,
                          'PositionControl_Kp': 500.0, 'TorqueControl_enableFF': 1.0, 'JointGearRatio': 160.0, 'NumberOfPoles': 8.0, 'PositionControl_SensorFeedback': 4.0,
                          'PositionControl_Input_fc_Hz': 30.0, 'JointMinValue': -3.14159265359, 'FluxLinkage': 0.0444, 'TorqueControl_Kd': 0.03, 'JointTorqueLimit_Nm': 10.0,
                          'TorqueControl_Kp': 3.351, 'SpringAPS_BitOffset': 115108200.0, 'JointSensors_MotorPosition': 1.0, 'JointSafety_LimitZone_Rad': 0.07,
                          'TorqueControl_enableDynFF': 0.0, 'TorqueControl_autoKd': 0.0, 'JointSensors_OutputForce': 2.0, 'PositionControl_enableInLPF': 1.0,
                          'Commutation_Select': 2.0, 'JointMaxValue': 3.14159265359, 'CurrVelFilter_fc_Hz': 200.0, 'TorqueControl_ParallelDamping': 0.0, 'JointSafety_UpperLimit_Rad': 3.15,
                          'EncoderCPR': 544.0, 'SpaceVector_CurrentToSV': 1.0, 'CurrentSafeLimit': 13.0, 'EffortControl_Alpha': 0.0, 'EffortControl_AlphaDot': 0.5}
        import difflib
        a = '\n'.join(['%s:%s' % (key, value) for (key, value) in sorted(coeffs.items())])
        b = '\n'.join(['%s:%s' % (key, value) for (key, value) in sorted(expectedCoeffs.items())])
        for coeff in coeffs:
            assert not coeff==None
    def testGatherCoeffs(self):
        sampleInstanceFile = self.testDirectory + \
            '/test_files/sample_instance.xml'
        instanceFileHandler = InstanceFileHandler(sampleInstanceFile)

        coeffs = instanceFileHandler.gatherCoeffs("/left_leg/j1")

        expectedCoeffs = {
            'TemperatureSensor_SensorLoc2': 2.0,
            'TemperatureSensor_SensorLoc1': 1.0,
            'JointSensors_OutputPosition': 2.0,
            'IGainAmpsPerBit': 0.018928,
            'DeltaAPSSafeLimit': 9999.0,
            'TorqueControl_enablePID': 1.0,
            'TorqueControl_FFd_fc_Hz': 25.0,
            'APS1DriftSafeLimit': 9999.0,
            'PositionControl_MotorTorqueDirection': 1.0,
            'TorqueControl_Kd_fc_Hz': 50.0,
            'VelocitySafeLimit': 9999.0,
            'WindingResistance': 2.112,
            'JointOutputAPS_MountingGain': 1.0,
            'JointSafety_LowerLimit_Rad': -3.15,
            'CommTimeoutMs': 80.0,
            'PhaseACurOffset': 2048.0,
            'JerkSafeLimit': 9999.0,
            'BusVoltage_SensorGain': 0.163412,
            'PositionOffset_Rad': -1.6651,
            'EncMountingDir': 1.0,
            'TorqueControl_TdobWindupLimit_Nm': 80.0,
            'MotorAccFilter_fc_Hz': 50.0,
            'JointOutputAPS_CountsToRad': 0.00076699038,
            'PhaseCCurOffset': 2045.0,
            'SpaceVector_MaxNormVoltage': 0.666,
            'MotorWindingType': 0.0,
            'TorqueControl_Tdob_fc_Hz': 50.0,
            'JointSensors_OutputVelocity': 1.0,
            'Renishaw_CountsToRad': 5.8516723e-09,
            'TorqueControl_m': 1.2,
            'EncoderIndexOffset': 1.16973095726,
            'BusVoltage_BitOffset': 2048.0,
            'SpringStiffness': 2750.0,
            'Inductance_DAxis': 0.0009,
            'MotorVelFilter_fc_Hz': 800.0,
            'JointKinematicDir': -1.0,
            'TorqueOffset_Nm': -9.39,
            'TemperatureSensor_MaxTemp1': 125.0,
            'TorqueControl_MotorTorqueDirection': 1.0,
            'TemperatureSensor_MaxTemp2': 110.0,
            'PositionControl_Kd': 1.0,
            'TorqueControl_Current2MotorTorque': 0.0375,
            'PhaseBCurOffset': 2048.0,
            'TorqueControl_PD_damp': 0.95,
            'EncDriftSafeLimit': 9999.0,
            'DeadTimeCompensation': 0.02,
            'TorqueControl_b': 70.0,
            'TorqueControl_enableDOB': 0.0,
            'SpringAPS_MountingGain': -1.0,
            'PositionControl_Kd_fc_Hz': 50.0,
            'Inductance_QAxis': 0.00139,
            'JointVelFilter_fc_Hz': 30.0,
            'PositionControl_Kp': 500.0,
            'TorqueControl_enableFF': 1.0,
            'JointGearRatio': 160.0,
            'NumberOfPoles': 8.0,
            'PositionControl_SensorFeedback': 4.0,
            'PositionControl_Input_fc_Hz': 30.0,
            'JointMinValue': -3.14159265359,
            'FluxLinkage': 0.0444,
            'TorqueControl_Kd': 0.03,
            'JointTorqueLimit_Nm': 10.0,
            'TorqueControl_Kp': 3.351,
            'SpringAPS_BitOffset': 115108200.0,
            'JointSensors_MotorPosition': 1.0,
            'JointSafety_LimitZone_Rad': 0.07,
            'TorqueControl_enableDynFF': 0.0,
            'TorqueControl_autoKd': 0.0,
            'JointSensors_OutputForce': 2.0,
            'PositionControl_enableInLPF': 1.0,
            'Commutation_Select': 2.0,
            'JointMaxValue': 3.14159265359,
            'CurrVelFilter_fc_Hz': 200.0,
            'TorqueControl_ParallelDamping': 0.0,
            'JointSafety_UpperLimit_Rad': 3.15,
            'EncoderCPR': 544.0,
            'SpaceVector_CurrentToSV': 1.0,
            'CurrentSafeLimit': 13.0,
            'EffortControl_Alpha': 0.0,
            'EffortControl_AlphaDot': 0.5
        }
        import difflib
        a = '\n'.join([
            '%s:%s' % (key, value) for (key, value) in sorted(coeffs.items())
        ])
        b = '\n'.join([
            '%s:%s' % (key, value)
            for (key, value) in sorted(expectedCoeffs.items())
        ])
        for diffs in difflib.unified_diff(a.splitlines(), b.splitlines()):
            print diffs
        assert cmp(coeffs, expectedCoeffs) == 0