def assert_instruction(first_line_number: int,
                       source_string: str) -> Assertion:
    return asrt.And([
        asrt.sub_component('first_line_number',
                           Instruction.first_line_number.fget,
                           asrt.Equals(first_line_number)),
        asrt.sub_component('source_string', Instruction.source_string.fget,
                           asrt.Equals(source_string))
    ])
Exemple #2
0
    def test_symbol_value_with_space_SHOULD_be_given_as_single_argument_to_program(
            self):
        symbol = StringConstantSymbolContext('symbol_name',
                                             'symbol value with space')

        expected_output = lines_content([symbol.str_value])

        executable_file_name = 'the-executable_file_name'

        command_line = '{executable_file_name} {symbol}'.format(
            executable_file_name=executable_file_name,
            symbol=symbol.name__sym_ref_syntax,
        )

        arrangement = arrangement_w_tcds(
            hds_contents=relativity_configurations.ATC_FILE.
            populator_for_relativity_option_root__hds(
                fs.DirContents([
                    fs.python_executable_file(
                        executable_file_name,
                        PYTHON_PROGRAM_THAT_PRINTS_COMMAND_LINE_ARGUMENTS_ON_SEPARATE_LINES
                    )
                ])),
            symbol_table=symbol.symbol_table)

        expectation = Expectation(
            symbol_usages=asrt.matches_sequence(
                [symbol.reference_assertion__w_str_rendering]),
            execute=eh_assertions.is_exit_code(0),
            post_sds=PostSdsExpectation.
            constant(sub_process_result_from_execute=pr.stdout(
                asrt.Equals(expected_output, 'CLI arguments, one per line'))),
        )
        check_execution(self, sut.actor(), [instr([command_line])],
                        arrangement, expectation)
Exemple #3
0
def is_entity_for_type(entity_type_name: str) -> Assertion:
    return asrt.And([
        is_entity,
        asrt.sub_component('entity type name',
                           EntityCrossReferenceId.entity_type_identifier.fget,
                           asrt.Equals(entity_type_name))
    ])
 def test_description_on_single_line_and_instruction_on_line_after(self):
     source_and_description_variants = [
         (
             [
                 '{d}single line, single quotes{d}',
                 'instruction',
             ],
             Expectation(
                 description=asrt.Equals('single line, single quotes'),
                 source=source_is_at_end,
                 instruction=assert_instruction(2, 'instruction')),
         ),
         (
             [
                 '{d}single line, single quotes{d}',
                 '',
                 'instruction',
             ],
             Expectation(
                 description=asrt.Equals('single line, single quotes'),
                 source=source_is_at_end,
                 instruction=assert_instruction(3, 'instruction')),
         ),
         (
             [
                 '   {d}single line, indented{d}',
                 'instruction',
             ],
             Expectation(description=asrt.Equals('single line, indented'),
                         source=source_is_at_end,
                         instruction=assert_instruction(2, 'instruction')),
         ),
     ]
     for description_lines, expectation in source_and_description_variants:
         with self.subTest(description_lines=description_lines):
             source = _source_of_lines(description_lines)
             arrangement = Arrangement(self.sut, source)
             check(self, expectation, arrangement)
Exemple #5
0
    def runTest(self):
        sub_dir_of_home = 'sub-dir'
        dir_symbol = ConstantSuffixPathDdvSymbolContext('dir_symbol_name',
                                                        RelOptionType.REL_HDS_ACT,
                                                        sub_dir_of_home,
                                                        PATH_RELATIVITY_VARIANTS_FOR_FILE_TO_RUN)

        source_file_name_symbol = StringConstantSymbolContext('source_file_name_symbol_name',
                                                              'the-source-file.py')

        argument = 'argument_string'

        expected_output = lines_content([argument])

        command_line = '{dir}/{file_name}  {argument} '.format(
            dir=dir_symbol.name__sym_ref_syntax,
            file_name=source_file_name_symbol.name__sym_ref_syntax,
            argument=argument,
        )

        executable_file = fs.File(
            source_file_name_symbol.str_value,
            PYTHON_PROGRAM_THAT_PRINTS_COMMAND_LINE_ARGUMENTS_ON_SEPARATE_LINES)

        arrangement = arrangement_w_tcds(
            hds_contents=contents_in(RelHdsOptionType.REL_HDS_ACT, fs.DirContents([
                fs.Dir(sub_dir_of_home, [executable_file])
            ])),
            symbol_table=SymbolContext.symbol_table_of_contexts([
                dir_symbol,
                source_file_name_symbol,
            ])
        )

        expectation = Expectation(
            symbol_usages=asrt.matches_sequence([
                dir_symbol.reference_assertion__path_or_string,
                source_file_name_symbol.reference_assertion__path_component,
            ]),
            execute=eh_assertions.is_exit_code(0),
            post_sds=PostSdsExpectation.constant(
                sub_process_result_from_execute=pr.stdout(asrt.Equals(expected_output,
                                                                      'CLI arguments, one per line'))
            ),
        )
        self._check(command_line,
                    arrangement,
                    expectation)
