Пример #1
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,
             },
         )
Пример #2
0
    def test_target_is_all_phases(self):
        # ACT & ASSERT #
        setup = self.ENVIRONS_SETUP__DIFFERENT
        identical_setup = self.ENVIRONS_SETUP__IDENTICAL
        var_to_set = self.VAR_TO_SET

        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_addition_to_phase_all(var_to_set),
            ),
            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_addition_to_phase_all(var_to_set),
            ),
            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_addition_to_phase_all(var_to_set),
            ),
            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_addition_to_phase_all(
                    var_to_set),
            ),
        ]
        # ACT & ASSERT #
        CHECKER.check__abs_stx__multi__std_layouts_and_source_variants(
            self,
            SetVariableArgumentsAbsStx.of_nav(var_to_set, phase_spec=None),
            symbol_usages=asrt.is_empty_sequence,
            execution_cases=all_execution_cases,
        )
Пример #3
0
    def test_constant_string_value__current_is_not_none(self):
        # ACT & ASSERT #
        var = NameAndValue('name', 'value')

        CHECKER.check__abs_stx__std_layouts_and_source_variants(
            self, SetVariableArgumentsAbsStx.of_nav(var, phase_spec=None),
            Arrangement.setup_phase_aware(
                process_execution_settings=proc_exe_env_for_test(environ={})),
            MultiSourceExpectation.setup_phase_aware(
                main_result=asrt.is_none,
                main_side_effect_on_environment_variables=asrt.equals(
                    {var.name: var.value})))
Пример #4
0
 def _check_modification_of_single_phase(
         self, phase_to_modify: Phase, var_to_set: EnvVar,
         execution_cases: ExeCasesForContentsOfOtherGetter,
         contents_of_non_checked_phase__populated: EnvVarDict):
     # ARRANGE #
     all_execution_cases = (
         execution_cases(contents_of_non_checked_phase__populated) +
         execution_cases(None))
     # ACT & ASSERT #
     CHECKER.check__abs_stx__multi__std_layouts_and_source_variants(
         self,
         SetVariableArgumentsAbsStx.of_nav(var_to_set,
                                           phase_spec=phase_to_modify),
         symbol_usages=asrt.is_empty_sequence,
         execution_cases=all_execution_cases,
     )
Пример #5
0
    def runTest(self):
        # ARRANGE #
        var_val = NameAndValue('name', 'value')
        instruction_argument = SetVariableArgumentsAbsStx.of_nav(
            var_val, phase_spec=Phase.ACT)
        expected_environ = {}

        empty_environ = {}

        def mk_arrangement():
            return self.conf.arrangement(environ=dict(empty_environ))

        # ACT & ASSERT #
        self.conf.instruction_checker.check_parsing__abs_stx(
            self, self.conf.parser(), instruction_argument, mk_arrangement,
            self.conf.expect_success(instruction_settings=asrt_is.matches(
                environ=asrt.equals(expected_environ))))
Пример #6
0
    def test_target_is_act(self):
        # ACT & ASSERT #
        phase_spec__source = Phase.ACT
        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')],
        )

        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=_exe_cases_for_unmodified(
                environs_setup, phase_spec__to_check_for_modifications),
        )
Пример #7
0
    def test_current_environ_is_none(self):
        # ACT & ASSERT #
        var_in_default = NameAndValue('var_in_default',
                                      'value of var in default')

        def get_default_environ() -> Dict[str, str]:
            return NameAndValue.as_dict([var_in_default])

        var_to_set = NameAndValue('var_to_set', 'value')

        CHECKER.check__abs_stx__std_layouts_and_source_variants(
            self, SetVariableArgumentsAbsStx.of_nav(var_to_set,
                                                    phase_spec=None),
            Arrangement.setup_phase_aware(
                process_execution_settings=proc_exe_env_for_test(environ=None),
                default_environ_getter=get_default_environ,
            ),
            MultiSourceExpectation.setup_phase_aware(
                main_result=asrt.is_none,
                main_side_effect_on_environment_variables=asrt.equals(
                    NameAndValue.as_dict([var_in_default, var_to_set]))))
