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, ), ]
def test_existing_variable(self): var_a = NameAndValue('a', 'A') var_b = NameAndValue('b', 'B') environ__before = NameAndValue.as_dict([var_a, var_b]) environ__after = NameAndValue.as_dict([var_b]) CHECKER.check__abs_stx__std_layouts_and_source_variants( self, UnsetVariableArgumentsAbsStx.of_str(var_a.name, phase_spec=None), Arrangement.setup_phase_aware( process_execution_settings=ProcessExecutionSettings. with_environ(environ__before), ), MultiSourceExpectation.setup_phase_aware( main_side_effect_on_environment_variables=asrt.equals( environ__after), ))
def runTest(self): # ARRANGE # var_to_unset = NameAndValue('var_to_unset', 'value of var to unset') other_var = NameAndValue('other_var', 'val of other var') instruction_argument = UnsetVariableArgumentsAbsStx.of_str( var_to_unset.name, phase_spec=None) vars_from_defaults_getter = [var_to_unset, other_var] environ_wo_var_to_unset = NameAndValue.as_dict([other_var]) def get_default_environ() -> Dict[str, str]: return NameAndValue.as_dict(vars_from_defaults_getter) 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(environ_wo_var_to_unset))))
def test_WHEN_var_name_is_not_an_existing_env_var_THEN_env_SHOULD_be_unmodified( self): non_existing_var_name = 'non_existing' existing_var = NameAndValue('existing', 'EXISTING') environ__before = NameAndValue.as_dict([existing_var]) environ__after = NameAndValue.as_dict([existing_var]) CHECKER.check__abs_stx__std_layouts_and_source_variants( self, UnsetVariableArgumentsAbsStx.of_str(non_existing_var_name, phase_spec=None), Arrangement.setup_phase_aware( process_execution_settings=ProcessExecutionSettings. with_environ(environ__before), ), MultiSourceExpectation.setup_phase_aware( main_side_effect_on_environment_variables=asrt.equals( environ__after), ))
def test_current_environ_is_none(self): var_a = NameAndValue('a', 'A') var_b = NameAndValue('b', 'B') environ__before = NameAndValue.as_dict([var_a, var_b]) environ__after = NameAndValue.as_dict([var_b]) def get_default_environ() -> Dict[str, str]: return dict(environ__before) CHECKER.check__abs_stx__std_layouts_and_source_variants( self, UnsetVariableArgumentsAbsStx.of_str(var_a.name, 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_side_effect_on_environment_variables=asrt.equals( environ__after), ))
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]))))
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))))
def with_added__as_dict(self, phase: Phase, additional: EnvVar) -> EnvVarDict: return NameAndValue.as_dict(self.with_added(phase, additional))
def ret_val() -> EnvVarDict: return NameAndValue.as_dict(environ)
def as_dict(self, phase: Phase) -> EnvVarDict: return NameAndValue.as_dict(self.env_vars(phase))
def get_default_environ() -> Dict[str, str]: return NameAndValue.as_dict([var_in_default])
def get_default_environ() -> Dict[str, str]: return NameAndValue.as_dict(vars_from_defaults_getter)