Exemple #6
0
    def test_multiple_symbol_references_in_executable(self):
        sub_dir_of_home = 'sub-dir'
        dir_symbol = ConstantSuffixPathDdvSymbolContext(
            'dir_symbol_name', RelOptionType.REL_HDS_ACT, sub_dir_of_home,
            PATH_RELATIVITY_VARIANTS_FOR_FILE_TO_RUN)

        executable_file_name_symbol = StringConstantSymbolContext(
            'executable_file_name_symbol_name', 'the-executable-file')

        argument = 'argument_string'

        expected_output = lines_content([argument])

        command_line = '{dir}/{file_name}  {argument} '.format(
            dir=dir_symbol.name__sym_ref_syntax,
            file_name=executable_file_name_symbol.name__sym_ref_syntax,
            argument=argument,
        )

        executable_file = fs.python_executable_file(
            executable_file_name_symbol.str_value,
            PYTHON_PROGRAM_THAT_PRINTS_COMMAND_LINE_ARGUMENTS_ON_SEPARATE_LINES
        )

        arrangement = arrangement_w_tcds(
            hds_contents=relativity_configurations.ATC_FILE.
            populator_for_relativity_option_root__hds(
                fs.DirContents([fs.Dir(sub_dir_of_home, [executable_file])])),
            symbol_table=SymbolContext.symbol_table_of_contexts([
                dir_symbol,
                executable_file_name_symbol,
            ]))

        expectation = Expectation(
            symbol_usages=asrt.matches_sequence([
                dir_symbol.reference_assertion__path_or_string,
                executable_file_name_symbol.
                reference_assertion__string__w_all_indirect_refs_are_strings,
            ]),
            execute=eh_assertions.is_exit_code(0),
            post_sds=PostSdsExpectation.
            constant(sub_process_result_from_execute=pr.stdout(
                asrt.Equals(expected_output, 'CLI arguments, one per line'))),
        )
        check_execution(self, sut.actor(), [instr([command_line])],
                        arrangement, expectation)
Exemple #7
0
    def test_string_symbol_reference_in_executable_and_argument(self):
        symbol_for_executable = StringConstantSymbolContext(
            'executable_symbol_name', 'the-executable')

        argument_symbol = StringConstantSymbolContext('argument_symbol_name',
                                                      'string-constant')

        expected_output = lines_content([argument_symbol.str_value])

        command_line = '{executable} {argument} '.format(
            executable=symbol_for_executable.name__sym_ref_syntax,
            argument=argument_symbol.name__sym_ref_syntax,
        )

        arrangement = arrangement_w_tcds(
            hds_contents=relativity_configurations.ATC_FILE.
            populator_for_relativity_option_root__hds(
                fs.DirContents([
                    fs.python_executable_file(
                        symbol_for_executable.str_value,
                        PYTHON_PROGRAM_THAT_PRINTS_COMMAND_LINE_ARGUMENTS_ON_SEPARATE_LINES
                    )
                ])),
            symbol_table=SymbolContext.symbol_table_of_contexts([
                symbol_for_executable,
                argument_symbol,
            ]))

        expectation = Expectation(
            execute=eh_assertions.is_exit_code(0),
            symbol_usages=asrt.matches_sequence([
                symbol_for_executable.reference_assertion__path_or_string(
                    PATH_RELATIVITY_VARIANTS_FOR_FILE_TO_RUN),
                argument_symbol.reference_assertion__w_str_rendering,
            ]),
            post_sds=PostSdsExpectation.
            constant(sub_process_result_from_execute=pr.stdout(
                asrt.Equals(expected_output, 'CLI arguments, one per line'))),
        )
        check_execution(self, sut.actor(), [instr([command_line])],
                        arrangement, expectation)
    def runTest(self):
        symbol = StringConstantSymbolContext('symbol_name', 'the symbol value')

        program_that_prints_value_of_symbol = 'print("{symbol}")'

        single_source_line = program_that_prints_value_of_symbol.format(
            symbol=symbol.name__sym_ref_syntax, )

        expected_output = symbol.str_value + '\n'

        self._check(
            single_source_line,
            arrangement_w_tcds(symbol_table=symbol.symbol_table),
            Expectation(
                symbol_usages=asrt.matches_sequence([
                    symbol.reference_assertion__w_str_rendering,
                ]),
                post_sds=PostSdsExpectation.constant(
                    sub_process_result_from_execute=asrt_pr.stdout(
                        asrt.Equals(expected_output, 'program output'))),
            ))
