def check_parsing_with_different_source_variants(
        self,
        make_instruction_arguments: InstructionArgumentsVariantConstructor,
        default_relativity: RelOptionType,
        non_default_relativity: RelOptionType,
        main_result_for_positive_expectation: PassOrFail,
        contents_of_relativity_option_root: DirContents = empty_dir_contents(),
        following_symbols_setup: SymbolsArrEx = SymbolsArrEx.empty()):

        rel_opt_configs = [
            rel_opt_conf.default_conf_rel_any(default_relativity),
            rel_opt_conf.conf_rel_any(non_default_relativity),
        ]

        for rel_opt_config in rel_opt_configs:
            for expectation_type_of_test_case in ExpectationType:
                etc = pfh_expectation_type_config(
                    expectation_type_of_test_case)
                instruction_arguments = make_instruction_arguments.apply(
                    etc, rel_opt_config)

                for source in equivalent_source_variants__with_source_check__consume_last_line(
                        self.put, instruction_arguments):
                    self._check_(
                        source,
                        etc,
                        main_result_for_positive_expectation,
                        rel_opt_config,
                        contents_of_relativity_option_root,
                        following_symbols_setup=following_symbols_setup)
Example #2
0
 def test_invalid_arguments_with_symbol_references(self):
     symbol_name = SymbolWithReferenceSyntax('symbol_name')
     operand_arg_with_symbol_ref_list = [
         ' {op} {sym}'.format(op=comparators.EQ.name, sym=symbol_name),
     ]
     invalid_symbol_values = [
         'not_a_number',
         '1.5',
         '72 87',
     ]
     for invalid_symbol_value in invalid_symbol_values:
         symbol = StringConstantSymbolContext(symbol_name.name,
                                              invalid_symbol_value)
         for operand_arg_with_symbol_ref in operand_arg_with_symbol_ref_list:
             arguments = self._conf().arguments_constructor.apply(
                 operand_arg_with_symbol_ref)
             with self.subTest(argument=arguments,
                               invalid_symbol_value=invalid_symbol_value):
                 for source in equivalent_source_variants__with_source_check__consume_last_line(
                         self, arguments):
                     self._check(
                         source,
                         ArrangementPostAct(symbols=symbol.symbol_table),
                         Expectation(
                             validation_pre_sds=svh_asrt.
                             is_validation_error(),
                             symbol_usages=asrt.matches_sequence([
                                 symbol.
                                 reference_assertion__string__w_all_indirect_refs_are_strings
                             ]),
                         ),
                     )
Example #3
0
    def test(self):

        expected_defined_symbol = ConstantSuffixPathDdvSymbolContext(
            'name', RelOptionType.REL_ACT, 'component')
        argument_cases = [
            NameAndValue('value on same line', '{rel_act} {suffix}'),
            NameAndValue('value on following line',
                         '{new_line} {rel_act} {suffix}'),
        ]

        for argument_case in argument_cases:
            with self.subTest(arguments=argument_case.name):
                instruction_argument = src2(
                    ValueType.PATH,
                    expected_defined_symbol.name,
                    argument_case.value,
                    suffix=expected_defined_symbol.path_suffix)
                for source in equivalent_source_variants__with_source_check__consume_last_line(
                        self, instruction_argument):
                    INSTRUCTION_CHECKER.check(
                        self, source, Arrangement.phase_agnostic(),
                        Expectation.phase_agnostic(
                            symbol_usages=asrt.matches_singleton_sequence(
                                expected_defined_symbol.
                                assert_matches_definition_of_sdv),
                            symbols_after_main=assert_symbol_table_is_singleton(
                                expected_defined_symbol.name,
                                expected_defined_symbol.value.
                                assert_matches_container_of_sdv)))
