Exemplo n.º 1
0
class TestPositiveIntOnNonModelWSingleLine(unittest.TestCase):
    INPUT_LINES = ['the one and only line']
    CASES = [
        NArrEx(
            '0',
            0,
            [],
        ),
        NArrEx(
            'in range',
            1,
            INPUT_LINES,
        ),
        NArrEx(
            'too large',
            2,
            [],
        ),
    ]

    def test_with_model_access__only_as_lines_is_used(self):
        for case in self.CASES:
            with self.subTest(case.name, range=case.arrangement):
                _check_int_arg__w_max_lines_from_iter(
                    self,
                    case.arrangement,
                    InpExp(self.INPUT_LINES, case.expectation),
                )
Exemplo n.º 2
0
        def execution_cases(
            contents_of_non_checked_phase: Optional[Mapping[str, str]]
        ) -> List[NArrEx[Arrangement, ExecutionExpectation[None]]]:
            expectation_of_removed_var = setup.expectation_of_removal_from_phase_act(
                var_to_unset,
                contents_of_non_checked_phase=contents_of_non_checked_phase,
            )

            return [
                NArrEx(
                    'environ/existing (not None), other_is_populated={}'.
                    format(contents_of_non_checked_phase is not None),
                    arr(
                        non_act=contents_of_non_checked_phase,
                        the_act=setup.as_dict(Phase.ACT),
                        defaults_getter=get_empty_environ,
                    ),
                    expectation_of_removed_var,
                ),
                NArrEx(
                    'environ/non existing (None), other_is_populated={}'.
                    format(contents_of_non_checked_phase is not None),
                    arr(
                        non_act=contents_of_non_checked_phase,
                        the_act=None,
                        defaults_getter=setup.defaults_getter_with_values(
                            Phase.ACT),
                    ),
                    expectation_of_removed_var,
                ),
            ]
Exemplo n.º 3
0
 def runTest(self):
     self._check_cases([
         NArrEx('constant False', arg_rend.constant(False),
                asrt_interval.matches_empty()),
         NArrEx('constant True', arg_rend.constant(True),
                asrt_interval.matches_unlimited()),
     ])
Exemplo n.º 4
0
def _exe_cases_of_modification(
    before_modification: Sequence[NameAndValue[str]],
    after_modification: Sequence[NameAndValue[str]],
    symbols: Optional[SymbolTable] = None,
) -> Sequence[NArrEx[Arrangement, ExecutionExpectation[None]]]:
    expected = expectation(NameAndValue.as_dict(after_modification))
    return [
        NArrEx(
            'environ/existing (not None)',
            arr(
                NameAndValue.as_dict(before_modification),
                default_environ_getter=get_empty_environ,
                symbols=symbols,
            ),
            expected,
        ),
        NArrEx(
            'environ/non-existing None)',
            arr(
                None,
                default_environ_getter=defaults_getter__of_nav(
                    before_modification),
                symbols=symbols,
            ),
            expected,
        ),
    ]
Exemplo n.º 5
0
    def test_target_is_all_phases(self):
        # ACT & ASSERT #
        setup = self.ENVIRONS_SETUP__DIFFERENT
        identical_setup = self.ENVIRONS_SETUP__IDENTICAL
        var_to_unset = self.COMMON_VAR_TO_UNSET.name

        arbitrary_phase = Phase.NON_ACT

        all_execution_cases = [
            NArrEx(
                'non-act/populated, act/populated',
                arr(
                    non_act=setup.as_dict(Phase.NON_ACT),
                    the_act=setup.as_dict(Phase.ACT),
                    defaults_getter=get_empty_environ,
                ),
                setup.expectation_of_removal_from_phase_all(var_to_unset),
            ),
            NArrEx(
                'non-act/populated, act/not populated',
                arr(
                    non_act=setup.as_dict(Phase.NON_ACT),
                    the_act=None,
                    defaults_getter=setup.defaults_getter_with_values(
                        Phase.ACT),
                ),
                setup.expectation_of_removal_from_phase_all(var_to_unset),
            ),
            NArrEx(
                'non-act/not populated, act/populated',
                arr(
                    non_act=None,
                    the_act=setup.as_dict(Phase.ACT),
                    defaults_getter=setup.defaults_getter_with_values(
                        Phase.NON_ACT),
                ),
                setup.expectation_of_removal_from_phase_all(var_to_unset),
            ),
            NArrEx(
                'non-act/not populated, act/not populated',
                arr(
                    non_act=None,
                    the_act=None,
                    defaults_getter=identical_setup.
                    defaults_getter_with_values(arbitrary_phase),
                ),
                identical_setup.expectation_of_removal_from_phase_all(
                    var_to_unset),
            ),
        ]
        # ACT & ASSERT #
        CHECKER.check__abs_stx__multi__std_layouts_and_source_variants(
            self,
            UnsetVariableArgumentsAbsStx.of_str(var_to_unset, phase_spec=None),
            symbol_usages=asrt.is_empty_sequence,
            execution_cases=all_execution_cases,
        )
