Exemplo n.º 1
0
    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)
        true_result = matching_result.of(True)
        operand1 = MatcherWInitialAction(
            recorder_of_operand_application.action, true_result)
        operand2 = MatcherWInitialAction(
            recorder_of_operand_application.action, true_result)
        matcher = sut.Conjunction([operand1, operand2], freezer)

        # ACT #
        matcher.matches_w_trace(0)
        # ASSERT #
        self.assertEqual(expected_method_invocation_sequence,
                         invocation_recordings.recordings,
                         'method invocation sequence')
Exemplo n.º 2
0
def matcher_that_asserts_model_is_frozen(
        put: unittest.TestCase, result: bool,
        matcher_name: str) -> MatcherWTrace[TestModelWFreezing]:
    assert_model_is_frozen = ActionThatAppliesAssertion2(
        put,
        asrt.sub_component('is_frozen', TestModelWFreezing.is_frozen,
                           asrt.equals(True)),
        asrt.MessageBuilder(matcher_name))
    return MatcherWInitialAction(assert_model_is_frozen.action,
                                 matching_result.of(result))
 def __init__(
     self,
     name_for_err_msgs: str,
     result: bool,
     sequence_to_register_from: IntSequence,
 ):
     self.media = SequenceRecordingMedia()
     registry = IntSequenceRegistry(sequence_to_register_from, self.media)
     super().__init__(
         registry.action,
         matching_result.of(result),
     )
     self.name_for_err_msgs = name_for_err_msgs
Exemplo n.º 4
0
    def matches_w_trace(self, model: FileMatcherModel) -> MatchingResult:
        if not isinstance(model, FileMatcherModel):
            raise HardErrorException(
                text_doc_assertions.new_single_string_text_for_test(
                    'Model is not a {}: {}'.format(type(FileMatcherModel),
                                                   model)))

        if not model.file_type_access.is_type(FileType.DIRECTORY):
            raise HardErrorException(
                text_doc_assertions.new_single_string_text_for_test(
                    'Test failure: File is not a directory'))

        return matching_result.of(True)
Exemplo n.º 5
0
def matcher_that_applies_assertion(
    put: unittest.TestCase,
    assertion: Assertion[ACTUAL],
    get_actual: Callable[[MODEL], ACTUAL],
    message_builder: MessageBuilder,
    result: bool,
    structure: StructureRenderer = STRUCTURE_FOR_TEST,
) -> MatcherWTrace[MODEL]:
    return MatcherWInitialAction(
        ActionThatAppliesAssertion(
            put,
            assertion,
            get_actual,
            message_builder,
        ).action,
        matching_result.of(result),
        structure,
    )
Exemplo n.º 6
0
 def matches_w_trace(self, model: FileMatcherModel) -> MatchingResult:
     return matching_result.of(
         model.path.primitive.name.startswith(self._base_name_prefix))
Exemplo n.º 7
0
 def matches_w_trace(self, model: FileMatcherModel) -> MatchingResult:
     return matching_result.of(model.path.primitive.is_dir())
Exemplo n.º 8
0
 def matches_w_trace(self, model: FileMatcherModel) -> MatchingResult:
     return matching_result.of(
         model.file_type_access.is_type(FileType.DIRECTORY))
Exemplo n.º 9
0
 def matches_w_trace(self, model: LineMatcherLine) -> MatchingResult:
     return matching_result.of(model[0] in self._matching_line_numbers)
Exemplo n.º 10
0
 def matches_w_trace(self, model: LineMatcherLine) -> MatchingResult:
     return matching_result.of(self._sub_string in model[1])
Exemplo n.º 11
0
def matcher_that_accesses_contents_and_gives_constant(result: bool) -> MatcherWTrace[StringSource]:
    return MatcherWInitialAction(
        properties_access.get_string_source_contents,
        matching_result.of(result)
    )