예제 #1
0
    def test_multiple_raw_blocks(self):
        parser = docs.DocumentationParser(
            results=ParseResult.rpc(),
            root_project=self.root_project_config,
            project=self.subdir_project_config,
            macro_manifest=Manifest.from_macros())

        file_block = self._build_file(MULTIPLE_RAW_BLOCKS, 'test_file.md')

        parser.parse_file(file_block)
        results = sorted(parser.results.docs.values(), key=lambda n: n.name)
        self.assertEqual(len(results), 2)
        for result in results:
            self.assertIsInstance(result, ParsedDocumentation)
            self.assertEqual(result.package_name, 'some_package')
            self.assertEqual(result.original_file_path, self.testfile_path)
            self.assertEqual(result.root_path, self.subdir_path)
            self.assertEqual(result.resource_type, NodeType.Documentation)
            self.assertEqual(result.path, 'test_file.md')

        self.assertEqual(results[0].name, 'other_doc')
        self.assertEqual(results[0].block_contents,
                         '```\n    {% docs %}other doc{% enddocs %}\n    ```')
        self.assertEqual(results[1].name, 'some_doc')
        self.assertEqual(
            results[1].block_contents,
            '```\n    {% docs %}some doc{% enddocs %}\n    ```',
        )
예제 #2
0
    def test_load_file(self):
        parser = docs.DocumentationParser(
            results=ParseResult.rpc(),
            root_project=self.root_project_config,
            project=self.subdir_project_config,
            macro_manifest=Manifest.from_macros())

        file_block = self._build_file(TEST_DOCUMENTATION_FILE, 'test_file.md')

        parser.parse_file(file_block)
        results = sorted(parser.results.docs.values(), key=lambda n: n.name)
        self.assertEqual(len(results), 2)
        for result in results:
            self.assertIsInstance(result, ParsedDocumentation)
            self.assertEqual(result.package_name, 'some_package')
            self.assertNotEqual(result.file_contents, TEST_DOCUMENTATION_FILE)
            self.assertEqual(result.original_file_path, self.testfile_path)
            self.assertEqual(result.root_path, self.subdir_path)
            self.assertEqual(result.resource_type, NodeType.Documentation)
            self.assertEqual(result.path, 'test_file.md')

        self.assertEqual(results[0].name, 'snowplow_sessions')
        self.assertEqual(results[0].file_contents, SNOWPLOW_SESSIONS_BLOCK)
        self.assertEqual(results[1].name, 'snowplow_sessions__session_id')
        self.assertEqual(results[1].file_contents,
                         SNOWPLOW_SESSIONS_SESSION_ID_BLOCK)
예제 #3
0
    def test_parse(self):
        docfile = UnparsedDocumentationFile(
            root_path=self.root_path,
            resource_type=NodeType.Documentation,
            path='test_file.md',
            original_file_path=self.testfile_path,
            package_name='some_package',
            file_contents=TEST_DOCUMENTATION_FILE)
        all_projects = {
            'root': self.root_project_config,
            'some_package': self.subdir_project_config
        }
        parser = docs.DocumentationParser(self.root_project_config,
                                          all_projects)
        parsed = list(parser.parse(docfile))
        parsed.sort(key=lambda x: x.name)

        self.assertEqual(len(parsed), 2)
        table = parsed[0]
        column = parsed[1]
        self.assertEqual(table.name, 'snowplow_sessions')
        self.assertEqual(table.unique_id, 'some_package.snowplow_sessions')
        self.assertEqual(table.block_contents, SNOWPLOW_SESSIONS_DOCS.strip())

        self.assertEqual(column.name, 'snowplow_sessions__session_id')
        self.assertEqual(column.unique_id,
                         'some_package.snowplow_sessions__session_id')
        self.assertEqual(column.block_contents,
                         SNOWPLOW_SESSIONS_SESSION_ID_DOCS.strip())
예제 #4
0
    def test_load_file_extras(self):
        TEST_DOCUMENTATION_FILE + '{% model foo %}select 1 as id{% endmodel %}'

        parser = docs.DocumentationParser(
            results=ParseResult.rpc(),
            root_project=self.root_project_config,
            project=self.subdir_project_config,
            macro_manifest=Manifest.from_macros())

        file_block = self._build_file(TEST_DOCUMENTATION_FILE, 'test_file.md')

        parser.parse_file(file_block)
        results = sorted(parser.results.docs.values(), key=lambda n: n.name)
        self.assertEqual(len(results), 2)
        for result in results:
            self.assertIsInstance(result, ParsedDocumentation)
        self.assertEqual(results[0].name, 'snowplow_sessions')
        self.assertEqual(results[1].name, 'snowplow_sessions__session_id')