Example #1
0
    def runTest(self):
        # ARRANGE #
        cases = [
            NameAndValue(
                'empty',
                '',
            ),
            NameAndValue(
                'single line',
                'abc',
            ),
            NameAndValue(
                'multi line',
                '1st\n2nd\n',
            ),
        ]
        for case in cases:
            with self.subTest(case.name):
                source_constructor = _SourceConstructor(case.value)
                expectation = multi_obj_assertions.ExpectationOnUnFrozenAndFrozen.equals(
                    ''.join(source_constructor.contents),
                    may_depend_on_external_resources=asrt.equals(False),
                    frozen_may_depend_on_external_resources=asrt.equals(False),
                )

                assertion = multi_obj_assertions.assertion_of_sequence_permutations(
                    expectation)
                # ACT & ASSERT #
                assertion.apply_without_message(
                    self,
                    multi_obj_assertions.SourceConstructors.of_common(
                        source_constructor),
                )
Example #2
0
    def runTest(self):
        # ARRANGE #
        for transformation_may_depend_on_external_resources in [False, True]:
            with self.subTest(transformation_may_depend_on_external_resources=
                              transformation_may_depend_on_external_resources):
                source_constructor = _SourceConstructorOfTransFun(
                    _transformer_function,
                    [
                        '1st\n',
                        '2nd\n',
                    ],
                    transformation_may_depend_on_external_resources,
                )
                expectation = multi_obj_assertions.ExpectationOnUnFrozenAndFrozen.equals(
                    ''.join(_transformer_function(source_constructor.lines)),
                    may_depend_on_external_resources=asrt.equals(
                        transformation_may_depend_on_external_resources),
                    frozen_may_depend_on_external_resources=asrt.equals(
                        transformation_may_depend_on_external_resources),
                )

                assertion = multi_obj_assertions.assertion_of_sequence_permutations(
                    expectation)
                # ACT & ASSERT #
                assertion.apply_without_message(
                    self,
                    multi_obj_assertions.SourceConstructors.of_common(
                        source_constructor),
                )
    def test_exit_code_non_0_and_ignore_exit_code(self):
        # ARRANGE #
        input_raw_lines = [
            'a\n',
            'ab\n',
            '123\n',
        ]
        additional_transformer = string_transformers.count_num_uppercase_characters()
        expected = '1\n2\n0\n'
        expectation = multi_obj_assertions.ExpectationOnUnFrozenAndFrozen.equals(
            expected,
            may_depend_on_external_resources=asrt.equals(True),
            frozen_may_depend_on_external_resources=asrt.anything_goes(),
        )

        source_constructor = _ToUpperProgramSourceConstructor(
            input_raw_lines,
            ignore_exit_code=True,
            exit_code=1,
            transformation_of_program=[additional_transformer]
        )

        assertion = multi_obj_assertions.assertion_of_sequence_permutations(expectation)
        # ACT & ASSERT #
        assertion.apply_without_message(
            self,
            multi_obj_assertions.SourceConstructors.of_common(source_constructor),
        )
    def test_exit_code_0(self):
        # ARRANGE #
        input_raw_lines = [
            'a\n',
            'ab\n',
            '123\n',
        ]

        for ignore_exit_code in [False, True]:
            source_constructor = _ToUpperCommandSourceConstructor(
                input_raw_lines,
                ignore_exit_code=False,
                exit_code=0
            )
            expectation = multi_obj_assertions.ExpectationOnUnFrozenAndFrozen.equals(
                source_constructor.contents.upper(),
                may_depend_on_external_resources=asrt.equals(True),
                frozen_may_depend_on_external_resources=asrt.anything_goes(),
            )
            with self.subTest(ignore_exit_code=ignore_exit_code):
                assertion = multi_obj_assertions.assertion_of_sequence_permutations(expectation)
                # ACT & ASSERT #
                assertion.apply_without_message(
                    self,
                    multi_obj_assertions.SourceConstructors.of_common(source_constructor)
                )
Example #5
0
    def test_contents_is_larger_than_mem_buff(self):
        # ARRANGE #
        mem_buff_size = 4
        cases = [
            NameAndValue(
                'single line',
                'abc' * mem_buff_size,
            ),
            NameAndValue(
                'multi line',
                '1st\n2nd\n' * mem_buff_size,
            ),
        ]
        for case in cases:
            with self.subTest(case.name):
                source_constructor = _SourceConstructorOfUnfrozenAsConstStr(
                    case.value, mem_buff_size)
                expectation = multi_obj_assertions.ExpectationOnUnFrozenAndFrozen.equals(
                    ''.join(source_constructor.contents),
                    may_depend_on_external_resources=asrt.equals(False),
                    frozen_may_depend_on_external_resources=asrt.equals(True),
                )

                assertion = multi_obj_assertions.assertion_of_sequence_permutations(
                    expectation)
                # ACT & ASSERT #
                assertion.apply_without_message(
                    self,
                    multi_obj_assertions.SourceConstructors.of_common(
                        source_constructor),
                )
