Ejemplo n.º 1
0
    def test_set_value_that_references_an_env_var(self):
        # ARRANGE #

        existing_env_var = NameAndValue('MY_VAR', 'MY_VAL')
        defined_env_var = NameAndValue('name', existing_env_var.value)

        environ__before = {
            existing_env_var.name: existing_env_var.value,
        }
        environ__after = {
            defined_env_var.name: defined_env_var.value,
            existing_env_var.name: existing_env_var.value,
        }

        # ACT & ASSERT #

        CHECKER.check__abs_stx__std_layouts_and_source_variants(
            self,
            SetVariableArgumentsAbsStx.of_str(defined_env_var.name,
                                              env_var_ref_syntax(
                                                  existing_env_var.name),
                                              phase_spec=None),
            arrangement=Arrangement.setup_phase_aware(
                process_execution_settings=ProcessExecutionSettings.
                with_environ(environ__before), ),
            expectation=MultiSourceExpectation.setup_phase_aware(
                main_side_effect_on_environment_variables=asrt.equals(
                    environ__after), ))
Ejemplo n.º 2
0
    def test_a_references_to_a_non_existing_env_var_SHOULD_be_replaced_with_empty_string(
            self):
        # ARRANGE #
        existing_var = NameAndValue('existing', 'EXISTING')
        non_existing_var__name = 'non_existing'
        new_var_to_set__name = 'new_var_to_set'

        source = SetVariableArgumentsAbsStx.of_str(
            new_var_to_set__name,
            env_var_ref_syntax(non_existing_var__name),
            phase_spec=None,
        )
        # ACT & ASSERT #

        CHECKER.check__abs_stx__std_layouts_and_source_variants(
            self, source,
            Arrangement.setup_phase_aware(
                process_execution_settings=proc_exe_env_for_test(
                    environ={existing_var.name: existing_var.value})),
            MultiSourceExpectation.setup_phase_aware(
                main_result=asrt.is_none,
                main_side_effect_on_environment_variables=asrt.equals({
                    existing_var.name:
                    existing_var.value,
                    new_var_to_set__name:
                    '',
                })))
Ejemplo n.º 3
0
    def test_value_SHOULD_be_able_to_have_symbol_references(self):
        # ARRANGE #

        variable_name = 'variable_to_assign'

        my_symbol = StringConstantSymbolContext('my_symbol', 'my symbol value')
        your_symbol = StringConstantSymbolContext('your_symbol',
                                                  'your symbol value')

        value_template = 'pre {MY_SYMBOL} {YOUR_SYMBOL} post'

        expected_evaluated_value_string = value_template.format(
            MY_SYMBOL=my_symbol.str_value,
            YOUR_SYMBOL=your_symbol.str_value,
        )
        expected_environ_after_main = {
            variable_name: expected_evaluated_value_string,
        }
        value_source_string = value_template.format(
            MY_SYMBOL=symbol_reference_syntax_for_name(my_symbol.name),
            YOUR_SYMBOL=symbol_reference_syntax_for_name(your_symbol.name),
        )

        source_syntax = SetVariableArgumentsAbsStx.of_str(
            variable_name,
            value_source_string,
            phase_spec=None,
            quoting=QuoteType.SOFT)

        # ACT & ASSERT #

        CHECKER.check__abs_stx__std_layouts_and_source_variants(
            self,
            source_syntax,
            Arrangement.setup_phase_aware(
                symbols=SymbolContext.symbol_table_of_contexts(
                    [my_symbol, your_symbol]),
                process_execution_settings=ProcessExecutionSettings.
                with_environ({}),
            ),
            MultiSourceExpectation.setup_phase_aware(
                main_side_effect_on_environment_variables=asrt.equals(
                    expected_environ_after_main),
                symbol_usages=asrt.matches_sequence([
                    my_symbol.usage_assertion__w_str_rendering,
                    your_symbol.usage_assertion__w_str_rendering,
                ]),
            ),
        )
