def test_default_constructor_arguments(self): # ARRANGE # self._test_all_element_types( sut.SectionContentElementBuilder( FileLocationInfo(pathlib.Path.cwd())), assertion_on_file_path=asrt.is_none, assertion_on_file_inclusion_chain=asrt.matches_sequence([]))
def _resolve_initial_file_location_info( source_file_path: Path) -> FileLocationInfo: abs_path_of_dir_containing_first_file_path = Path('/') \ if source_file_path.is_absolute() \ else _file_access.resolve_path(Path.cwd(), []) return FileLocationInfo(abs_path_of_dir_containing_first_file_path, source_file_path, [])
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)))
def test_single_file_path_argument(self): # ARRANGE # file_path = pathlib.Path('a path') self._test_all_element_types( sut.SectionContentElementBuilder( FileLocationInfo(pathlib.Path.cwd(), file_path_rel_referrer=file_path)), assertion_on_file_path=asrt.equals(file_path), assertion_on_file_inclusion_chain=asrt.matches_sequence([]))
def test_single_file_inclusion_chain_argument(self): # ARRANGE # file_inclusion_chain = [ SourceLocation(single_line_sequence(2, 'inclusion line'), pathlib.Path('inclusion file path')) ] self._test_all_element_types( sut.SectionContentElementBuilder( FileLocationInfo(pathlib.Path.cwd(), file_inclusion_chain=file_inclusion_chain)), assertion_on_file_path=asrt.is_none, assertion_on_file_inclusion_chain=equals_file_inclusion_chain( file_inclusion_chain))
def _include_files(self, inclusion_directive: ParsedFileInclusionDirective): conf = _SectionsConfigurationInternal(self.configuration.section2parser, self._name_of_current_section, self.configuration.section_element_name_for_error_messages) for file_to_include in inclusion_directive.files_to_include: included_doc = parse_file( conf, self._file_reference_relativity_root_dir, FileLocationInfo(self._current_file_location.abs_path_of_dir_containing_first_file_path, file_to_include, self._current_file_location.location_path_of( inclusion_directive.source)), self.visited_paths) _add_raw_doc(self._section_name_2_element_list, included_doc)
def new_instruction( line_number: int, line_text: str, section_name: str, file_path: pathlib.Path = None, file_inclusion_chain: List[SourceLocation] = () ) -> model.SectionContentElement: builder = SectionContentElementBuilder( FileLocationInfo( pathlib.Path('/'), file_path, file_inclusion_chain, )) return builder.new_instruction( line_source.LineSequence(line_number, (line_text, )), InstructionInSection(section_name))
def test_assignment_of_single_constant_word(self): # ARRANGE # source = single_line_source('{string_type} name1 = v1') source_string = source.source_string parser = sut.EmbryoParser() the_file_path_rel_referrer = pathlib.Path('the-path-rel-referrer') the_file_location_info = FileLocationInfo( pathlib.Path.cwd(), the_file_path_rel_referrer, [ SourceLocation(LineSequence(10, ('line-in-inclusion-chain',)), pathlib.Path('the-path-rel-referrer-of-first-file')) ]) fs_location_info = FileSystemLocationInfo(the_file_location_info) # ACT # instruction = parser.parse(fs_location_info, source) # ASSERT # expected_source_location_path = SourceLocationPath( SourceLocation(single_line_sequence(1, source_string), the_file_path_rel_referrer), the_file_location_info.file_inclusion_chain, ) assertion = matches_source_location_info( abs_path_of_dir_containing_first_file_path=asrt.equals( the_file_location_info.abs_path_of_dir_containing_first_file_path), source_location_path=equals_source_location_path(expected_source_location_path) ) # ASSERT SANITY # assert 1 == len(instruction.symbol_usages), 'A single symbol should have been defined' symbol_definition = instruction.symbol_usages[0] assert isinstance(symbol_definition, SymbolDefinition) assertion.apply_without_message(self, symbol_definition.symbol_container.source_location)
def __init__(self, recorder: Optional[ListRecorder] = None): super().__init__() self.__recorder = recorder if self.__recorder is None: self.__recorder = ListRecorder() self.ilc = instruction_line_constructor() self.recording_instructions = RecordingInstructionsFactory( self.__recorder) self.__recorders = { PartialPhase.SETUP: self._new_setup_instruction, PartialPhase.BEFORE_ASSERT: self._new_before_assert_instruction, PartialPhase.ASSERT: self._new_assert_instruction, PartialPhase.CLEANUP: self._new_cleanup_instruction } self._element_builder = SectionContentElementBuilder( FileLocationInfo(pathlib.Path.cwd())) self.__extra = {} for ph in PartialPhase: self.__extra[ph] = [] self.__the_extra = {}
import pathlib from typing import List from exactly_lib.section_document import model from exactly_lib.section_document.element_builder import SectionContentElementBuilder from exactly_lib.section_document.model import SectionContentElement, Instruction from exactly_lib.section_document.source_location import SourceLocation, FileLocationInfo from exactly_lib.util import line_source from exactly_lib.util.line_source import Line, LineSequence from exactly_lib_test.section_document.test_resources.element_assertions import InstructionInSection _ELEMENT_BUILDER_WITHOUT_FILE_PATH = SectionContentElementBuilder( FileLocationInfo(pathlib.Path.cwd())) def new_comment_element( source_line: line_source.Line) -> SectionContentElement: return _ELEMENT_BUILDER_WITHOUT_FILE_PATH.new_comment( new_ls_from_line(source_line)) def new_instruction_element(source_line: line_source.Line, instruction: Instruction) -> SectionContentElement: return _ELEMENT_BUILDER_WITHOUT_FILE_PATH.new_instruction( new_ls_from_line(source_line), instruction, None) def new_ls_from_line(line: Line) -> LineSequence: return LineSequence(line.line_number, (line.text, ))
import pathlib from exactly_lib.section_document.source_location import FileLocationInfo, SourceLocationInfo from exactly_lib.util import line_source _FL = FileLocationInfo(pathlib.Path('/')) def single_line_sequence(line_number: int, line: str) -> SourceLocationInfo: return source_info_for_line_sequence( line_source.single_line_sequence(line_number, line)) def source_info_for_line_sequence( source: line_source.LineSequence) -> SourceLocationInfo: return _FL.source_location_info_for(source)
def __init__(self): self._current_line = 1 self._element_builder = SectionContentElementBuilder(FileLocationInfo(pathlib.Path.cwd()))