Example #4
0
 def test(self):
     with tmp_dir() as abs_path_of_dir_containing_last_file_base_name:
         fs_location_info = FileSystemLocationInfo(
             FileLocationInfo(
                 abs_path_of_dir_containing_last_file_base_name))
         instruction_argument = src2(ValueType.PATH, 'name',
                                     '{rel_source_file} component')
         for source in equivalent_source_variants__with_source_check__consume_last_line(
                 self, instruction_argument):
             expected_path_sdv = path_sdvs.constant(
                 path_ddvs.rel_abs_path(
                     abs_path_of_dir_containing_last_file_base_name,
                     path_ddvs.constant_path_part('component')))
             expected_symbol_value = PathSymbolValueContext.of_sdv(
                 expected_path_sdv)
             expected_symbol = PathSymbolContext('name',
                                                 expected_symbol_value)
             INSTRUCTION_CHECKER.check(
                 self, source,
                 Arrangement.phase_agnostic(
                     fs_location_info=fs_location_info),
                 Expectation.phase_agnostic(
                     symbol_usages=asrt.matches_singleton_sequence(
                         expected_symbol.assert_matches_definition_of_sdv),
                     symbols_after_main=assert_symbol_table_is_singleton(
                         'name', expected_symbol_value.
                         assert_matches_container_of_sdv)))
Example #5
0
 def test(self):
     instruction_argument = src2(
         ValueType.PATH, 'ASSIGNED_NAME',
         '{rel_symbol} REFERENCED_SYMBOL component')
     for source in equivalent_source_variants__with_source_check__consume_last_line(
             self, instruction_argument):
         expected_path_sdv = path_sdvs.rel_symbol(
             SymbolReference(
                 'REFERENCED_SYMBOL',
                 ReferenceRestrictionsOnDirectAndIndirect(
                     PathAndRelativityRestriction(
                         type_parser.REL_OPTIONS_CONFIGURATION.
                         accepted_relativity_variants))),
             path_part_sdvs.from_constant_str('component'))
         expected_symbol_value = PathSymbolValueContext.of_sdv(
             expected_path_sdv)
         expected_symbol = PathSymbolContext('ASSIGNED_NAME',
                                             expected_symbol_value)
         INSTRUCTION_CHECKER.check(
             self, source, Arrangement.phase_agnostic(),
             Expectation.phase_agnostic(
                 symbol_usages=asrt.matches_sequence(
                     [expected_symbol.assert_matches_definition_of_sdv]),
                 symbols_after_main=assert_symbol_table_is_singleton(
                     expected_symbol.name, expected_symbol_value.
                     assert_matches_container_of_sdv)))
    def check__with_source_variants(self, instruction_arguments: str,
                                    arrangement: ArrangementPostAct,
                                    expectation: Expectation):

        for source in equivalent_source_variants__with_source_check__consume_last_line(
                self.put, instruction_arguments):
            instruction_check.check(self.put, self.parser, source, arrangement,
                                    expectation)
Example #7
0
 def _run(self, expected: tcs.TestCaseStatus, initial: tcs.TestCaseStatus,
          argument: str):
     for source in equivalent_source_variants__with_source_check__consume_last_line(
             self, argument):
         self._check(
             sut.Parser(), source,
             Arrangement(test_case_status=initial,
                         actor=actor_that_runs_constant_actions()),
             Expectation(configuration=asrt_conf.matches(
                 status=asrt.is_(expected))))
Example #8
0
 def test_succeed_when_valid_syntax(self):
     test_cases = [
         'file-name.ext',
         '**.ext',
         '\'quoted file name ***\'',
     ]
     parser = sut.new_parser()
     for instruction_argument in test_cases:
         with self.subTest(msg='instruction argument=' + repr(instruction_argument)):
             for source in equivalent_source_variants__with_source_check__consume_last_line(self,
                                                                                            instruction_argument):
                 actual = parser.parse(ARBITRARY_FS_LOCATION_INFO, source)
                 self.assertIsInstance(actual,
                                       parsed_section_element.ParsedInstruction)
                 self.assertIsInstance(actual.instruction_info.instruction,
                                       sut.SuitesSectionInstruction)
Example #9
0
    def test_fail_when_invalid_syntax(self):
        test_cases = [
            '   ',
            '  =  ',
            '= "argument-2',
            'argument-1 "argument-2',
        ]
        parser = sut.Parser()
        for instruction_argument in test_cases:
            with self.subTest(msg='instruction argument=' +
                              repr(instruction_argument)):
                for source in equivalent_source_variants__with_source_check__consume_last_line(
                        self, instruction_argument):
                    with self.assertRaises(
                            SingleInstructionInvalidArgumentException) as cm:
                        parser.parse(ARBITRARY_FS_LOCATION_INFO, source)

                    self.assertIsInstance(cm.exception.error_message, str)