Example #6
0
def check_variants(expectation: sut.ExpectationOnUnFrozenAndFrozen,
                   ) -> Sequence[NameAndValue[Assertion[sut.SourceConstructors]]]:
    return [
        NameAndValue(
            'check sequence permutations',
            sut.assertion_of_sequence_permutations(expectation),
        ),
        NameAndValue(
            'check_with_first_access_is_not_write_to',
            sut.assertion_of_first_access_is_not_write_to(expectation),
        ),
        NameAndValue(
            'check_2_seq_w_file_first_and_last',
            sut.assertion_of_2_seq_w_file_first_and_last(expectation),
        ),
    ]
Example #7
0
def _check(put: unittest.TestCase,
           source_constructor: multi_obj_assertions.SourceConstructor,
           expected_contents: str):
    # ARRANGE #
    expectation = multi_obj_assertions.ExpectationOnUnFrozenAndFrozen.equals(
        expected_contents,
        may_depend_on_external_resources=asrt.equals(True),
        frozen_may_depend_on_external_resources=asrt.equals(True),
    )

    assertions = multi_obj_assertions.assertion_of_sequence_permutations(
        expectation)
    # ACT & ASSERT #
    assertions.apply_without_message(
        put,
        multi_obj_assertions.SourceConstructors.of_common(source_constructor),
    )
    def test_exit_code_non_0_and_not_ignore_exit_code(self):
        # ARRANGE #
        source_constructor = _ToUpperCommandSourceConstructor(
            [
                'a\n',
                'ab\n',
                '123\n',
            ],
            ignore_exit_code=False,
            exit_code=1
        )
        expectation = multi_obj_assertions.ExpectationOnUnFrozenAndFrozen.hard_error()

        assertion = multi_obj_assertions.assertion_of_sequence_permutations(expectation)
        # ACT & ASSERT #
        assertion.apply_without_message(
            self,
            multi_obj_assertions.SourceConstructors.of_common(source_constructor),
        )
    def test_exit_code_non_0_and_not_ignore_exit_code(self):
        # ARRANGE #
        source_constructor = _ToUpperProgramSourceConstructor(
            [
                'a\n',
                'ab\n',
                '123\n',
            ],
            ignore_exit_code=False,
            exit_code=1,
            transformation_of_program=[string_transformers.count_num_uppercase_characters()]
        )
        expectation = multi_obj_assertions.ExpectationOnUnFrozenAndFrozen.hard_error()

        assertion = multi_obj_assertions.assertion_of_sequence_permutations(expectation)
        # ACT & ASSERT #
        assertion.apply_without_message(
            self,
            multi_obj_assertions.SourceConstructors.of_common(source_constructor),
        )
Example #10
0
    def runTest(self):
        # ARRANGE #
        source_constructor = _SourceConstructor([
            '1st\n',
            '2nd\n',
        ])
        expectation = multi_obj_assertions.ExpectationOnUnFrozenAndFrozen.equals(
            ''.join(source_constructor.lines),
            may_depend_on_external_resources=asrt.anything_goes(),
            frozen_may_depend_on_external_resources=asrt.anything_goes(),
        )

        assertion = multi_obj_assertions.assertion_of_sequence_permutations(
            expectation)
        # ACT & ASSERT #
        assertion.apply_without_message(
            self,
            multi_obj_assertions.SourceConstructors.of_common(
                source_constructor),
        )
Example #11
0
    def test_arbitrary_model_method_invocations_in_arbitrary_order(self):
        # ARRANGE #
        source_constructor = _SourceConstructor(_transformer_function, [
            'a\n',
            'ab\n',
            '123\n',
        ])
        expectation = multi_obj_assertions.ExpectationOnUnFrozenAndFrozen.equals(
            ''.join(_transformer_function(source_constructor.raw_lines)),
            may_depend_on_external_resources=asrt.equals(True),
            frozen_may_depend_on_external_resources=asrt.anything_goes(),
        )

        assertion = multi_obj_assertions.assertion_of_sequence_permutations(
            expectation)
        # ACT & ASSERT #
        assertion.apply_without_message(
            self,
            multi_obj_assertions.SourceConstructors.of_common(
                source_constructor),
        )
    def test_exit_code_non_0_and_ignore_exit_code(self):
        # ARRANGE #
        source_constructor = _ToUpperCommandSourceConstructor(
            [
                'a\n',
                'ab\n',
                '123\n',
            ],
            ignore_exit_code=True,
            exit_code=1
        )
        expectation = multi_obj_assertions.ExpectationOnUnFrozenAndFrozen.equals(
            source_constructor.contents.upper(),
            may_depend_on_external_resources=asrt.equals(True),
            frozen_may_depend_on_external_resources=asrt.anything_goes(),
        )

        assertion = multi_obj_assertions.assertion_of_sequence_permutations(expectation)
        # ACT & ASSERT #
        assertion.apply_without_message(
            self,
            multi_obj_assertions.SourceConstructors.of_common(source_constructor),
        )