|
| 1 | +from pathlib import Path, PurePath |
| 2 | +from typing import Dict, Tuple, List |
| 3 | +from .steps import GizaStepsCategory |
| 4 | +from .nodes import ast_to_testing_string |
| 5 | +from ..types import Diagnostic, Page, EmbeddedRstParser, ProjectConfig |
| 6 | +from ..parser import make_embedded_rst_parser |
| 7 | + |
| 8 | + |
| 9 | +def test_step() -> None: |
| 10 | + project_path, project_config, project_diagnostics = ProjectConfig.open(Path('test_data')) |
| 11 | + assert project_diagnostics == [] |
| 12 | + |
| 13 | + category = GizaStepsCategory(project_config) |
| 14 | + path = Path('test_data/steps-test.yaml') |
| 15 | + child_path = Path('test_data/steps-test-child.yaml') |
| 16 | + |
| 17 | + def add_main_file() -> List[Diagnostic]: |
| 18 | + steps, text, parse_diagnostics = category.parse(path) |
| 19 | + category.add(path, text, steps) |
| 20 | + assert len(parse_diagnostics) == 0 |
| 21 | + assert len(steps) == 4 |
| 22 | + return parse_diagnostics |
| 23 | + |
| 24 | + def add_child_file() -> List[Diagnostic]: |
| 25 | + steps, text, parse_diagnostics = category.parse(child_path) |
| 26 | + category.add(child_path, text, steps) |
| 27 | + assert len(parse_diagnostics) == 0 |
| 28 | + return parse_diagnostics |
| 29 | + |
| 30 | + all_diagnostics: Dict[PurePath, List[Diagnostic]] = {} |
| 31 | + all_diagnostics[path] = add_main_file() |
| 32 | + all_diagnostics[child_path] = add_child_file() |
| 33 | + |
| 34 | + file_id, giza_node = next(category.reify_all_files(all_diagnostics)) |
| 35 | + |
| 36 | + def create_page() -> Tuple[Page, EmbeddedRstParser]: |
| 37 | + page = Page(path, '', {}) |
| 38 | + return page, make_embedded_rst_parser(project_config, page, all_diagnostics[path]) |
| 39 | + |
| 40 | + pages = category.to_pages(create_page, giza_node.data) |
| 41 | + assert len(pages) == 1 |
| 42 | + print(repr(ast_to_testing_string(pages[0].ast))) |
| 43 | + assert ast_to_testing_string(pages[0].ast) == ''.join(( |
| 44 | + '<directive name="steps"><directive name="step"><section><heading><text>Import the public ', |
| 45 | + 'key used by the package management system.</text></heading><paragraph><text>Issue the ', |
| 46 | + 'following command to import the\n</text><reference><text>MongoDB public GPG Key</text>', |
| 47 | + '</reference><target ids="[\'mongodb-public-gpg-key\']"></target></paragraph></section>', |
| 48 | + '</directive>', |
| 49 | + |
| 50 | + '<directive name="step"><section><heading><text>Create a </text><literal><text>', |
| 51 | + '/etc/apt/sources.list.d/mongodb-org-3.4.list</text></literal><text> file for MongoDB.', |
| 52 | + '</text></heading><paragraph><text>Create the list file using the command appropriate for ', |
| 53 | + 'your version\nof Debian.</text></paragraph></section></directive>', |
| 54 | + |
| 55 | + '<directive name="step"><section><heading><text>Reload local package database.</text>', |
| 56 | + '</heading><paragraph><text>Issue the following command to reload the local package ', |
| 57 | + 'database:</text></paragraph><code lang="sh" copyable="True">sudo apt-get update\n</code>', |
| 58 | + '</section></directive>', |
| 59 | + |
| 60 | + '<directive name="step"><section><heading><text>Install the MongoDB packages.</text>', |
| 61 | + '</heading><paragraph><text>You can install either the latest stable version of MongoDB ', |
| 62 | + 'or a\nspecific version of MongoDB.</text></paragraph>', |
| 63 | + '<directive name="code-block">', |
| 64 | + '<text>sh</text><literal></literal></directive></section></directive></directive>' |
| 65 | + )) |
0 commit comments