def parse_file(self, block: FileBlock) -> None: dct = self._yaml_from_file(block.file) # mark the file as seen, even if there are no macros in it self.results.get_file(block.file) if dct: try: dct = self.raw_renderer.render_data(dct) except CompilationException as exc: raise CompilationException( f'Failed to render {block.path.original_file_path} from ' f'project {self.project.project_name}: {exc}') from exc yaml_block = YamlBlock.from_file_block(block, dct) self._parse_format_version(yaml_block) parser: YamlDocsReader for key in NodeType.documentable(): plural = key.pluralize() if key == NodeType.Source: parser = SourceParser(self, yaml_block, plural) elif key == NodeType.Macro: parser = MacroPatchParser(self, yaml_block, plural) elif key == NodeType.Analysis: parser = AnalysisPatchParser(self, yaml_block, plural) else: parser = TestablePatchParser(self, yaml_block, plural) for test_block in parser.parse(): self.parse_tests(test_block)
def parse_file(self, block: FileBlock) -> None: dct = self._yaml_from_file(block.file) # mark the file as seen, even if there are no macros in it self.results.get_file(block.file) if dct: yaml_block = YamlBlock.from_file_block(block, dct) self._parse_format_version(yaml_block) self.parse_yaml_models(yaml_block) self.parse_yaml_sources(yaml_block)
def yaml_block_for(self, test_yml: str, filename: str): file_block = self.file_block_for(data=test_yml, filename=filename) return YamlBlock.from_file_block( src=file_block, data=yaml.safe_load(test_yml), )
def parse_file(self, block: FileBlock) -> None: dct = self._yaml_from_file(block.file) # mark the file as seen, in ParseResult.files self.results.get_file(block.file) if dct: try: # This does a deep_map to check for circular references dct = self.raw_renderer.render_data(dct) except CompilationException as exc: raise CompilationException( f'Failed to render {block.path.original_file_path} from ' f'project {self.project.project_name}: {exc}') from exc # contains the FileBlock and the data (dictionary) yaml_block = YamlBlock.from_file_block(block, dct) # checks version self._check_format_version(yaml_block) parser: YamlDocsReader # There are 7 kinds of parsers: # Model, Seed, Snapshot, Source, Macro, Analysis, Exposures # NonSourceParser.parse(), TestablePatchParser is a variety of # NodePatchParser if 'models' in dct: parser = TestablePatchParser(self, yaml_block, 'models') for test_block in parser.parse(): self.parse_tests(test_block) # NonSourceParser.parse() if 'seeds' in dct: parser = TestablePatchParser(self, yaml_block, 'seeds') for test_block in parser.parse(): self.parse_tests(test_block) # NonSourceParser.parse() if 'snapshots' in dct: parser = TestablePatchParser(self, yaml_block, 'snapshots') for test_block in parser.parse(): self.parse_tests(test_block) # This parser uses SourceParser.parse() which doesn't return # any test blocks. Source tests are handled at a later point # in the process. if 'sources' in dct: parser = SourceParser(self, yaml_block, 'sources') parser.parse() # NonSourceParser.parse() if 'macros' in dct: parser = MacroPatchParser(self, yaml_block, 'macros') for test_block in parser.parse(): self.parse_tests(test_block) # NonSourceParser.parse() if 'analyses' in dct: parser = AnalysisPatchParser(self, yaml_block, 'analyses') for test_block in parser.parse(): self.parse_tests(test_block) # parse exposures if 'exposures' in dct: self.parse_exposures(yaml_block)