Ejemplo n.º 4
0
    def test_set_value_that_contains_text_and_references_to_env_vars(self):
        # ARRANGE #

        my_var = NameAndValue('MY_VAR', 'MY_VAL')
        your_var = NameAndValue('YOUR_VAR', 'YOUR_VAL')
        var_to_set_name = 'name'

        value_template = 'pre {my_var} {your_var} post'

        source = SetVariableArgumentsAbsStx.of_str(
            var_to_set_name,
            value_template.format(
                my_var=env_var_ref_syntax(my_var.name),
                your_var=env_var_ref_syntax(your_var.name),
            ),
            phase_spec=None,
            quoting=QuoteType.SOFT,
        )

        expected_value = value_template.format(
            my_var=my_var.value,
            your_var=your_var.value,
        )

        environ__before = {
            my_var.name: my_var.value,
            your_var.name: your_var.value,
        }

        expected_environ__after = {
            var_to_set_name: expected_value,
            my_var.name: my_var.value,
            your_var.name: your_var.value,
        }

        # ACT & ASSERT #

        CHECKER.check__abs_stx__std_layouts_and_source_variants(
            self,
            source,
            arrangement=Arrangement.setup_phase_aware(
                process_execution_settings=ProcessExecutionSettings.
                with_environ(environ__before), ),
            expectation=MultiSourceExpectation.setup_phase_aware(
                main_side_effect_on_environment_variables=asrt.equals(
                    expected_environ__after), ))
Ejemplo n.º 5
0
    def test_multi_line_value(self):
        # ARRANGE #
        var = NameAndValue('name', 'a\nmulti\nline\nvalue\n')
        environ__before = {}
        environ__after = {var.name: var.value}

        # ACT & ASSERT #
        CHECKER.check__abs_stx__std_layouts_and_source_variants(
            self,
            SetVariableArgumentsAbsStx.of_str(var.name,
                                              var.value,
                                              phase_spec=None,
                                              quoting=QuoteType.HARD),
            Arrangement.setup_phase_aware(
                process_execution_settings=proc_exe_env_for_test(
                    environ=environ__before)),
            MultiSourceExpectation.setup_phase_aware(
                main_result=asrt.is_none,
                main_side_effect_on_environment_variables=asrt.equals(
                    environ__after)))
Ejemplo n.º 6
0
    def test_value_with_hard_quoted_value_SHOULD_skip_symbol_substitution(
            self):
        # ARRANGE #

        variable_name = 'variable_to_assign'

        my_symbol = NameAndValue('my_symbol', 'my symbol value')
        your_symbol = NameAndValue('your_symbol', 'your symbol value')

        value_template = 'pre {MY_SYMBOL} {YOUR_SYMBOL} post'

        value_source_string = value_template.format(
            MY_SYMBOL=symbol_reference_syntax_for_name(my_symbol.name),
            YOUR_SYMBOL=symbol_reference_syntax_for_name(your_symbol.name),
        )

        expected_environ_after_main = {
            variable_name: value_source_string,
        }

        source_syntax = SetVariableArgumentsAbsStx.of_str(
            variable_name,
            value_source_string,
            phase_spec=None,
            quoting=QuoteType.HARD)

        # ACT & ASSERT #

        CHECKER.check__abs_stx__std_layouts_and_source_variants(
            self,
            source_syntax,
            Arrangement.setup_phase_aware(
                process_execution_settings=ProcessExecutionSettings.
                with_environ({}), ),
            MultiSourceExpectation.setup_phase_aware(
                main_side_effect_on_environment_variables=asrt.equals(
                    expected_environ_after_main),
                symbol_usages=asrt.matches_sequence([]),
            ),
        )
Ejemplo n.º 7
0
    def test_WHEN_env_contains_the_var_being_set_THEN_its_value_SHOULD_be_replaced(
            self):
        # ACT & ASSERT #
        var_name = 'ENV_VAR'
        value_before = 'before'
        value_after = 'after'

        environ__before = {var_name: value_before}

        environ__after = {var_name: value_after}

        CHECKER.check__abs_stx__std_layouts_and_source_variants(
            self,
            SetVariableArgumentsAbsStx.of_str(var_name,
                                              value_after,
                                              phase_spec=None),
            Arrangement.setup_phase_aware(
                process_execution_settings=proc_exe_env_for_test(
                    environ=environ__before)),
            MultiSourceExpectation.setup_phase_aware(
                main_result=asrt.is_none,
                main_side_effect_on_environment_variables=asrt.equals(
                    environ__after)))