Exemplo n.º 1
0
 def test_direct_reference(self):
     # ACT #
     actual = sut.ErrorMessage(
         self.string_sym_def_1.name, self.symbol_table,
         FailureOfDirectReference(_new_em('the message', 'the how to fix')))
     # ASSERT #
     asrt_text_doc.assert_is_valid_text_renderer(self, actual)
Exemplo n.º 2
0
 def test_invalid_type(self):
     # ACT #
     actual = sut.ErrorMessage(self.string_sym_def_1.name,
                               self.symbol_table,
                               InvalidValueTypeFailure([ValueType.PATH]))
     # ASSERT #
     asrt_text_doc.assert_is_valid_text_renderer(self, actual)
 def test(self):
     cases = [
         FailureOfDirectReference(_new_em('error message')),
         FailureOfDirectReference(_new_em('error message',
                                          'how to fix')),
     ]
     for failure in cases:
         with self.subTest(msg=failure.error):
             actual = sut.ErrorMessage('checked_symbol', empty_symbol_table(), failure)
             asrt_text_doc.assert_is_valid_text_renderer(self, actual)
Exemplo n.º 4
0
def _validate_reference(symbol_reference: SymbolReference,
                        symbols: SymbolTable) -> Optional[TextRenderer]:
    referenced_sdv_container = symbols.lookup(symbol_reference.name)
    assert isinstance(referenced_sdv_container, SymbolContainer), \
        'Values in SymbolTable must be SymbolContainer'
    result = symbol_reference.restrictions.is_satisfied_by(
        symbols, symbol_reference.name, referenced_sdv_container)
    if result is None:
        return None
    return restriction_failures.ErrorMessage(symbol_reference.name, symbols,
                                             result)
 def test_symbol_is_builtin(self):
     for how_to_fix in ['', 'how_to_fix']:
         with self.subTest(how_to_fix=how_to_fix):
             error = _new_em('error message',
                             how_to_fix=how_to_fix)
             failure = FailureOfIndirectReference(failing_symbol='name_of_failing_symbol',
                                                  path_to_failing_symbol=[],
                                                  error=error)
             # ACT #
             checked_symbol = StringSymbolContext.of_constant('checked_symbol',
                                                              'checked symbol value',
                                                              definition_source=None)
             symbol_table = checked_symbol.symbol_table
             actual = sut.ErrorMessage(checked_symbol.name, symbol_table, failure)
             # ASSERT #
             asrt_text_doc.assert_is_valid_text_renderer(self, actual)
 def test_all_referenced_symbols_have_definition_source(self):
     for path_to_failing_symbol in [[], ['symbol_on_path_to_failing_symbol']]:
         for how_to_fix in ['', 'how_to_fix']:
             with self.subTest(path_to_failing_symbol=path_to_failing_symbol,
                               how_to_fix=how_to_fix):
                 error = _new_em('error message',
                                 how_to_fix=how_to_fix)
                 failure = FailureOfIndirectReference(failing_symbol='name_of_failing_symbol',
                                                      path_to_failing_symbol=path_to_failing_symbol,
                                                      error=error)
                 # ACT #
                 checked_symbol = StringConstantSymbolContext('checked_symbol')
                 symbol_table = SymbolContext.symbol_table_of_contexts(
                     [checked_symbol] +
                     [StringConstantSymbolContext(failing_symbol)
                      for failing_symbol in path_to_failing_symbol]
                 )
                 actual = sut.ErrorMessage(checked_symbol.name, symbol_table, failure)
                 # ASSERT #
                 asrt_text_doc.assert_is_valid_text_renderer(self, actual)