Esempio n. 1
0
 def test_not_equals(self):
     string_symbol = StringConstantSymbolContext('string_symbol_name',
                                                 'string symbol value')
     cases = [
         Case('different number of elements',
              expected=
              list_sdvs.empty(),
              actual=
              list_sdvs.from_str_constants(['value']),
              ),
         Case('different value of single string',
              expected=
              list_sdvs.from_str_constants(['expected value']),
              actual=
              list_sdvs.from_str_constants(['actual value']),
              ),
         Case('different element types, but same resolved value',
              expected=
              list_sdvs.from_str_constants([string_symbol.str_value]),
              actual=
              list_sdvs.from_elements([list_sdvs.symbol_element(string_symbol.reference__w_str_rendering)]),
              symbols=
              string_symbol.symbol_table,
              ),
     ]
     for case in cases:
         with self.subTest(msg=case.name):
             assertion = sut.equals_list_sdv(case.expected, case.symbols)
             assert_that_assertion_fails(assertion, case.actual)
    def _check(
        self,
        command_driver: CommandDriverSdvCase,
        arguments_of_referenced_command: List[str],
        accumulated_arguments_of_referenced_program: List[str],
        additional_argument: List[str],
    ):
        # ARRANGE #
        all_arguments = (arguments_of_referenced_command +
                         accumulated_arguments_of_referenced_program +
                         additional_argument)

        def expected_program(
                env: AssertionResolvingEnvironment) -> Assertion[Program]:
            return asrt_pgm_val.matches_program(
                asrt_command.matches_command(
                    driver=command_driver.expected_command_driver(env),
                    arguments=asrt.equals(all_arguments)),
                stdin=asrt_pgm_val.is_no_stdin(),
                transformer=asrt_pgm_val.is_no_transformation(),
            )

        referenced_program_symbol = ProgramSymbolContext.of_sdv(
            'REFERENCED_PROGRAM',
            command_program_sdv.ProgramSdvForCommand(
                CommandSdv(
                    command_driver.command_driver,
                    ArgumentsSdv.new_without_validation(
                        list_sdvs.from_str_constants(
                            arguments_of_referenced_command))),
                AccumulatedComponents.of_arguments(
                    ArgumentsSdv.new_without_validation(
                        list_sdvs.from_str_constants(
                            accumulated_arguments_of_referenced_program)))))
        source_to_parse = self.source_to_parse(
            referenced_program_symbol.name,
            [
                ArgumentOfRichStringAbsStx.of_str(arg)
                for arg in additional_argument
            ],
        )
        # ACT & ASSERT #
        self.integration_checker().check__abs_stx__wo_input(
            self.put,
            source_to_parse,
            command_driver.mk_arrangement(
                referenced_program_symbol.symbol_table),
            Expectation(
                parse=ParseExpectation(
                    symbol_references=referenced_program_symbol.
                    references_assertion, ),
                primitive=expected_program,
            ),
        )
Esempio n. 3
0
    def test_assignment_of_list_with_multiple_constant_elements(self):
        # ARRANGE #
        value_without_space = 'value_without_space'
        value_with_space = 'value with space'

        symbol_to_assign = ListSymbolContext.of_sdv(
            'the_symbol_name',
            sdvs.from_str_constants([value_without_space, value_with_space]))

        syntax = _syntax(
            symbol_to_assign,
            NonEmptyListAbsStx([
                ListElementStringAbsStx.of_str(value_without_space),
                ListElementStringAbsStx.of_str(value_with_space,
                                               QuoteType.SOFT),
            ]))

        expectation = MultiSourceExpectation.phase_agnostic(
            symbol_usages=asrt.matches_sequence(
                [symbol_to_assign.assert_matches_definition_of_sdv]),
            symbols_after_main=assert_symbol_table_is_singleton(
                symbol_to_assign.name,
                symbol_to_assign.value.assert_matches_container_of_sdv,
            ),
        )
        # ACT & ASSERT #
        INSTRUCTION_CHECKER.check__abs_stx__layout_and_source_variants(
            self,
            syntax,
            Arrangement.phase_agnostic(),
            expectation,
        )
