Ejemplo n.º 1
0
 def test_assignment_of_symbols_and_constant_text_within_soft_quotes(self):
     # ARRANGE #
     referred_symbol1 = SymbolWithReferenceSyntax('referred_symbol_1')
     referred_symbol2 = SymbolWithReferenceSyntax('referred_symbol_2')
     assigned_symbol = StringSymbolContext.of_sdv(
         'defined_symbol',
         string_sdv_from_fragments([
             symbol(referred_symbol1.name),
             constant(' between '),
             symbol(referred_symbol2.name),
         ]))
     source = single_line_source('{string_type} {name} = {soft_quote}{sym_ref1} between {sym_ref2}{soft_quote}',
                                 soft_quote=SOFT_QUOTE_CHAR,
                                 name=assigned_symbol.name,
                                 sym_ref1=referred_symbol1,
                                 sym_ref2=referred_symbol2)
     expectation = Expectation.phase_agnostic(
         symbol_usages=asrt.matches_sequence([
             assigned_symbol.assert_matches_definition_of_sdv,
         ]),
         symbols_after_main=assert_symbol_table_is_singleton(
             assigned_symbol.name,
             assigned_symbol.value.assert_matches_container_of_sdv,
         )
     )
     # ACT & ASSERT #
     INSTRUCTION_CHECKER.check(self, source, Arrangement.phase_agnostic(), expectation)
Ejemplo n.º 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__for_expression_parser(
                         self, Arguments(arguments)):
                     self._check(
                         source,
                         Arrangement(symbols=symbol.symbol_table),
                         Expectation(
                             ParseExpectation(
                                 symbol_references=asrt.matches_sequence([
                                     symbol.
                                     reference_assertion__string__w_all_indirect_refs_are_strings
                                 ]), ),
                             ExecutionExpectation(
                                 validation=asrt_validation.
                                 ValidationAssertions.
                                 pre_sds_fails__w_any_msg(), ),
                         ),
                     )
Ejemplo n.º 3
0
    def test_assignment_of_single_symbol_reference(self):
        # ARRANGE #
        referred_symbol = SymbolWithReferenceSyntax('referred_symbol')
        expected_sdv = string_sdv_from_fragments([symbol(referred_symbol.name),
                                                  constant('\n')])
        assigned_symbol = StringSymbolContext.of_sdv(
            'defined_symbol',
            expected_sdv,
        )
        sb = SB.new_with(referred_symbol=referred_symbol,
                         name_of_defined_symbol=assigned_symbol.name)

        source = sb.lines(
            here_doc_lines(first_line_start='{string_type} {name_of_defined_symbol} = ',
                           marker='EOF',
                           contents_lines=[str(referred_symbol)])
        )
        # EXPECTATION #
        expectation = Expectation.phase_agnostic(
            symbol_usages=asrt.matches_sequence([
                assigned_symbol.assert_matches_definition_of_sdv,
            ]),
            symbols_after_main=assert_symbol_table_is_singleton(
                assigned_symbol.name,
                assigned_symbol.value.assert_matches_container_of_sdv,
            )
        )
        # ACT & ASSERT #
        INSTRUCTION_CHECKER.check(self, source, Arrangement.phase_agnostic(), expectation)
Ejemplo n.º 4
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
                             ]),
                         ),
                     )
Ejemplo n.º 5
0
def successful_parse_of_single_symbol() -> List[TC]:
    symbol_ref = SymbolWithReferenceSyntax('validSymbol_name_1')
    single_symbol = [symbol(symbol_ref.name)]
    return [
        TC(
            _src('{symbol_reference}', symbol_reference=symbol_ref),
            Expectation(
                fragments=single_symbol,
                token_stream=assert_token_stream(is_null=asrt.is_true),
            )),
        TC(
            _src('{symbol_reference} rest', symbol_reference=symbol_ref),
            Expectation(
                fragments=single_symbol,
                token_stream=assert_token_stream(
                    head_token=assert_token_string_is('rest')),
            )),
        TC(
            _src('{soft_quote}{symbol_reference}{soft_quote} rest',
                 soft_quote=SOFT_QUOTE_CHAR,
                 symbol_reference=symbol_ref),
            Expectation(
                fragments=single_symbol,
                token_stream=assert_token_stream(
                    head_token=assert_token_string_is('rest')),
            )),
    ]