Exemple #9
0
 def runTest(self):
     actor = sut.actor()
     act_phase_instructions = [
         instr(['system-under-test first-argument "quoted argument"'])
     ]
     arrangement = arrangement_w_tcds(
         hds_contents=relativity_configurations.ATC_FILE.
         populator_for_relativity_option_root__hds(
             fs.DirContents([
                 fs.python_executable_file(
                     'system-under-test',
                     PYTHON_PROGRAM_THAT_PRINTS_COMMAND_LINE_ARGUMENTS_ON_SEPARATE_LINES
                 )
             ])))
     expected_output = lines_content(['first-argument', 'quoted argument'])
     expectation = Expectation(
         execute=eh_assertions.is_exit_code(0),
         post_sds=PostSdsExpectation.
         constant(sub_process_result_from_execute=pr.stdout(
             asrt.Equals(expected_output, 'CLI arguments, one per line'))))
     check_execution(self, actor, act_phase_instructions, arrangement,
                     expectation)
Exemple #10
0
    def test_symbol_reference_in_arguments(self):
        list_symbol = ListConstantSymbolContext(
            'list_symbol_name', ['first element', 'second element'])

        string_constant = 'string-constant'

        expected_output = lines_content(['string-constant'] +
                                        list_symbol.constant_list)

        executable = 'the-executable'

        command_line = '{executable} {string_constant} {list_symbol}'.format(
            executable=executable,
            string_constant=string_constant,
            list_symbol=list_symbol.name__sym_ref_syntax,
        )

        arrangement = arrangement_w_tcds(
            hds_contents=relativity_configurations.ATC_FILE.
            populator_for_relativity_option_root__hds(
                fs.DirContents([
                    fs.python_executable_file(
                        executable,
                        PYTHON_PROGRAM_THAT_PRINTS_COMMAND_LINE_ARGUMENTS_ON_SEPARATE_LINES
                    )
                ])),
            symbol_table=list_symbol.symbol_table)

        expectation = Expectation(
            symbol_usages=asrt.matches_singleton_sequence(
                list_symbol.reference_assertion),
            execute=eh_assertions.is_exit_code(0),
            post_sds=PostSdsExpectation.
            constant(sub_process_result_from_execute=pr.stdout(
                asrt.Equals(expected_output, 'CLI arguments, one per line'))),
        )
        check_execution(self, sut.actor(), [instr([command_line])],
                        arrangement, expectation)