Esempio n. 4
0
 def of_constants(
     elements: Sequence[str],
     definition_source: Optional[
         SourceLocationInfo] = ARBITRARY_LINE_SEQUENCE_FOR_DEFINITION,
 ) -> 'ListSymbolValueContext':
     return ListSymbolValueContext.of_sdv(
         list_sdvs.from_str_constants(elements), definition_source)
Esempio n. 5
0
def for_system_program__from_pgm_and_args(
        pgm_and_args: ProgramAndArguments) -> CommandSdv:
    program = string_sdvs.str_constant(pgm_and_args.program)
    arguments = list_sdvs.from_str_constants(pgm_and_args.arguments)
    additional_arguments = ArgumentsSdv.new_without_validation(arguments)
    return for_system_program(program).new_with_additional_arguments(
        additional_arguments)
    def run_test(self):
        relativity_conf = relativity_options.conf_rel_any(
            self._missing_file_relativity)

        referenced_program_arguments = [
            'valid arg 1 of referenced', 'valid arg 2 of referenced'
        ]
        referenced_system_program_sdv = program_sdvs.system_program(
            string_sdvs.str_constant('valid-system-program'),
            ArgumentsSdv.new_without_validation(
                list_sdvs.from_str_constants(referenced_program_arguments)))

        valid_program_symbol = ProgramSymbolContext.of_sdv(
            'VALID_PROGRAM', referenced_system_program_sdv)

        invalid_argument_syntax = ArgumentOfExistingPathAbsStx(
            relativity_conf.path_abs_stx_of_name('non-existing-file'))
        reference_and_additional_invalid_argument = self.source_to_parse(
            valid_program_symbol.name,
            [invalid_argument_syntax],
        )
        # ACT & ASSERT #
        self.integration_checker(
        ).check__abs_stx__layouts__source_variants__wo_input(
            self.put,
            equivalent_source_variants__for_consume_until_end_of_last_line__s__nsc,
            reference_and_additional_invalid_argument,
            arrangement_w_tcds(symbols=valid_program_symbol.symbol_table, ),
            MultiSourceExpectation.of_const(
                symbol_references=valid_program_symbol.references_assertion,
                primitive=asrt.anything_goes(),
                execution=ExecutionExpectation(
                    validation=FAILING_VALIDATION_ASSERTION_FOR_PARTITION[
                        relativity_conf.directory_structure_partition], )),
        )
Esempio n. 7
0
 def _command_to_execute(
     self,
     environment: InstructionEnvironmentForPostSdsStep,
 ) -> CommandSdv:
     return self.object_to_execute.interpreter.new_with_additional_arguments(
         ArgumentsSdv(
             list_sdvs.from_str_constants([str(self.source_file_path)])))
Esempio n. 8
0
 def test_equals(self):
     cases = [
         list_sdvs.from_str_constants(['value']),
         list_sdvs.from_elements([list_sdvs.symbol_element(reference_to__on_direct_and_indirect('symbol_name'))]),
     ]
     for sdv in cases:
         with self.subTest(msg=str(sdv)):
             sut.equals_list_sdv(sdv).apply_without_message(self, sdv)
def _source_interpreter_with_system_command(
        cmd_and_args: List[str]) -> NameAndValue[Actor]:
    command_sdv = command_sdvs.for_system_program(
        string_sdvs.str_constant(cmd_and_args[0]),
        ArgumentsSdv(list_sdvs.from_str_constants(cmd_and_args[1:])),
    )
    return NameAndValue(actors.SOURCE_INTERPRETER_ACTOR.singular_name,
                        actor.actor(command_sdv))
Esempio n. 10
0
 def test_not_equals__list(self):
     # ARRANGE #
     expected = list_sdvs.from_str_constants(['value'])
     actual = list_sdvs.from_elements([
         list_sdvs.symbol_element(
             data_references.reference_to__on_direct_and_indirect(
                 'symbol_name'))
     ])
     # ACT & ASSERT #
     assert_that_assertion_fails(sut.equals_data_type_sdv(expected), actual)
