def test_func_val_replace(self): argless = mapCmd.mapCmd({0: (lambda: 'spam', [])}, offset=0) self.assertEqual(argless[0](['x']), 'spam') arged = mapCmd.mapCmd({0: ((lambda x: 'spam'), [0])}) self.assertEqual(arged[0](['x']), 'spam') cmd = mapCmd.mapCmd({0: ((lambda x: x + 2), [0])}) self.assertEqual(cmd[0]([2]), 4)
def test_func_val_names(self): cmd = mapCmd.mapCmd({'A': ((lambda x: x + 2), ['B'])}, str_is_name=True) self.assertEqual(cmd[0]([1,2,3,4]), 4)
def test_func_val_offset(self): cmd = mapCmd.mapCmd({1: ((lambda x: x + 2), [2])}, offset=1) self.assertEqual(cmd[0]([1,2,3,4]), 4)
def test_value_val_replace(self): cmd = mapCmd.mapCmd({0: 'spam'}) self.assertEqual(cmd[0](['x']), 'spam')
def test_index_val_replace(self): cmd = mapCmd.mapCmd({0: 0}) self.assertEqual(cmd[0](['x']), 'x')
def test_name_val_replace(self): cmd = mapCmd.mapCmd({'a': 0}) self.assertEqual(cmd[0](['x']), 'x')
def test_invalid_key(self): with self.assertRaises(TypeError): mapCmd.mapCmd({(1, 2): 0}, str_is_name=True, int_is_index=True)
def test_name_key_offset(self): cmd = mapCmd.mapCmd({'A': 1, 2: 'B'}, str_is_name=True, offset=1) self.assertEqual([0, 1], list(cmd))
def test_name_key_replace(self): cmd = mapCmd.mapCmd({'A': 0, 1: 'B'}, str_is_name=True) self.assertEqual([0, 1], list(cmd))
def test_index_key_offset(self): cmd = mapCmd.mapCmd({1: 1}, offset=1) self.assertEqual([0], list(cmd))
def test_index_key(self): cmd = mapCmd.mapCmd({0: 0}) self.assertEqual([0], list(cmd))