Exemple #11
0
    def test_symbol_value_with_space_SHOULD_be_given_as_single_argument_to_program(self):
        symbol = StringConstantSymbolContext('symbol_name', 'symbol value with space')

        expected_output = lines_content([symbol.str_value])

        source_file = 'the-source-file.py'

        command_line = '{source_file} {symbol}'.format(
            source_file=source_file,
            symbol=symbol.name__sym_ref_syntax,
        )

        arrangement = integration_check.arrangement_w_tcds(
            hds_contents=contents_in(RelHdsOptionType.REL_HDS_ACT, fs.DirContents([
                fs.File(
                    source_file,
                    PYTHON_PROGRAM_THAT_PRINTS_COMMAND_LINE_ARGUMENTS_ON_SEPARATE_LINES)
            ])),
            symbol_table=symbol.symbol_table
        )

        expectation = integration_check.Expectation(
            symbol_usages=asrt.matches_sequence(
                [symbol.reference_assertion__w_str_rendering]
            ),
            execute=eh_assertions.is_exit_code(0),
            post_sds=PostSdsExpectation.constant(
                sub_process_result_from_execute=asrt_pr.stdout(asrt.Equals(expected_output,
                                                                           'CLI arguments, one per line'))
            ),
        )
        integration_check.check_execution(self,
                                          ACTOR_THAT_RUNS_PYTHON_PROGRAM_FILE,
                                          [instr([command_line])],
                                          arrangement,
                                          expectation)
 def test_ignore_comment_lines_between_description_and_instruction(self):
     source_and_description_variants = [
         (
             [
                 '{d}description{d}',
                 syntax.LINE_COMMENT_MARKER,
                 'instruction',
             ],
             Expectation(description=asrt.Equals('description'),
                         source=source_is_at_end,
                         instruction=assert_instruction(3, 'instruction')),
         ),
         (
             [
                 '{d}description{d}',
                 '     ' + syntax.LINE_COMMENT_MARKER + ' comment text   ',
                 'instruction',
             ],
             Expectation(description=asrt.Equals('description'),
                         source=source_is_at_end,
                         instruction=assert_instruction(3, 'instruction')),
         ),
         (
             [
                 '{d}description{d}',
                 '',
                 syntax.LINE_COMMENT_MARKER,
                 '',
                 'Instruction',
             ],
             Expectation(description=asrt.Equals('description'),
                         source=source_is_at_end,
                         instruction=assert_instruction(5, 'Instruction')),
         ),
         (
             [
                 '{d}description line 1',
                 'description line 2{d}',
                 syntax.LINE_COMMENT_MARKER,
                 'Instruction',
             ],
             Expectation(description=asrt.Equals(
                 'description line 1\ndescription line 2'),
                         source=source_is_at_end,
                         instruction=assert_instruction(4, 'Instruction')),
         ),
         (
             [
                 '{d}description line 1',
                 'description line 2{d}',
                 '',
                 '' + syntax.LINE_COMMENT_MARKER,
                 '' + syntax.LINE_COMMENT_MARKER,
                 'Instruction',
             ],
             Expectation(description=asrt.Equals(
                 'description line 1\ndescription line 2'),
                         source=source_is_at_end,
                         instruction=assert_instruction(6, 'Instruction')),
         ),
     ]
     for description_lines, expectation in source_and_description_variants:
         with self.subTest(description_lines=description_lines):
             source = _source_of_lines(description_lines)
             arrangement = Arrangement(self.sut, source)
             check(self, expectation, arrangement)
Exemple #13
0
def is_empty() -> Assertion[str]:
    """
    :rtype: An Assertion on a str.
    """
    return asrt.Equals('')
Exemple #14
0
def status_is(
    expected_status: pfh.PassOrFailOrHardErrorEnum
) -> Assertion[pfh.PassOrFailOrHardError]:
    return asrt.sub_component('status', pfh.PassOrFailOrHardError.status.fget,
                              asrt.Equals(expected_status))
Exemple #15
0
def equals_with_last_element_removed(expected: list) -> Assertion:
    return asrt.sub_component('all elements except last',
                              lambda l: l[:-1],
                              asrt.Equals(expected))
Exemple #16
0
 def test_true(self):
     sut.Equals('expected').apply(self.put, 'expected')
     sut.Equals('expected').apply(self.put, 'expected',
                                  sut.MessageBuilder('head'))
Exemple #17
0
def status_is(
    expected_status: svh.SuccessOrValidationErrorOrHardErrorEnum,
) -> Assertion[svh.SuccessOrValidationErrorOrHardError]:
    return asrt.sub_component(
        'status', svh.SuccessOrValidationErrorOrHardError.status.fget,
        asrt.Equals(expected_status))
Exemple #18
0
 def test_false__with_message_builder(self):
     with self.assertRaises(TestException):
         sut.Equals('expected').apply(self.put, 'not equal to expected',
                                      sut.MessageBuilder('message head'))