Exemplo n.º 6
0
    def test_main_method_arguments(self):
        # ARRANGE #
        the_environ = MappingProxyType({'an_env_var': 'an env var value'})

        the_timeout = 72
        the_os_services = os_services_access.new_for_current_os()

        setup_settings_cases = [
            NArrEx(
                'none',
                None,
                asrt.is_none,
            ),
            NArrEx(
                'not none',
                SetupSettingsArr(the_environ),
                _IsSettingsBuilderWoStdinWEnviron(asrt.equals(the_environ)),
            ),
        ]

        for setup_settings_case in setup_settings_cases:
            def main_action_that_checks_arguments(environment: InstructionEnvironmentForPostSdsStep,
                                                  instruction_settings: InstructionSettings,
                                                  settings_builder: Optional[SetupSettingsBuilder],
                                                  os_services: OsServices):
                self.assertIs(os_services, the_os_services, 'os_services')

                self.assertEqual(the_environ, environment.proc_exe_settings.environ,
                                 'proc exe settings/environment')

                self.assertEqual(the_timeout, environment.proc_exe_settings.timeout_in_seconds,
                                 'proc exe settings/timeout')

                self.assertEqual(the_environ, instruction_settings.environ(),
                                 'instruction settings/environment')

                setup_settings_case.expectation.apply_with_message(self, settings_builder,
                                                                   'setup settings passed to main')

            # ACT & ASSERT #
            self._check_source_and_exe_variants(
                ParserThatGives(instruction_embryo_that__setup_phase_aware(
                    main_initial_action=main_action_that_checks_arguments
                )),
                Arrangement.setup_phase_aware(
                    process_execution_settings=ProcessExecutionSettings(the_timeout, the_environ),
                    setup_settings=setup_settings_case.arrangement,
                    os_services=the_os_services,
                ),
                MultiSourceExpectation.setup_phase_aware(
                    setup_settings=asrt.anything_goes(),
                ),
            )
Exemplo n.º 7
0
def dir_partition_cases_for_validation(dst_path_symbol_name: str,
                                       ) -> Sequence[NArrEx[RelativityOptionConfiguration, ValidationAssertions]]:
    return [
        NArrEx(
            DirectoryStructurePartition.HDS.name,
            _relativity_conf_for_symbol(dst_path_symbol_name, RelOptionType.REL_HDS_CASE),
            ValidationAssertions.pre_sds_fails__w_any_msg(),
        ),
        NArrEx(
            DirectoryStructurePartition.NON_HDS.name,
            _relativity_conf_for_symbol(dst_path_symbol_name, RelOptionType.REL_ACT),
            ValidationAssertions.post_sds_fails__w_any_msg(),
        ),
    ]
Exemplo n.º 8
0
 def test_target_is_all_phases_or_non_act(self):
     # ACT & ASSERT #
     phase_spec__to_check_for_modifications = Phase.NON_ACT
     environs_setup = EnvironsSetupForSet(
         the_act=[NameAndValue('act_1', ' value of act_1')],
         non_act=[NameAndValue('non_act_1', ' value of non_act_1')],
     )
     for phase_spec__source in [None, Phase.NON_ACT]:
         var_to_set = NameAndValue('var_to_set', 'value_to_set')
         # ACT & ASSERT #
         CHECKER.check__abs_stx__multi__std_layouts_and_source_variants(
             self,
             SetVariableArgumentsAbsStx.of_nav(
                 var_to_set, phase_spec=phase_spec__source),
             symbol_usages=asrt.is_empty_sequence,
             execution_cases=[
                 NArrEx(
                     arr_.name,
                     arr_.value,
                     environs_setup.expectation_of_addition_to_phase(
                         phase_spec__to_check_for_modifications,
                         var_to_set),
                 ) for arr_ in _arr_for(
                     environs_setup, phase_spec__to_check_for_modifications)
             ],
             sub_test_identifiers={
                 'phase_spec__source': phase_spec__source,
             },
         )