Ejemplo n.º 6
0
 def test_invalid_arguments_with_symbol_references(self):
     symbol_name = SymbolWithReferenceSyntax('symbol_name')
     operand_arg_with_symbol_ref_list = [
         IntegerMatcherComparisonAbsStx.of_cmp_op(
             comparators.EQ,
             StringSymbolAbsStx(symbol_name.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:
             full_syntax = self._conf().arguments_constructor.apply(
                 operand_arg_with_symbol_ref)
             with self.subTest(argument=full_syntax.as_str__default(),
                               invalid_symbol_value=invalid_symbol_value):
                 self._check(
                     full_syntax,
                     ArrangementPostAct2(symbols=symbol.symbol_table),
                     MultiSourceExpectation(
                         symbol_usages=asrt.matches_sequence([
                             symbol.
                             reference_assertion__string__w_all_indirect_refs_are_strings
                         ]),
                         execution=ExecutionExpectation(
                             validation_pre_sds=svh_asrt.
                             is_validation_error(), ),
                     ),
                 )
Ejemplo n.º 7
0
 def test_successful_parse(self):
     # ARRANGE #
     symbol_ref = SymbolWithReferenceSyntax('validSymbol_name_1')
     single_symbol = [symbol(symbol_ref.name)]
     parse_source = ParseSource(
         _src('{soft_quote}{symbol_reference}{soft_quote} rest',
              soft_quote=SOFT_QUOTE_CHAR,
              symbol_reference=symbol_ref))
     # ACT #
     actual = sut.parse_string_sdv_from_parse_source(parse_source)
     # ASSERT #
     assertion_on_result = assert_equals_string_sdv(single_symbol)
     assertion_on_result.apply_with_message(self, actual, 'result')
     assertion_on_parse_source = assert_source(
         remaining_part_of_current_line=asrt.equals('rest'))
     assertion_on_parse_source.apply_with_message(self, parse_source,
                                                  'parse_source')
Ejemplo n.º 8
0
 def test_files_names_must_be_relative(self):
     # ARRANGE #
     cases = [
         Case(
             'absolute posix file name (constant)',
             args.FilesCondition([
                 args.FileCondition(ABS_POSIX_PATH),
             ]),
             SymbolsArrEx.empty(),
         ),
         Case(
             'valid file name and absolute posix file name (constant)',
             args.FilesCondition([
                 args.FileCondition('valid-file-name'),
                 args.FileCondition(ABS_POSIX_PATH),
             ]),
             SymbolsArrEx.empty(),
         ),
         Case(
             'absolute posix file name (symbol ref)',
             args.FilesCondition([
                 args.FileCondition(
                     SymbolWithReferenceSyntax(ABS_POSIX_PATH_SYMBOL_NAME)),
             ]),
             SymbolsArrEx([
                 StringConstantSymbolContext(ABS_POSIX_PATH_SYMBOL_NAME,
                                             ABS_POSIX_PATH)
             ], [
                 is_sym_ref_to_string__w_all_indirect_refs_are_strings(
                     ABS_POSIX_PATH_SYMBOL_NAME)
             ]),
         ),
     ]
     for case in cases:
         with self.subTest(case.name):
             # ACT & ASSERT #
             CHECKER.check__w_source_variants(
                 self, case.source.as_arguments, None,
                 arrangement_wo_tcds(case.symbols.symbol_table),
                 Expectation(
                     ParseExpectation(symbol_references=case.symbols.
                                      expected_references_assertion),
                     ExecutionExpectation(validation=ValidationAssertions.
                                          pre_sds_fails__w_any_msg())))
Ejemplo n.º 9
0
 def test_assignment_of_single_symbol_reference(self):
     # ARRANGE #
     referred_symbol = SymbolWithReferenceSyntax('referred_symbol')
     assigned_symbol = StringSymbolContext.of_sdv('defined_symbol',
                                                  string_sdv_from_fragments([symbol(referred_symbol.name)]))
     source = single_line_source('{string_type} {name} = {symbol_reference}',
                                 name=assigned_symbol.name,
                                 symbol_reference=referred_symbol)
     expectation = Expectation.phase_agnostic(
         symbol_usages=asrt.matches_sequence([
             assigned_symbol.assert_matches_definition_of_sdv,
         ]),
         symbols_after_main=assert_symbol_table_is_singleton(
             assigned_symbol.name,
             assigned_symbol.value.assert_matches_container_of_sdv,
         )
     )
     # ACT & ASSERT #
     INSTRUCTION_CHECKER.check(self, source, Arrangement.phase_agnostic(), expectation)
Ejemplo n.º 10
0
    def test_forward_slash_should_separate_parts(self):
        # ARRANGE #
        multi_part_file_name = '/'.join(FILE_NAME_PARTS)
        expected_file_names = {PurePosixPath(*FILE_NAME_PARTS): asrt.is_none}

        multi_part_file_name_symbol = StringConstantSymbolContext(
            'multi_part_file_name_symbol', multi_part_file_name)

        cases = [
            Case(
                'multi part posix file name (constant)',
                args.FilesCondition([
                    args.FileCondition(multi_part_file_name),
                ]),
                SymbolsArrEx.empty(),
            ),
            Case(
                'multi part posix file name (symbol reference)',
                args.FilesCondition([
                    args.FileCondition(
                        SymbolWithReferenceSyntax(
                            multi_part_file_name_symbol.name)),
                ]),
                SymbolsArrEx([multi_part_file_name_symbol], [
                    is_sym_ref_to_string__w_all_indirect_refs_are_strings(
                        multi_part_file_name_symbol.name)
                ]),
            ),
        ]
        for case in cases:
            with self.subTest(case.name):
                # ACT & ASSERT #
                CHECKER.check__w_source_variants(
                    self, case.source.as_arguments, None,
                    arrangement_wo_tcds(case.symbols.symbol_table),
                    Expectation(
                        ParseExpectation(symbol_references=case.symbols.
                                         expected_references_assertion),
                        ExecutionExpectation(main_result=asrt.is_none, ),
                        primitive=prim_asrt__constant(
                            asrt_primitive.files_matches(
                                expected_file_names))))
Ejemplo n.º 11
0
 def test(self):
     # ARRANGE #
     cases = [
         CaseWithFiles(
             'single file name',
             args.FilesCondition([
                 args.FileCondition('file-name'),
             ]), SymbolsArrEx.empty(),
             {PurePosixPath('file-name'): asrt.is_none}),
         CaseWithFiles(
             'two file names',
             args.FilesCondition([
                 args.FileCondition('fn1'),
                 args.FileCondition('fn2'),
             ]), SymbolsArrEx.empty(), {
                 PurePosixPath('fn1'): asrt.is_none,
                 PurePosixPath('fn2'): asrt.is_none,
             }),
         CaseWithFiles(
             'two files with the same names',
             args.FilesCondition([
                 args.FileCondition('fn'),
                 args.FileCondition('fn'),
             ]), SymbolsArrEx.empty(), {
                 PurePosixPath('fn'): asrt.is_none,
             }),
         CaseWithFiles(
             'some unique files, some repeated',
             args.FilesCondition([
                 args.FileCondition('fn1'),
                 args.FileCondition('fn2'),
                 args.FileCondition('fn1'),
             ]), SymbolsArrEx.empty(), {
                 PurePosixPath('fn1'): asrt.is_none,
                 PurePosixPath('fn2'): asrt.is_none,
             }),
         CaseWithFiles(
             'different symbols with identical value',
             args.FilesCondition([
                 args.FileCondition(SymbolWithReferenceSyntax('sym_ref1')),
                 args.FileCondition(SymbolWithReferenceSyntax('sym_ref2')),
             ]),
             SymbolsArrEx([
                 StringConstantSymbolContext('sym_ref1', 'fn'),
                 StringConstantSymbolContext('sym_ref2', 'fn'),
             ], [
                 is_sym_ref_to_string__w_all_indirect_refs_are_strings(
                     'sym_ref1'),
                 is_sym_ref_to_string__w_all_indirect_refs_are_strings(
                     'sym_ref2'),
             ]), {
                 PurePosixPath('fn'): asrt.is_none,
             }),
     ]
     for case in cases:
         with self.subTest(case.name):
             # ACT & ASSERT #
             CHECKER.check__w_source_variants(
                 self, case.source.as_arguments, None,
                 arrangement_wo_tcds(case.symbols.symbol_table),
                 Expectation(
                     ParseExpectation(symbol_references=case.symbols.
                                      expected_references_assertion),
                     ExecutionExpectation(),
                     prim_asrt__constant(
                         asrt_primitive.files_matches(case.expected))))
Ejemplo n.º 12
0
 def runTest(self):
     # ARRANGE #
     cases = [
         NIE(
             'file name reference',
             [
                 is_sym_ref_to_string__w_all_indirect_refs_are_strings(
                     STRING_SYMBOL_NAME)
             ],
             args.FilesCondition([
                 args.FileCondition(
                     SymbolWithReferenceSyntax(STRING_SYMBOL_NAME)),
             ]),
         ),
         NIE(
             'file name reference (embedded)',
             [
                 is_sym_ref_to_string__w_all_indirect_refs_are_strings(
                     STRING_SYMBOL_NAME)
             ],
             args.FilesCondition([
                 args.FileCondition(
                     'file-name-prefix-' +
                     str(SymbolWithReferenceSyntax(STRING_SYMBOL_NAME)) +
                     '-suffix'),
             ]),
         ),
         NIE(
             'file matcher reference',
             [is_reference_to_file_matcher(FILE_MATCHER_SYMBOL_NAME)],
             args.FilesCondition([
                 args.FileCondition(
                     'constant-file-name',
                     fm_args.SymbolReferenceWReferenceSyntax(
                         FILE_MATCHER_SYMBOL_NAME)),
             ]),
         ),
         NIE(
             'file name and file matcher reference',
             [
                 is_sym_ref_to_string__w_all_indirect_refs_are_strings(
                     STRING_SYMBOL_NAME),
                 is_reference_to_file_matcher(FILE_MATCHER_SYMBOL_NAME),
             ],
             args.FilesCondition([
                 args.FileCondition(
                     SymbolWithReferenceSyntax(STRING_SYMBOL_NAME),
                     fm_args.SymbolReferenceWReferenceSyntax(
                         FILE_MATCHER_SYMBOL_NAME)),
             ]),
         ),
         NIE(
             'multiple file name and file matcher reference',
             [
                 is_sym_ref_to_string__w_all_indirect_refs_are_strings(
                     STRING_SYMBOL_NAME),
                 is_reference_to_file_matcher(FILE_MATCHER_SYMBOL_NAME),
                 is_sym_ref_to_string__w_all_indirect_refs_are_strings(
                     STRING_SYMBOL_NAME_2),
                 is_reference_to_file_matcher(FILE_MATCHER_SYMBOL_NAME_2),
             ],
             args.FilesCondition([
                 args.FileCondition(
                     SymbolWithReferenceSyntax(STRING_SYMBOL_NAME),
                     fm_args.SymbolReferenceWReferenceSyntax(
                         FILE_MATCHER_SYMBOL_NAME),
                 ),
                 args.FileCondition(
                     SymbolWithReferenceSyntax(STRING_SYMBOL_NAME_2),
                     fm_args.SymbolReferenceWReferenceSyntax(
                         FILE_MATCHER_SYMBOL_NAME_2),
                 ),
             ]),
         ),
     ]
     for must_be_on_current_line in [False, True]:
         for case in cases:
             with self.subTest(
                     case=case.name,
                     must_be_on_current_line=must_be_on_current_line):
                 # ACT #
                 actual = sut.parsers(must_be_on_current_line).full.parse(
                     case.input_value.as_remaining_source)
                 # ASSERT #
                 expectation = asrt.matches_sequence(case.expected_value)
                 expectation.apply_without_message(
                     self,
                     actual.references,
                 )