def test_key_formatter(self):
    'Tests print method with various key formatters'
    torqueKey = gtd.TorqueKey(0, 0).key()
    factor = gtd.MinTorqueFactor(torqueKey, gtsam.noiseModel.Unit.Create(1))
    with patch('sys.stdout', new=StringIO()) as fake_out:
        factor.print('factor: ', gtd.GTDKeyFormatter)
        self.assertTrue(('factor: min torque factor' in fake_out.getvalue()))
        self.assertTrue(('keys = { T(0)0 }' in fake_out.getvalue()))

    def myKeyFormatter(key):
        return 'this is my key formatter {}'.format(key)
    with patch('sys.stdout', new=StringIO()) as fake_out:
        factor.print('factor: ', myKeyFormatter)
        self.assertTrue(('factor: min torque factor' in fake_out.getvalue()))
        self.assertTrue(('keys = {{ this is my key formatter {} }}'.format(torqueKey) in fake_out.getvalue()))
Tests print method with various key formatters
def test_key_formatter(self):
    
    torqueKey = gtd.TorqueKey(0, 0).key()
    factor = gtd.MinTorqueFactor(torqueKey, gtsam.noiseModel.Unit.Create(1))
    with patch('sys.stdout', new=StringIO()) as fake_out:
        factor.print('factor: ', gtd.GTDKeyFormatter)
        self.assertTrue(('factor: min torque factor' in fake_out.getvalue()))
        self.assertTrue(('keys = { T(0)0 }' in fake_out.getvalue()))

    def myKeyFormatter(key):
        return 'this is my key formatter {}'.format(key)
    with patch('sys.stdout', new=StringIO()) as fake_out:
        factor.print('factor: ', myKeyFormatter)
        self.assertTrue(('factor: min torque factor' in fake_out.getvalue()))
        self.assertTrue(('keys = {{ this is my key formatter {} }}'.format(torqueKey) in fake_out.getvalue()))