Exemplo n.º 9
0
 def test_translation_of_0_for_non_empty_ranges(self):
     self._check_permutations([
         NArrEx(
             'everything',
             [_from(0)],
             matches_merged_ranges(
                 is_everything=asrt.equals(True)
             ),
         ),
         NArrEx(
             'M:N',
             [_from_to(0, 10)],
             matches_merged_ranges(
                 head=asrt.equals(10)
             ),
         ),
     ])
Exemplo n.º 10
0
def _exe_cases_of_modification(
    before_modification: EnvironsSetup,
    after_modification: EnvironsSetup,
    symbols: Optional[SymbolTable] = None,
) -> Sequence[NArrEx[Arrangement, ExecutionExpectation[None]]]:
    expectation_after_manipulation = expectation(
        non_act=after_modification.as_dict(Phase.NON_ACT),
        the_act=after_modification.as_dict(Phase.ACT),
    )
    return [
        NArrEx(
            'non-act/populated, act/populated',
            arr(
                non_act=before_modification.as_dict(Phase.NON_ACT),
                the_act=before_modification.as_dict(Phase.ACT),
                defaults_getter=get_empty_environ,
                symbols=symbols,
            ),
            expectation_after_manipulation,
        ),
        NArrEx(
            'non-act/populated, act/not populated',
            arr(
                non_act=before_modification.as_dict(Phase.NON_ACT),
                the_act=None,
                defaults_getter=before_modification.
                defaults_getter_with_values(Phase.ACT),
                symbols=symbols,
            ),
            expectation_after_manipulation,
        ),
        NArrEx(
            'non-act/not populated, act/populated',
            arr(
                non_act=None,
                the_act=before_modification.as_dict(Phase.ACT),
                defaults_getter=before_modification.
                defaults_getter_with_values(Phase.NON_ACT),
                symbols=symbols,
            ),
            expectation_after_manipulation,
        ),
    ]
Exemplo n.º 11
0
class TestPositiveIntOnNonModelWMultipleLines(unittest.TestCase):
    ACTUAL_1 = '1st\n'
    ACTUAL_2 = '2nd\n'
    ACTUAL_3 = '3rd\n'
    INPUT_LINES = [ACTUAL_1, ACTUAL_2, ACTUAL_3]
    CASES = [
        NArrEx(
            'outside range - too small',
            0,
            [],
        ),
        NArrEx(
            'in range - 1st',
            1,
            [ACTUAL_1],
        ),
        NArrEx(
            'in range - in middle',
            2,
            [ACTUAL_2],
        ),
        NArrEx(
            'in range - last',
            3,
            [ACTUAL_3],
        ),
        NArrEx(
            'outside range - too large',
            4,
            [],
        ),
    ]

    def test_with_model_access__only_as_lines_is_used(self):
        for case in self.CASES:
            with self.subTest(case.name, range=case.arrangement):
                _check_int_arg__w_max_lines_from_iter(
                    self,
                    case.arrangement,
                    InpExp(self.INPUT_LINES, case.expectation),
                )