Esempio n. 11
0
 def test_list_constant(self):
     # ARRANGE #
     constant = ['a', 'b' 'c']
     # ACT #
     actual = list_sdvs.from_str_constants(constant)
     # ASSERT #
     self.assertEqual([], actual.references,
                      'references')
     actual_value = actual.resolve(empty_symbol_table())
     expected_value = AMultiDirDependentValue(resolving_dependencies=set(),
                                              get_value_when_no_dir_dependencies=do_return(constant),
                                              get_value_of_any_dependency=do_return(constant))
     matches_multi_dir_dependent_value(expected_value).apply_with_message(self, actual_value, 'resolve value')
Esempio n. 12
0
 def test_not_equals(self):
     string_symbol = StringConstantSymbolContext('string_symbol_name', 'string symbol value')
     cases = [
         MatchesCase('different number of elements',
                     expected=
                     lr.ListDdv([]),
                     expected_references=
                     asrt.is_empty_sequence,
                     actual=
                     list_sdvs.from_str_constants(['value']),
                     ),
         MatchesCase('different value of single string',
                     expected=
                     lr.ListDdv([string_ddv_of_single_string('expected value')]),
                     expected_references=
                     asrt.is_empty_sequence,
                     actual=
                     list_sdvs.from_str_constants(['actual value']),
                     ),
         MatchesCase('different references',
                     expected=
                     lr.ListDdv([string_ddv_of_single_string(string_symbol.str_value)]),
                     expected_references=
                     asrt.matches_sequence([string_symbol.reference_assertion__w_str_rendering]),
                     actual=
                     list_sdvs.from_elements([list_sdvs.string_element(
                         string_sdvs.symbol_reference(
                             SymbolReference(string_symbol.name,
                                             OrReferenceRestrictions([])),
                         ))]),
                     symbols=
                     string_symbol.symbol_table,
                     ),
     ]
     for case in cases:
         with self.subTest(msg=case.name):
             assertion = sut.matches_list_sdv(case.expected, case.expected_references, case.symbols)
             assert_that_assertion_fails(assertion, case.actual)
Esempio n. 13
0
 def test_equals(self):
     test_cases = [
         (
             list_sdvs.empty(),
             []
         ),
         (
             list_sdvs.from_str_constants(['value 1',
                                           'value 2']),
             ['value 1', 'value 2']
         ),
     ]
     for actual, expected in test_cases:
         with self.subTest(expected=repr(expected)):
             sut.equals_constant_list(expected).apply_without_message(self, actual)
Esempio n. 14
0
 def test_not_equals(self):
     test_cases = [
         (
             list_sdvs.empty(),
             ['non empty']
         ),
         (
             list_sdvs.from_str_constants(['value 1',
                                           'value 2 actual']),
             ['value 1', 'value 2 expected']
         ),
     ]
     for actual, expected in test_cases:
         assertion = sut.equals_constant_list(expected)
         with self.subTest(expected=repr(expected)):
             assert_that_assertion_fails(assertion, actual)
Esempio n. 15
0
 def test_equals(self):
     string_symbol = StringConstantSymbolContext('string_symbol_name', 'string symbol value')
     cases = [
         MatchesCase('empty list of fragments',
                     expected=
                     lr.ListDdv([]),
                     expected_references=
                     asrt.is_empty_sequence,
                     actual=
                     list_sdvs.empty(),
                     ),
         MatchesCase('single fragment',
                     expected=
                     lr.ListDdv([string_ddv_of_single_string('expected value')]),
                     expected_references=
                     asrt.is_empty_sequence,
                     actual=
                     list_sdvs.from_str_constants(['expected value']),
                     ),
         MatchesCase('symbol reference',
                     expected=
                     lr.ListDdv([string_ddv_of_single_string(string_symbol.str_value)]),
                     expected_references=
                     asrt.matches_sequence([string_symbol.reference_assertion__w_str_rendering]),
                     actual=
                     list_sdvs.from_elements([list_sdvs.string_element(
                         string_sdvs.symbol_reference(string_symbol.reference__w_str_rendering)
                     )]),
                     symbols=
                     string_symbol.symbol_table,
                     ),
     ]
     for case in cases:
         with self.subTest(msg=case.name):
             assertion = sut.matches_list_sdv(case.expected, case.expected_references, case.symbols)
             assertion.apply_without_message(self, case.actual)
