Exemplo n.º 1
0
 def test_fail_if_instruction_is_not_phase_agnostic__multi(self):
     with self.assertRaises(utils.TestError):
         checker = sut.Checker(ParserThatGives(instruction_embryo_that__phase_agnostic()))
         checker.check__abs_stx__multi__std_layouts_and_source_variants(
             self.tc,
             CustomAbsStx.empty(),
             symbol_usages=asrt.is_empty_sequence,
             execution_cases=[
                 NArrEx(
                     'the one and only case',
                     Arrangement.setup_phase_aware(),
                     ExecutionExpectation.setup_phase_aware(),
                 )
             ]
         )
Exemplo n.º 2
0
    def _check_source_and_exe_variants__failing_assertions(
            self,
            parser: embryo.InstructionEmbryoParser[T],
            arrangement: Arrangement,
            expectation: MultiSourceExpectation[T],
            sub_test_identifiers: Mapping[str, Any] = MappingProxyType({}),
    ):
        """Runs check methods for both single and multi-source.

        Source consumption is assumed to be correct (and is not tested by this method).

        :param parser: Must not consume any source.
        """
        checker = sut.Checker(ParserThatConsumesCurrentLine(parser))

        with self.subTest(zz_execution='single', **sub_test_identifiers):
            with self.assertRaises(utils.TestError):
                checker.check(self.tc,
                              remaining_source('irrelevant source'),
                              arrangement,
                              expectation.as_w_source(asrt.anything_goes()),
                              )

        with self.subTest(zz_execution='w source variants', **sub_test_identifiers):
            with self.assertRaises(utils.TestError):
                checker.check__w_source_variants(
                    self.tc,
                    'irrelevant source',
                    arrangement,
                    expectation,
                )

        with self.subTest(zz_execution='multi execution', **sub_test_identifiers):
            with self.assertRaises(utils.TestError):
                checker.check__abs_stx__multi__std_layouts_and_source_variants(
                    self.tc,
                    CustomAbsStx.of_str('irrelevant source'),
                    symbol_usages=expectation.symbol_usages,
                    execution_cases=[
                        NArrEx(
                            'the one and only case',
                            arrangement,
                            expectation,
                        ),
                    ]
                )
Exemplo n.º 3
0
    def runTest(self):
        # ARRANGE #
        dst_file_name = 'dst-file_name-file.txt'
        src_file = File('src-file_name-file.txt', 'contents')
        home_dir_contents = DirContents([src_file])
        expected_destination_dir_contents = DirContents([File(dst_file_name, src_file.contents)])

        dst_rel_option = rel_opt_conf.symbol_conf_rel_non_hds(
            defs.ARBITRARY_LEGAL_RELATIVITY__DST__NON_HDS,
            'DST_SYMBOL',
            defs.PATH_RELATIVITY_VARIANTS__DST,
        )
        for phase_is_after_act in [False, True]:
            with self.subTest(phase_is_after_act=phase_is_after_act):
                checker = instruction_embryo_check.Checker(sut.EmbryoParser(phase_is_after_act))
                src_rel_option = rel_opt_conf.symbol_conf_rel_hds(
                    defs.ARBITRARY_LEGAL_RELATIVITY__SRC__HDS,
                    'SRC_SYMBOL',
                    defs.path_relativity_variants__src(phase_is_after_act),
                )
                # ACT & ASSERT #
                checker.check(
                    self,
                    args.copy(src_rel_option.path_argument_of_rel_name(src_file.name),
                              dst_rel_option.path_argument_of_rel_name(dst_file_name)
                              ).as_remaining_source,
                    Arrangement.phase_agnostic(
                        tcds=TcdsArrangement(
                            hds_contents=src_rel_option.populator_for_relativity_option_root__hds(home_dir_contents),
                        ),
                        symbols=SymbolContext.symbol_table_of_contexts(
                            src_rel_option.symbols.contexts_for_arrangement() +
                            dst_rel_option.symbols.contexts_for_arrangement()
                        )
                    ),
                    Expectation.phase_agnostic_2(
                        symbol_usages=asrt.matches_sequence(
                            src_rel_option.symbols.usage_expectation_assertions() +
                            dst_rel_option.symbols.usage_expectation_assertions()
                        ),
                        main_side_effects_on_sds=sds_contents_check.non_hds_dir_contains_exactly(
                            dst_rel_option.root_dir__non_hds,
                            expected_destination_dir_contents),

                    ),
                )
Exemplo n.º 4
0
    )


def _successful__append() -> ContentsCase:
    created_file = fs.File.empty('created-regular-file')
    dst_dir = fs.Dir('destination-dir', [
        created_file,
    ])

    return ContentsCase(
        'create',
        dst_dir.name,
        fs_abs_stx.DirContentsExplicitAbsStx(
            ModificationType.APPEND,
            fs_abs_stx.LiteralFilesSourceAbsStx([
                fs_abs_stx.regular_file_spec__str_name(
                    created_file.name,
                    fs_abs_stx.FileContentsEmptyAbsStx(),
                )
            ])
        ),
        pre_existing_files=[fs.Dir.empty(dst_dir.name)],
        expected_files=[dst_dir]
    )