Exemplo n.º 12
0
 def test_merging_of__segments(self):
     self._check_permutations([
         NArrEx(
             'overlapping (single)',
             [_from_to(5, 7), _from_to(6, 8)],
             matches_merged_ranges(
                 body=equals_segments([(5, 8)])
             ),
         ),
         NArrEx(
             'overlapping (multiple)',
             [_from_to(5, 7), _from_to(6, 8), _from_to(7, 9)],
             matches_merged_ranges(
                 body=equals_segments([(5, 9)])
             ),
         ),
         NArrEx(
             'adjacent (single)',
             [_from_to(5, 7), _from_to(8, 9)],
             matches_merged_ranges(
                 body=equals_segments([(5, 9)])
             ),
         ),
         NArrEx(
             'adjacent (multiple)',
             [_from_to(5, 7), _single(8), _from_to(9, 10)],
             matches_merged_ranges(
                 body=equals_segments([(5, 10)])
             ),
         ),
         NArrEx(
             'subset (one range contains every other range (singles))',
             [_from_to(3, 7),
              _single(3), _single(4), _single(7)],
             matches_merged_ranges(
                 body=equals_segments([(3, 7)])
             ),
         ),
         NArrEx(
             'subset (one range contains every other range (singles))',
             [_from_to(3, 7),
              _from_to(3, 7), _from_to(3, 4), _from_to(5, 7), _from_to(4, 6)],
             matches_merged_ranges(
                 body=equals_segments([(3, 7)])
             ),
         ),
         NArrEx(
             'subset (merged ranges contains every other range)',
             [_from_to(3, 4), _from_to(5, 7),
              _single(3), _single(7),
              _from_to(3, 4), _from_to(4, 6)],
             matches_merged_ranges(
                 body=equals_segments([(3, 7)])
             ),
         ),
     ])
Exemplo n.º 13
0
def current_line_case_variants_for_grammar(
    expected_expression: ast.Expr,
    grammar: Grammar,
    source_cases: Sequence[SourceCase],
) -> List[NArrEx[Arrangement, Expectation]]:
    ret_val = [
        NArrEx(
            the_source_case.name + ' / must_be_on_current_line=True',
            Arrangement(
                grammar=grammar,
                source=the_source_case.parse_source,
                must_be_on_current_line=True,
            ),
            Expectation(
                expression=expected_expression,
                source=the_source_case.assertion,
            )) for the_source_case in source_cases
    ]

    ret_val += [
        NArrEx(
            the_source_case.name + ' / must_be_on_current_line=False',
            Arrangement(
                grammar=grammar,
                source=the_source_case.parse_source,
                must_be_on_current_line=False,
            ),
            Expectation(
                expression=expected_expression,
                source=the_source_case.assertion,
            )) for the_source_case in source_cases
    ]

    ret_val += [
        for_added_empty_first_line(expected_expression, grammar,
                                   the_source_case)
        for the_source_case in source_cases
    ]

    return ret_val
Exemplo n.º 14
0
    def runTest(self):
        cases = [
            NArrEx(
                'single line (non-empty) ended by new-line',
                ['last\n'],
                ['last'],
            ),
            NArrEx(
                'single line (empty) ended by new-line',
                ['\n'],
                [],
            ),
            NArrEx(
                'non-empty and empty line',
                ['1\n', '\n'],
                ['1'],
            ),
            NArrEx(
                'multiple lines - first non-empty',
                ['1\n', '\n', '\n'],
                ['1'],
            ),
            NArrEx(
                'multiple lines - every line empty',
                ['\n', '\n', '\n'],
                [],
            ),
            NArrEx(
                'multiple lines - empty sequence before non-empty contents - ended by new-line',
                ['\n', '\n', 'non-empty\n'],
                ['non-empty'],
            ),
            NArrEx(
                'multiple lines - empty sequence before non-empty contents - ended sequence of empty lines',
                ['\n', '\n', 'non-empty\n', '\n', '\n'],
                ['non-empty'],
            ),
            NArrEx(
                'multiple lines - empty before and after, non-empty-line has space around',
                ['\n', '\n', '  non-empty  \n', '\n', '\n'],
                ['non-empty'],
            ),
        ]

        # ARRANGE #
        for case in cases:
            with self.subTest(case.name):
                # ACT & ASSERT #
                _check(self, case.arrangement, case.expectation)
