def test_freezer_is_applied_once_before_operand_application(self):
        # ARRANGE #
        expected_method_invocation_sequence = [
            ApplicationMethod.FREEZE,
            ApplicationMethod.OPERAND_APPLICATION,
            ApplicationMethod.OPERAND_APPLICATION,
        ]
        invocation_recordings = SequenceRecordingMedia()
        recorder_of_freeze = ConstantRecorder(ApplicationMethod.FREEZE,
                                              invocation_recordings)
        freezer = FreezerThatRecordsApplication(
            recorder_of_freeze.action).freeze
        recorder_of_operand_application = ConstantRecorder(
            ApplicationMethod.OPERAND_APPLICATION, invocation_recordings)
        false_result = matching_result.of(False)
        operand1 = MatcherWInitialAction(
            recorder_of_operand_application.action, false_result)
        operand2 = MatcherWInitialAction(
            recorder_of_operand_application.action, false_result)
        matcher = sut.Disjunction([operand1, operand2], freezer)

        # ACT #
        matcher.matches_w_trace(0)
        # ASSERT #
        self.assertEqual(expected_method_invocation_sequence,
                         invocation_recordings.recordings,
                         'method invocation sequence')
Example #2
0
 def visit_conjunction(
         self,
         operands: Sequence[MatcherWTrace[MODEL]]) -> IntIntervalWInversion:
     return self._matcher_evaluator(
         combinator_matchers.Disjunction([
             combinator_matchers.Negation(operand) for operand in operands
         ]))
Example #3
0
    def prune(self, dir_selector: FileMatcher) -> FilesMatcherModel:
        new_dir_selector = (dir_selector if self._directory_prune is None else
                            combinator_matchers.Disjunction(
                                [self._directory_prune, dir_selector]))

        return _FilesMatcherModelForDir(
            self._dir_path,
            self._files_generator,
            self._files_selection,
            new_dir_selector,
        )
    def test_frozen_model_is_passed_to_operands(self):
        # ARRANGE #
        operand1 = matcher_that_asserts_model_is_frozen(
            self, False, 'operand1')
        operand2 = matcher_that_asserts_model_is_frozen(
            self, False, 'operand2')
        matcher = sut.Disjunction([operand1, operand2], give_frozen_model)

        original_unfrozen_model = TestModelWFreezing(False)
        # ACT & ASSERT #
        matcher.matches_w_trace(original_unfrozen_model)
    def test_accept_visitor_invokes_correct_method(self):
        # ARRANGE #
        operand1 = constant.MatcherWithConstantResult(False)
        operand2 = constant.MatcherWithConstantResult(False)
        matcher = sut.Disjunction([operand1, operand2])

        return_value = 11
        visitor = MatcherStdTypeVisitorTestAcceptImpl.new_w_default_to_raise_exception(
            disjunction_action=assert_argument_satisfies__and_return(
                self,
                asrt.matches_sequence([asrt.is_(operand1),
                                       asrt.is_(operand2)]),
                return_value,
            ))
        actual_return_value = matcher.accept(visitor)
        # ASSERT #
        self.assertEqual(return_value, actual_return_value, 'return value')