_CHECKER = embryo_check.Checker(sut.EmbryoParser())

if __name__ == '__main__':
    unittest.TextTestRunner().run(suite())
Exemplo n.º 5
0
def suite() -> unittest.TestSuite:
    return unittest.TestSuite([
        TestSystemProgramIsExecuted(),
        TestSymbolReferences(),
        TestArgumentsShouldBeValidated(),
        TestHardErrorFromExecution(),
        TestNonZeroExitCodeFromExecution(),
        TestContentsOfStdinShouldBeEmpty(),
        unittest.makeSuite(TestFailingParse),
        suite_for_instruction_documentation(sut.DescriptionForNonAssertPhaseInstruction('instruction name',
                                                                                        'section_name'))
    ])


CHECKER = embryo_check.Checker(sut.embryo_parser('instruction-name'))


class ArgumentsCase:
    def __init__(self,
                 name: str,
                 arguments: ArgumentElementsRenderer,
                 expected_arguments: Assertion[Sequence[str]],
                 symbols: Sequence[SymbolContext] = (),
                 ):
        self.name = name
        self.arguments = arguments
        self.symbols = symbols
        self.expected_arguments = expected_arguments

Exemplo n.º 6
0
from exactly_lib.impls.instructions.multi_phase.environ import parse as sut
from exactly_lib.impls.instructions.multi_phase.environ.impl import Phase
from exactly_lib_test.impls.instructions.multi_phase.test_resources import instruction_embryo_check as embryo_check
from exactly_lib_test.section_document.test_resources import parse_checker

PHASE_SPECS = [
    None,
    Phase.ACT,
    Phase.NON_ACT,
]

CHECKER = embryo_check.Checker(sut.EmbryoParser(phase_is_after_act=False))

PARSE_CHECKER = parse_checker.Checker(
    sut.EmbryoParser(phase_is_after_act=False))
Exemplo n.º 7
0
from typing import Optional

from exactly_lib.common.report_rendering.text_doc import TextRenderer
from exactly_lib.impls.instructions.multi_phase import new_file as sut
from exactly_lib_test.impls.instructions.multi_phase.test_resources import \
    instruction_embryo_check as embryo_check
from exactly_lib_test.section_document.test_resources import parse_checker

PARSE_CHECKER = parse_checker.Checker(sut.EmbryoParser(False))

CHECKER__BEFORE_ACT = embryo_check.Checker(sut.EmbryoParser(False))
CHECKER__AFTER_ACT = embryo_check.Checker(sut.EmbryoParser(True))

CHECKERS = {
    False: CHECKER__BEFORE_ACT,
    True: CHECKER__AFTER_ACT,
}


def checker(
        phase_is_after_act: bool
) -> embryo_check.Checker[Optional[TextRenderer]]:
    return CHECKERS[phase_is_after_act]
Exemplo n.º 8
0
from exactly_lib.impls.instructions.multi_phase.define_symbol import parser as sut
from exactly_lib_test.impls.instructions.multi_phase.test_resources import \
    instruction_embryo_check
from exactly_lib_test.section_document.test_resources import parse_checker

INSTRUCTION_CHECKER = instruction_embryo_check.Checker(sut.EmbryoParser())

PARSE_CHECKER = parse_checker.Checker(sut.EmbryoParser())
Exemplo n.º 9
0
def embryo_checker(
        is_after_act_phase: bool
) -> embryo_check.Checker[Optional[TextRenderer]]:
    return embryo_check.Checker(sut.EmbryoParser(is_after_act_phase))
Exemplo n.º 10
0
                                 destination_rel_opt: rel_opt_conf.RelativityOptionConfigurationForRelNonHds,
                                 contents: DirContents,
                                 ) -> sds_populator.SdsPopulator:
        return sds_populator.contents_in_resolved_dir(
            sds_populator.SdsSubDirResolverFromSdsFun(destination_rel_opt.root_dir__non_hds),
            contents,
        )


_PARSER__BEFORE_ACT = sut.EmbryoParser(False)
_PARSER__AFTER_ACT = sut.EmbryoParser(True)

_PARSE_CHECKER__BEFORE_ACT = parse_checker.Checker(_PARSER__BEFORE_ACT)
_PARSE_CHECKER__AFTER_ACT = parse_checker.Checker(_PARSER__AFTER_ACT)

_EXECUTION_CHECKER__BEFORE_ACT = instruction_embryo_check.Checker(_PARSER__BEFORE_ACT)
_EXECUTION_CHECKER__AFTER_ACT = instruction_embryo_check.Checker(_PARSER__AFTER_ACT)

_PARSERS = [
    NameAndValue('before act',
                 _PARSER__BEFORE_ACT
                 ),
    NameAndValue('after act',
                 _PARSER__AFTER_ACT
                 ),
]

_PARSE_CHECKERS = [
    NameAndValue('before act',
                 _PARSE_CHECKER__BEFORE_ACT
                 ),