Exemplo n.º 15
0
 def runTest(self):
     self._check_cases([
         NArrEx('empty', sm_args.Empty(),
                asrt_interval.matches_unlimited()),
         NArrEx(
             'conjunction',
             arg_rend.within_paren(
                 arg_rend.conjunction([
                     sm_args.Empty(),
                     sm_args.Equals(FileOrString.of_string('expected')),
                 ])), asrt_interval.matches_unlimited()),
         NArrEx('negation',
                arg_rend.within_paren(arg_rend.negation(sm_args.Empty())),
                asrt_interval.matches_unlimited()),
         NArrEx(
             'constant False'
             '(currently not able to derive interval from contents - '
             'would like this to become the empty interval)',
             arg_rend.constant(False), asrt_interval.matches_unlimited()),
         NArrEx('constant False', arg_rend.constant(True),
                asrt_interval.matches_unlimited()),
     ])
Exemplo n.º 16
0
    def runTest(self):
        # ARRANGE #
        cases = [
            NArrEx(
                'layout spec w optional-new line as empty',
                LAYOUT_SPEC__OPTIONAL_NEW_LINE_AS_EMPTY,
                '',
            ),
            NArrEx(
                'layout spec w optional new-line as new-line',
                LAYOUT_SPEC__OPTIONAL_NEW_LINE_AS_NEW_LINE,
                '\n',
            ),
        ]

        tok_seq = TokenSequence.optional_new_line()
        for case in cases:
            with self.subTest(case.name):
                # ACT #
                actual = tok_seq.layout(case.arrangement)
                # ASSERT #
                self.assertEqual(case.expectation, actual)
Exemplo n.º 17
0
 def runTest(self):
     # ARRANGE #
     cases = [
         NArrEx(
             'pre SDS validation failure SHOULD cause validation error',
             RelOptionType.REL_HDS_CASE,
             MultiSourceExpectation.phase_agnostic(
                 validation=ValidationAssertions.pre_sds_fails__w_any_msg()
             ),
         ),
         NArrEx(
             'post SDS validation failure SHOULD cause main error',
             RelOptionType.REL_ACT,
             MultiSourceExpectation.phase_agnostic(
                 validation=ValidationAssertions.post_sds_fails__w_any_msg()
             ),
         ),
     ]
     for case in cases:
         program_with_ref_to_non_existing_file = program_abs_stx.ProgramOfExecutableFileCommandLineAbsStx(
             path_abs_stx.RelOptPathAbsStx(case.arrangement, 'non-existing-file')
         )
         instruction_syntax = instr_abs_stx.create_w_explicit_contents(
             path_abs_stx.DefaultRelPathAbsStx('dst-file'),
             string_source_abs_stx.StringSourceOfProgramAbsStx(ProcOutputFile.STDOUT,
                                                               program_with_ref_to_non_existing_file,
                                                               ignore_exit_code=False)
         )
         # ACT & ASSERT #
         for phase_is_after_act in [False, True]:
             checker = integration_check.checker(phase_is_after_act)
             with self.subTest(phase_is_after_act=phase_is_after_act,
                               step=case.name):
                 checker.check__abs_stx__std_layouts_and_source_variants(
                     self,
                     instruction_syntax,
                     Arrangement.phase_agnostic(),
                     case.expectation,
                 )
Exemplo n.º 18
0
    def test_successful_parse_with_infix_op_expressions(self):
        s = ast.PrimitiveSansArg()
        cases = [
            NArrEx(
                'prefix operator binds to following primitive expression (single infix ops)',
                Arrangement(
                    grammar=ast.GRAMMAR_WITH_ALL_COMPONENTS,
                    source=remaining_source('{p_op} {s}  {bin_op}  {s}  {bin_op}  {p_op} {s}'.format(
                        s=ast.PRIMITIVE_SANS_ARG,
                        p_op=ast.PREFIX_P,
                        bin_op=ast.INFIX_OP_A,
                    )),
                ),
                Expectation(
                    expression=InfixOpA([PrefixOpExprP(s), s, PrefixOpExprP(s)]),
                    source=asrt_source.is_at_end_of_line(1),
                ),
            ),
            NArrEx(
                'prefix operator binds to following primitive expression (different infix ops)',
                Arrangement(
                    grammar=ast.GRAMMAR_WITH_ALL_COMPONENTS,
                    source=remaining_source('{p_op} {s}  {bin_op_a}  {s}  {bin_op_b}  {p_op} {s}'.format(
                        s=ast.PRIMITIVE_SANS_ARG,
                        p_op=ast.PREFIX_P,
                        bin_op_a=ast.INFIX_OP_A,
                        bin_op_b=ast.INFIX_OP_B_THAT_IS_NOT_A_VALID_SYMBOL_NAME,
                    )),
                ),
                Expectation(
                    expression=InfixOpB([InfixOpA([PrefixOpExprP(s), s]), PrefixOpExprP(s)]),
                    source=asrt_source.is_at_end_of_line(1),
                ),
            ),
        ]
        # ACT & ASSERT #

        parse_check.check__multi(self, PARSER_MAKER_OF_FULL_EXPR_PARSER, cases)