Esempio n. 16
0
def equals_constant_list(expected_str_list: Iterable[str]) -> Assertion[SymbolDependentValue]:
    return equals_list_sdv(list_sdvs.from_str_constants(expected_str_list))
Esempio n. 17
0
 def test_equals__list(self):
     # ARRANGE #
     value = list_sdvs.from_str_constants(['value'])
     # ACT & ASSERT #
     sut.equals_data_type_sdv(value).apply_without_message(self, value)
Esempio n. 18
0
    def test_shell_program_via_symbol_reference(self):
        shell_command_line_of_referenced_program = 'initial shell command line'
        arguments_of_referenced_program = ['arg1', 'arg 2']
        referenced_shell_program_sdv = program_sdvs.shell_program(
            string_sdvs.str_constant(shell_command_line_of_referenced_program),
            ArgumentsSdv.new_without_validation(
                list_sdvs.from_str_constants(arguments_of_referenced_program)),
        )
        referenced_program_symbol = ProgramSymbolContext.of_sdv(
            'SHELL_PROGRAM_REFERENCE',
            referenced_shell_program_sdv,
        )

        string_argument_symbol = StringConstantSymbolContext(
            'STRING_ARGUMENT_SYMBOL',
            'string argument',
        )
        list_argument_symbol = ListConstantSymbolContext(
            'LIST_ARGUMENT_SYMBOL', ['list_arg_value_1', 'list arg value 2'])
        str_w_list_template = 'before{}after'
        str_w_list_ref = str_w_list_template.format(
            list_argument_symbol.name__sym_ref_syntax)

        expected_argument_strings = (
            arguments_of_referenced_program +
            [string_argument_symbol.str_value] +
            list_argument_symbol.constant_list + [
                str_w_list_template.format(' '.join(
                    list_argument_symbol.constant_list))
            ])

        symbols = [
            referenced_program_symbol, string_argument_symbol,
            list_argument_symbol
        ]

        syntax = ProgramOfSymbolReferenceAbsStx(
            referenced_program_symbol.name, [
                ArgumentOfSymbolReferenceAbsStx(string_argument_symbol.name),
                ArgumentOfSymbolReferenceAbsStx(list_argument_symbol.name),
                ArgumentOfRichStringAbsStx.of_str(str_w_list_ref),
            ])

        def expected_program(
                env: AssertionResolvingEnvironment) -> Assertion[Program]:
            return asrt_pgm_val.matches_program(
                command=asrt_command.equals_shell_command(
                    command_line=shell_command_line_of_referenced_program,
                    arguments=expected_argument_strings,
                ),
                stdin=asrt_pgm_val.is_no_stdin(),
                transformer=asrt_pgm_val.is_no_transformation(),
            )

        expectation = MultiSourceExpectation(
            symbol_references=asrt.matches_sequence([
                referenced_program_symbol.reference_assertion,
                string_argument_symbol.reference_assertion__w_str_rendering,
                list_argument_symbol.reference_assertion__w_str_rendering,
                list_argument_symbol.reference_assertion__w_str_rendering,
            ]),
            primitive=expected_program,
        )

        # ACT & ASSERT #
        CHECKER_WO_EXECUTION.check__abs_stx__layouts__source_variants__wo_input(
            self,
            equivalent_source_variants__for_consume_until_end_of_last_line__s__nsc,
            syntax,
            arrangement_wo_tcds(
                symbols=SymbolContext.symbol_table_of_contexts(symbols), ),
            expectation,
        )