Пример #8
0
    def runTest(self):
        # ARRANGE #
        var_val = NameAndValue('name', 'value')
        instruction_argument = SetVariableArgumentsAbsStx.of_nav(
            var_val, phase_spec=Phase.ACT)
        expected_environ = {var_val.name: var_val.value}

        env_before_modification = {}

        # ACT & ASSERT #
        CHECKER.check_multi_source__abs_stx(
            self,
            instruction_argument,
            arr(
                env_before_modification,
                env_before_modification,
            ),
            expect(
                instruction_settings=env_before_modification,
                setup_settings=expected_environ,
            ),
        )
Пример #9
0
    def test_reference_should_be_resolved_in_manipulated_phase(self):
        common_var_name = 'existing_in_both_act_and_non_act'

        new_var_to_set = NameAndValue('name_of_var_to_set',
                                      env_var_ref_syntax(common_var_name))

        common_var_value = {
            Phase.NON_ACT: 'value of common var in non act',
            Phase.ACT: 'value of common var in act',
        }

        before_modification = EnvironsSetupForSet(
            non_act=[
                NameAndValue(common_var_name, common_var_value[Phase.NON_ACT]),
                NameAndValue('only_in_non_act',
                             'value of var only in non-act'),
            ],
            the_act=[
                NameAndValue(common_var_name, common_var_value[Phase.ACT]),
                NameAndValue('only_in_act', 'value of var only in act'),
            ],
        )
        after_modification = before_modification.new_with_added(
            non_act=NameAndValue(new_var_to_set.name,
                                 common_var_value[Phase.NON_ACT]),
            the_act=NameAndValue(new_var_to_set.name,
                                 common_var_value[Phase.ACT]),
        )
        all_execution_cases = _exe_cases_of_modification(
            before_modification, after_modification)
        # ACT & ASSERT #
        CHECKER.check__abs_stx__multi__std_layouts_and_source_variants(
            self,
            SetVariableArgumentsAbsStx.of_nav(new_var_to_set, phase_spec=None),
            symbol_usages=asrt.is_empty_sequence,
            execution_cases=all_execution_cases,
        )
Пример #10
0
    def runTest(self):
        # ARRANGE #
        var_in_default = NameAndValue('var_in_default',
                                      'value of var in default')
        var_to_set = NameAndValue('var_to_set', 'value')
        expected_environ = NameAndValue.as_dict([var_in_default, var_to_set])

        def get_default_environ() -> Dict[str, str]:
            return NameAndValue.as_dict([var_in_default])

        instruction_argument = SetVariableArgumentsAbsStx.of_nav(
            var_to_set, phase_spec=None)

        def mk_arrangement():
            return self.conf.arrangement(
                environ=None,
                default_environ_getter=get_default_environ,
            )

        # ACT & ASSERT #
        self.conf.instruction_checker.check_parsing__abs_stx(
            self, self.conf.parser(), instruction_argument, mk_arrangement,
            self.conf.expect_success(instruction_settings=asrt_is.matches(
                environ=asrt.equals(expected_environ))))
Пример #11
0
    def test_reference_should_be_resolved_in_the_manipulated_phase(self):
        existing_var = NameAndValue('existing_name', 'value of existing')
        new_var_to_set_w_ref = NameAndValue(
            'name_of_var_to_set', env_var_ref_syntax(existing_var.name))

        vars_before = [existing_var]
        execution_cases = _exe_cases_of_modification(
            before_modification=vars_before,
            after_modification=[
                existing_var,
                NameAndValue(new_var_to_set_w_ref.name, existing_var.value)
            ])
        # ACT & ASSERT #
        for phase_spec__source in [None, Phase.NON_ACT]:
            CHECKER.check__abs_stx__multi__std_layouts_and_source_variants(
                self,
                SetVariableArgumentsAbsStx.of_nav(
                    new_var_to_set_w_ref, phase_spec=phase_spec__source),
                symbol_usages=asrt.is_empty_sequence,
                execution_cases=execution_cases,
                sub_test_identifiers={
                    'phase_spec__source': phase_spec__source,
                },
            )