Exemplo n.º 19
0
 def test_single_range(self):
     self._check_permutations([
         NArrEx(
             'no upper limits',
             [_single(3)],
             matches_merged_ranges(
                 head=asrt.is_none,
                 body=equals_segments([(3, 3)]),
             ),
         ),
         NArrEx(
             'single upper limit',
             [_to(5)],
             matches_merged_ranges(
                 head=asrt.equals(5),
             ),
         ),
         NArrEx(
             'single upper limit, and segment above',
             [_from(7)],
             matches_merged_ranges(
                 tail=asrt.equals(7),
             ),
         ),
         NArrEx(
             'multiple upper limits',
             [_from_to(13, 19)],
             matches_merged_ranges(
                 body=equals_segments([(13, 19)]),
             ),
         ),
         NArrEx(
             'single value 1 should become head',
             [_single(1)],
             matches_merged_ranges(
                 head=asrt.equals(1),
             ),
         ),
         NArrEx(
             'from-to starting at 1 should become head (upper bound 1)',
             [_from_to(1, 1)],
             matches_merged_ranges(
                 head=asrt.equals(1),
             ),
         ),
         NArrEx(
             'from-to starting at 1 should become head (upper bound > 1)',
             [_from_to(1, 2)],
             matches_merged_ranges(
                 head=asrt.equals(2),
             ),
         ),
     ])
Exemplo n.º 20
0
def _exe_cases_for_unmodified(
    setup: EnvironsSetup,
    phase: Phase,
) -> Sequence[NArrEx[Arrangement, ExecutionExpectation[None]]]:
    return [
        NArrEx(
            'environ/existing (not None)',
            arr(
                setup.as_dict(phase),
                default_environ_getter=get_empty_environ,
            ),
            expectation(setup.as_dict(phase)),
        ),
        NArrEx(
            'environ/non-existing None)',
            arr(
                None,
                default_environ_getter=setup.defaults_getter_with_values(
                    phase),
            ),
            expectation(None),
        ),
    ]
Exemplo n.º 21
0
 def runTest(self):
     # ARRANGE #
     cases = [
         NArrEx(
             'single empty line',
             ['\n', 'end'],
             ['end'],
         ),
         NArrEx(
             'single line with space',
             ['  \n', 'end'],
             ['end'],
         ),
         NArrEx(
             'single line with space (tab)',
             ['\t\n', 'end'],
             ['end'],
         ),
         NArrEx(
             'multiple empty lines',
             ['\n', '\n', '\n', 'end'],
             ['end'],
         ),
         NArrEx(
             'leading just-space lines and just-space lines in the middle',
             ['\n', '  \n', 'middle\n', '\n', ' \n', 'end'],
             ['middle\n', '\n', ' \n', 'end'],
         ),
     ]
     for case in cases:
         with self.subTest(case.name):
             # ACT & ASSERT #
             _check(
                 self,
                 case.arrangement,
                 case.expectation,
             )
