def test_dict_eq(self): letters = {'a': 'A', 'b': 'B', 'c': 'C'} operand = {'a': 'A', 'b': 'B'} eq_pred = jp.DICT_EQ(operand) self.assertBad(letters, eq_pred) self.assertGood(operand, eq_pred) self.assertBad({'a': 'A'}, eq_pred)
def test_path_value_found_top(self): source = _COMPOSITE_DICT pred = jp.PathEqPredicate('letters', _LETTER_DICT) result = pred(source) expect = _make_result(pred, jp.DICT_EQ(_LETTER_DICT), source, [PathValue('letters', _LETTER_DICT)], []) self.assertTrue(result) self.assertEqual(expect, result)
def test_dict_eq_indirect(self): context = ExecutionContext(testA='A', testKey='b') letters = {'a': 'A', 'b': 'B', 'c': 'C'} operand = {'a': lambda x: x['testA'], 'b': 'B'} actual_operand = {'a': 'A', 'b': 'B'} eq_pred = jp.DICT_EQ(operand) self.assertBad(letters, eq_pred, context=context) self.assertGood(actual_operand, eq_pred, context=context) self.assertBad({'a': 'A'}, eq_pred, context=context)
def test_dict_eq(self): letters = {'a': 'A', 'b': 'B', 'c': 'C'} operand = {'a': 'A', 'b': 'B'} eq_pred = jp.DICT_EQ(operand) self.assertBadResult(PathValue('', letters), eq_pred, eq_pred(letters)) self.assertGoodResult(PathValue('', operand), eq_pred, eq_pred(operand)) self.assertBadResult(PathValue('', {'a': 'A'}), eq_pred, eq_pred({'a': 'A'}))
def test_dict_eq(self): context = ExecutionContext() letters = {'a':'A', 'b':'B', 'c':'C'} operand = {'a': 'A', 'b': 'B'} eq_pred = jp.DICT_EQ(operand) self.assertBadResult(PathValue('', letters), eq_pred, eq_pred(context, letters)) self.assertGoodResult(PathValue('', operand), eq_pred, eq_pred(context, operand)) self.assertBadResult(PathValue('', {'a': 'A'}), eq_pred, eq_pred(context, {'a': 'A'}))
def test_dict_eq_indirect(self): context = ExecutionContext(testA='A', testKey='b') letters = {'a':'A', 'b':'B', 'c':'C'} operand = {'a': lambda x: x['testA'], 'b': 'B'} actual_operand = {'a': 'A', 'b': 'B'} eq_pred = jp.DICT_EQ(operand) self.assertBadResult(PathValue('', letters), eq_pred, eq_pred(context, letters)) self.assertGoodResult(PathValue('', actual_operand), eq_pred, eq_pred(context, actual_operand)) self.assertBadResult(PathValue('', {'a': 'A'}), eq_pred, eq_pred(context, {'a': 'A'}))