Example #10
0
 def test_invalid_arguments_without_symbol_references(self):
     test_cases = [
         ' {op} a'.format(op=comparators.EQ.name),
         '{op} 1.5'.format(op=comparators.GT.name),
     ]
     for condition_str in test_cases:
         with self.subTest(msg=condition_str):
             instr_arg = self._conf().arguments_constructor.apply(
                 condition_str)
             for source in equivalent_source_variants__with_source_check__consume_last_line(
                     self, instr_arg):
                 self._check(
                     source,
                     ArrangementPostAct(),
                     Expectation(
                         validation_pre_sds=svh_asrt.is_validation_error(),
                         symbol_usages=asrt.is_empty_sequence,
                     ),
                 )
Example #11
0
 def _check(self, instruction_argument_source: str,
            expected_command_and_arguments: list):
     for source in equivalent_source_variants__with_source_check__consume_last_line(
             self, instruction_argument_source):
         # ARRANGE #
         instruction = sut.Parser().parse(ARBITRARY_FS_LOCATION_INFO,
                                          source)
         assert isinstance(instruction, ConfigurationSectionInstruction)
         environment = configuration_section_environment()
         # ACT #
         instruction.execute(environment)
         # ASSERT #
         actual_preprocessor = environment.preprocessor
         self.assertIsInstance(actual_preprocessor,
                               PreprocessorViaExternalProgram)
         assert isinstance(actual_preprocessor,
                           PreprocessorViaExternalProgram)
         self.assertEqual(expected_command_and_arguments,
                          actual_preprocessor.external_program)
Example #12
0
    def test(self):
        expected_defined_symbol = ConstantSuffixPathDdvSymbolContext(
            'name', type_parser.REL_OPTIONS_CONFIGURATION.default_option,
            'component')

        instruction_argument = src2(ValueType.PATH,
                                    expected_defined_symbol.name,
                                    expected_defined_symbol.path_suffix)

        for source in equivalent_source_variants__with_source_check__consume_last_line(
                self, instruction_argument):
            INSTRUCTION_CHECKER.check(
                self, source, Arrangement.phase_agnostic(),
                Expectation.phase_agnostic(
                    symbol_usages=asrt.matches_singleton_sequence(
                        expected_defined_symbol.
                        assert_matches_definition_of_sdv),
                    symbols_after_main=assert_symbol_table_is_singleton(
                        'name', expected_defined_symbol.value.
                        assert_matches_container_of_sdv)))
Example #13
0
    def check_multi__with_source_variants(
            self,
            put: unittest.TestCase,
            source: SourceArrangement,
            symbol_usages: Assertion[Sequence[SymbolUsage]],
            execution: Sequence[NExArr[ExecutionExpectation, ArrangementPostAct2]],
    ):
        for parse_source in equivalent_source_variants__with_source_check__consume_last_line(
                put,
                source.arguments.as_single_string):
            instruction = self._parse_checker.parse(
                put,
                source.fs_location_info,
                parse_source,
                ParseExpectation(
                    symbol_usages=symbol_usages,
                ))

            for case in execution:
                with put.subTest(execution_case=case.name):
                    checker = ExecutionChecker(put, case.arrangement, case.expected)
                    checker.check(instruction)
Example #14
0
 def run_single_line_test_with_source_variants_and_source_check(
         self, put: unittest.TestCase, instruction_argument: str,
         arrangement, expectation):
     for source in equivalent_source_variants__with_source_check__consume_last_line(
             put, instruction_argument):
         self.run_test(put, source, arrangement, expectation)
Example #15
0
 def _check(self, instruction_argument: str, arrangement: Arrangement,
            expectation: Expectation):
     for source in equivalent_source_variants__with_source_check__consume_last_line(
             self, instruction_argument):
         Executor(self, arrangement,
                  expectation).execute(self.conf.parser(), source)