Exemplo n.º 22
0
    def runTest(self):
        # ARRANGE #
        dst_file = PathArgumentWithRelativity(
            'dst-file.txt', conf_rel_any(RelOptionType.REL_TMP))

        cases = [
            NArrEx(
                'pre sds validation failure SHOULD cause validation error',
                RelOptionType.REL_HDS_CASE,
                self.conf.expect_failing_validation_pre_sds(),
            ),
            NArrEx(
                'post sds validation failure SHOULD cause main hard error',
                RelOptionType.REL_ACT,
                self.conf.expect_hard_error_of_main__any(),
            ),
        ]
        for case in cases:
            src_file_rel_conf = conf_rel_any(case.arrangement)
            instruction_syntax = instr_abs_stx.create_w_explicit_contents(
                dst_file.argument_abs_stx,
                string_source_abs_stx.StringSourceOfFileAbsStx(
                    src_file_rel_conf.path_abs_stx_of_name(
                        'non-existing-source-file.txt')),
            )

            for source_case in equivalent_source_variants__with_source_check__consume_last_line__abs_stx(
                    instruction_syntax):
                with self.subTest(validation_case=case.name,
                                  source_case=source_case.name):
                    # ACT & ASSERT#
                    self.conf.run_test(
                        self,
                        source_case.value.source,
                        arrangement=self.conf.arrangement(),
                        expectation=case.expectation,
                    )
Exemplo n.º 23
0
 def test_merging_of__all_ranges_to_become_all_elements(self):
     self._check_permutations([
         NArrEx(
             '1:',
             [_from(1)],
             matches_merged_ranges(
                 is_everything=asrt.equals(True),
             ),
         ),
         NArrEx(
             ':N N: (overlapping)',
             [_to(7), _from(7)],
             matches_merged_ranges(
                 is_everything=asrt.equals(True),
             ),
         ),
         NArrEx(
             ':N (N+1): (adjacent)',
             [_to(7), _from(8)],
             matches_merged_ranges(
                 is_everything=asrt.equals(True),
             ),
         ),
         NArrEx(
             '1:N N: (overlapping)',
             [_from_to(1, 7), _from(7)],
             matches_merged_ranges(
                 is_everything=asrt.equals(True),
             ),
         ),
         NArrEx(
             '1:N (N+1): (adjacent)',
             [_from_to(1, 7), _from(8)],
             matches_merged_ranges(
                 is_everything=asrt.equals(True),
             ),
         ),
         NArrEx(
             'head and tail merged with segments (overlapping)',
             [_to(3), _from_to(3, 12), _from(12)],
             matches_merged_ranges(
                 is_everything=asrt.equals(True),
             ),
         ),
         NArrEx(
             'head and tail merged with segments (adjacent)',
             [_to(3), _from_to(4, 11), _from(12)],
             matches_merged_ranges(
                 is_everything=asrt.equals(True),
             ),
         ),
     ])
Exemplo n.º 24
0
 def test_removal_of_emtpy_segments(self):
     self._check_permutations([
         NArrEx(
             'only empty ranges, involving 0 (multiple)',
             [_single(0), _to(0), _from_to(0, 0), _from_to(1, 0)],
             matches_merged_ranges(
                 is_empty=asrt.equals(True)
             ),
         ),
         NArrEx(
             'only empty ranges (single)',
             [_from_to(3, 2)],
             matches_merged_ranges(
                 is_empty=asrt.equals(True)
             ),
         ),
         NArrEx(
             'only empty ranges (multiple)',
             [_from_to(3, 2), _from_to(7, 2)],
             matches_merged_ranges(
                 is_empty=asrt.equals(True)
             ),
         ),
         NArrEx(
             'empty and non-empty ranges (from-to)',
             [_from_to(3, 2), _from_to(2, 7)],
             matches_merged_ranges(
                 body=equals_segments([(2, 7)]),
             ),
         ),
         NArrEx(
             'empty and non-empty ranges (single)',
             [_from_to(3, 2), _single(2)],
             matches_merged_ranges(
                 body=equals_segments([(2, 2)]),
             ),
         ),
         NArrEx(
             'empty and non-empty ranges (first-to)',
             [_from_to(3, 2), _to(2)],
             matches_merged_ranges(
                 head=asrt.equals(2),
             ),
         ),
         NArrEx(
             'empty and non-empty ranges (last-from)',
             [_from_to(3, 2), _from(2)],
             matches_merged_ranges(
                 tail=asrt.equals(2)
             ),
         ),
     ])
Exemplo n.º 25
0
class TestNegativeIntOnNonModelWMultipleLines(unittest.TestCase):
    actual_1 = '1st\n'
    actual_2 = '2nd\n'
    actual_3 = '3rd\n'
    INPUT_LINES = [actual_1, actual_2, actual_3]
    CASES = [
        NArrEx(
            'in range - last',
            -1,
            [actual_3],
        ),
        NArrEx(
            'in range - in middle',
            -2,
            [actual_2],
        ),
        NArrEx(
            'in range - first',
            -3,
            [actual_1],
        ),
        NArrEx(
            'outside range - too small',
            -4,
            [],
        ),
    ]

    def test_with_model_access__only_as_lines_is_used(self):
        for case in self.CASES:
            with self.subTest(case.name, range=case.arrangement):
                _check_int_arg__wo_max_lines_from_iter(
                    self,
                    case.arrangement,
                    InpExp(self.INPUT_LINES, case.expectation),
                )
Exemplo n.º 26
0
def for_added_empty_first_line(
        expected_expression: ast.Expr, the_grammar: Grammar,
        src_case: SourceCase) -> NArrEx[Arrangement, Expectation]:
    case_for_empty_first_line = src_case.for_added_empty_first_line()
    return NArrEx(
        case_for_empty_first_line.name + ' / must_be_on_current_line=False',
        Arrangement(
            grammar=the_grammar,
            source=case_for_empty_first_line.parse_source,
            must_be_on_current_line=False,
        ),
        Expectation(
            expression=expected_expression,
            source=case_for_empty_first_line.assertion,
        ))
Exemplo n.º 27
0
    def test_assertion_on_setup_settings(self):
        # ARRANGE #
        environ__actual = {'actual_var': 'actual value'}
        environ__expected = {}
        the_setup_settings = SetupSettingsArr(environ=environ__actual)

        setup_settings_cases = [
            NArrEx(
                'none',
                None,
                asrt.is_not_none,
            ),
            NArrEx(
                'not none',
                the_setup_settings,
                asrt_settings_builder.matches(
                    environ=asrt.equals(environ__expected),
                    stdin=asrt.is_none,
                ),
            ),
        ]

        for setup_settings_case in setup_settings_cases:
            # ACT & ASSERT #
            self._check_source_and_exe_variants__failing_assertions(
                ParserThatGives(instruction_embryo_that__setup_phase_aware()),
                Arrangement.setup_phase_aware(
                    setup_settings=setup_settings_case.arrangement,
                ),
                MultiSourceExpectation.setup_phase_aware(
                    setup_settings=setup_settings_case.expectation,
                ),
                sub_test_identifiers={
                    'setup_settings': setup_settings_case.name,
                },
            )
Exemplo n.º 28
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.º 29
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.º 30
0
 def runTest(self):
     self._check_cases([
         NArrEx('equals (within line-num-range)',
                im_args.comparison2(comparators.EQ, 2),
                asrt_interval.matches_point(2)),
         NArrEx('equals (outside line-num-range)',
                im_args.comparison2(comparators.EQ, -2),
                asrt_interval.matches_empty()),
         NArrEx('greater-than (within line-num-range)',
                im_args.comparison2(comparators.GT, 7),
                asrt_interval.matches_lower_limit(7 + 1)),
         NArrEx('greater-than (outside line-num-range)',
                im_args.comparison2(comparators.GTE, -7),
                asrt_interval.matches_unlimited()),
         NArrEx('greater-than-eq (FIRST-LINE-NUMBER)',
                im_args.comparison2(comparators.GTE, FIRST_LINE_NUMBER),
                asrt_interval.matches_unlimited()),
         NArrEx(
             'greater-than && less-than (within line-num-range)',
             arg_rend.within_paren(
                 arg_rend.conjunction([
                     im_args.comparison2(comparators.GT, 7),
                     im_args.comparison2(comparators.LTE, 12),
                 ])), asrt_interval.matches_finite(7 + 1, 12)),
         NArrEx(
             'greater-than && less-than (outside line-num-range)',
             arg_rend.within_paren(
                 arg_rend.conjunction([
                     im_args.comparison2(comparators.GT, -7),
                     im_args.comparison2(comparators.LTE, 12),
                 ])), asrt_interval.matches_upper_limit(12)),
         NArrEx('constant False', arg_rend.constant(False),
                asrt_interval.matches_empty()),
         NArrEx('constant False', arg_rend.constant(True),
                asrt_interval.matches_unlimited()),
     ])