16 changed files with 724 additions and 0 deletions
@ -0,0 +1,44 @@ |
|||||
|
# Code blocks { #code-blocks } |
||||
|
|
||||
|
Some text |
||||
|
|
||||
|
```python |
||||
|
# This is a sample Python code block |
||||
|
def hello_world(): |
||||
|
# Comment with indentation |
||||
|
print("Hello, world!") # Print greeting |
||||
|
``` |
||||
|
|
||||
|
Some more text |
||||
|
|
||||
|
```toml |
||||
|
# This is a sample TOML code block |
||||
|
title = "TOML Example" # Title of the document |
||||
|
``` |
||||
|
|
||||
|
And more text |
||||
|
|
||||
|
```console |
||||
|
// Use the command "live" and pass the language code as a CLI argument |
||||
|
$ python ./scripts/docs.py live es |
||||
|
|
||||
|
<span style="color: green;">[INFO]</span> Serving on http://127.0.0.1:8008 |
||||
|
<span style="color: green;">[INFO]</span> Start watching changes |
||||
|
<span style="color: green;">[INFO]</span> Start detecting changes |
||||
|
``` |
||||
|
|
||||
|
And even more text |
||||
|
|
||||
|
```json |
||||
|
{ |
||||
|
// This is a sample JSON code block |
||||
|
"greeting": "Hello, world!" // Greeting |
||||
|
} |
||||
|
``` |
||||
|
|
||||
|
Mermaid diagram |
||||
|
|
||||
|
```mermaid |
||||
|
flowchart LR |
||||
|
stone(philosophers-stone) -->|requires| harry-1[harry v1] |
||||
|
``` |
||||
@ -0,0 +1,45 @@ |
|||||
|
# Code blocks { #code-blocks } |
||||
|
|
||||
|
Some text |
||||
|
|
||||
|
```python |
||||
|
# This is a sample Python code block |
||||
|
def hello_world(): |
||||
|
# Comment with indentation |
||||
|
print("Hello, world!") # Print greeting |
||||
|
``` |
||||
|
|
||||
|
Some more text |
||||
|
|
||||
|
```toml |
||||
|
# Extra line |
||||
|
# This is a sample TOML code block |
||||
|
title = "TOML Example" # Title of the document |
||||
|
``` |
||||
|
|
||||
|
And more text |
||||
|
|
||||
|
```console |
||||
|
// Use the command "live" and pass the language code as a CLI argument |
||||
|
$ python ./scripts/docs.py live es |
||||
|
|
||||
|
<span style="color: green;">[INFO]</span> Serving on http://127.0.0.1:8008 |
||||
|
<span style="color: green;">[INFO]</span> Start watching changes |
||||
|
<span style="color: green;">[INFO]</span> Start detecting changes |
||||
|
``` |
||||
|
|
||||
|
And even more text |
||||
|
|
||||
|
```json |
||||
|
{ |
||||
|
// This is a sample JSON code block |
||||
|
"greeting": "Hello, world!" // Greeting |
||||
|
} |
||||
|
``` |
||||
|
|
||||
|
Диаграма Mermaid |
||||
|
|
||||
|
```mermaid |
||||
|
flowchart LR |
||||
|
stone(philosophers-stone) -->|requires| harry-1[harry v1] |
||||
|
``` |
||||
@ -0,0 +1,45 @@ |
|||||
|
# Code blocks { #code-blocks } |
||||
|
|
||||
|
Some text |
||||
|
|
||||
|
```python |
||||
|
# This is a sample Python code block |
||||
|
def hello_world(): |
||||
|
# Comment with indentation |
||||
|
print("Hello, world!") # Print greeting |
||||
|
``` |
||||
|
|
||||
|
Some more text |
||||
|
|
||||
|
The following block is missing first line: |
||||
|
|
||||
|
```toml |
||||
|
title = "TOML Example" # Title of the document |
||||
|
``` |
||||
|
|
||||
|
And more text |
||||
|
|
||||
|
```console |
||||
|
// Use the command "live" and pass the language code as a CLI argument |
||||
|
$ python ./scripts/docs.py live es |
||||
|
|
||||
|
<span style="color: green;">[INFO]</span> Serving on http://127.0.0.1:8008 |
||||
|
<span style="color: green;">[INFO]</span> Start watching changes |
||||
|
<span style="color: green;">[INFO]</span> Start detecting changes |
||||
|
``` |
||||
|
|
||||
|
And even more text |
||||
|
|
||||
|
```json |
||||
|
{ |
||||
|
// This is a sample JSON code block |
||||
|
"greeting": "Hello, world!" // Greeting |
||||
|
} |
||||
|
``` |
||||
|
|
||||
|
Диаграма Mermaid |
||||
|
|
||||
|
```mermaid |
||||
|
flowchart LR |
||||
|
stone(philosophers-stone) -->|requires| harry-1[harry v1] |
||||
|
``` |
||||
@ -0,0 +1,44 @@ |
|||||
|
# Code blocks { #code-blocks } |
||||
|
|
||||
|
Some text |
||||
|
|
||||
|
```python |
||||
|
# This is a sample Python code block |
||||
|
def hello_world(): |
||||
|
# Comment with indentation |
||||
|
print("Hello, world!") # Print greeting |
||||
|
``` |
||||
|
|
||||
|
Some more text |
||||
|
|
||||
|
```toml |
||||
|
# This is a sample TOML code block |
||||
|
title = "TOML Example" # Title of the document |
||||
|
``` |
||||
|
|
||||
|
And more text |
||||
|
|
||||
|
```console |
||||
|
// Use the command "live" and pass the language code as a CLI argument |
||||
|
$ python ./scripts/docs.py live es |
||||
|
|
||||
|
<span style="color: green;">[INFO]</span> Serving on http://127.0.0.1:8008 |
||||
|
<span style="color: green;">[INFO]</span> Start watching changes |
||||
|
<span style="color: green;">[INFO]</span> Start detecting changes |
||||
|
``` |
||||
|
|
||||
|
And even more text |
||||
|
|
||||
|
```json |
||||
|
{ |
||||
|
// This is a sample JSON code block |
||||
|
"greeting": "Hello, world!" // Greeting |
||||
|
} |
||||
|
``` |
||||
|
|
||||
|
Диаграма Mermaid |
||||
|
|
||||
|
```mermaid |
||||
|
flowchart LR |
||||
|
stone(philosophers-stone) -->|requires| harry-1[harry v1] |
||||
|
``` |
||||
@ -0,0 +1,44 @@ |
|||||
|
# Code blocks { #code-blocks } |
||||
|
|
||||
|
Some text |
||||
|
|
||||
|
```python |
||||
|
# This is a sample Python code block |
||||
|
def hello_world(): |
||||
|
# Comment with indentation |
||||
|
print("Hello, world!") # Print greeting |
||||
|
``` |
||||
|
|
||||
|
Some more text |
||||
|
|
||||
|
```toml |
||||
|
# This is a sample TOML code block |
||||
|
title = "TOML Example" # Title of the document |
||||
|
``` |
||||
|
|
||||
|
And more text |
||||
|
|
||||
|
```console |
||||
|
// Use the command "live" and pass the language code as a CLI argument |
||||
|
$ python ./scripts/docs.py live es |
||||
|
|
||||
|
<span style="color: green;">[INFO]</span> Serving on http://127.0.0.1:8008 |
||||
|
<span style="color: green;">[INFO]</span> Start watching changes |
||||
|
<span style="color: green;">[INFO]</span> Start detecting changes |
||||
|
``` |
||||
|
|
||||
|
And even more text |
||||
|
|
||||
|
```json |
||||
|
{ |
||||
|
// This is a sample JSON code block |
||||
|
"greeting": "Hello, world!" // Greeting |
||||
|
} |
||||
|
``` |
||||
|
|
||||
|
Диаграма Mermaid |
||||
|
|
||||
|
```mermaid |
||||
|
flowchart LR |
||||
|
stone(philosophers-stone) -->|требует| harry-1[harry v1] |
||||
|
``` |
||||
@ -0,0 +1,50 @@ |
|||||
|
# Code blocks { #code-blocks } |
||||
|
|
||||
|
Some text |
||||
|
|
||||
|
```python |
||||
|
# This is a sample Python code block |
||||
|
def hello_world(): |
||||
|
# Comment with indentation |
||||
|
print("Hello, world!") # Print greeting |
||||
|
``` |
||||
|
|
||||
|
Some more text |
||||
|
|
||||
|
```toml |
||||
|
# This is a sample TOML code block |
||||
|
title = "TOML Example" # Title of the document |
||||
|
``` |
||||
|
|
||||
|
Extra code block |
||||
|
|
||||
|
``` |
||||
|
$ cd my_project |
||||
|
``` |
||||
|
|
||||
|
And more text |
||||
|
|
||||
|
```console |
||||
|
// Use the command "live" and pass the language code as a CLI argument |
||||
|
$ python ./scripts/docs.py live es |
||||
|
|
||||
|
<span style="color: green;">[INFO]</span> Serving on http://127.0.0.1:8008 |
||||
|
<span style="color: green;">[INFO]</span> Start watching changes |
||||
|
<span style="color: green;">[INFO]</span> Start detecting changes |
||||
|
``` |
||||
|
|
||||
|
And even more text |
||||
|
|
||||
|
```json |
||||
|
{ |
||||
|
// This is a sample JSON code block |
||||
|
"greeting": "Hello, world!" // Greeting |
||||
|
} |
||||
|
``` |
||||
|
|
||||
|
Диаграма Mermaid |
||||
|
|
||||
|
```mermaid |
||||
|
flowchart LR |
||||
|
stone(philosophers-stone) -->|requires| harry-1[harry v1] |
||||
|
``` |
||||
@ -0,0 +1,41 @@ |
|||||
|
# Code blocks { #code-blocks } |
||||
|
|
||||
|
Some text |
||||
|
|
||||
|
```python |
||||
|
# This is a sample Python code block |
||||
|
def hello_world(): |
||||
|
# Comment with indentation |
||||
|
print("Hello, world!") # Print greeting |
||||
|
``` |
||||
|
|
||||
|
Some more text |
||||
|
|
||||
|
Missing code block... |
||||
|
|
||||
|
And more text |
||||
|
|
||||
|
```console |
||||
|
// Use the command "live" and pass the language code as a CLI argument |
||||
|
$ python ./scripts/docs.py live es |
||||
|
|
||||
|
<span style="color: green;">[INFO]</span> Serving on http://127.0.0.1:8008 |
||||
|
<span style="color: green;">[INFO]</span> Start watching changes |
||||
|
<span style="color: green;">[INFO]</span> Start detecting changes |
||||
|
``` |
||||
|
|
||||
|
And even more text |
||||
|
|
||||
|
```json |
||||
|
{ |
||||
|
// This is a sample JSON code block |
||||
|
"greeting": "Hello, world!" // Greeting |
||||
|
} |
||||
|
``` |
||||
|
|
||||
|
Диаграма Mermaid |
||||
|
|
||||
|
```mermaid |
||||
|
flowchart LR |
||||
|
stone(philosophers-stone) -->|requires| harry-1[harry v1] |
||||
|
``` |
||||
@ -0,0 +1,46 @@ |
|||||
|
# Code blocks { #code-blocks } |
||||
|
|
||||
|
Some text |
||||
|
|
||||
|
```python |
||||
|
# This is a sample Python code block |
||||
|
def hello_world(): |
||||
|
# Comment with indentation |
||||
|
print("Hello, world!") # Print greeting |
||||
|
``` |
||||
|
|
||||
|
Some more text |
||||
|
|
||||
|
The following block has wrong language code (should be TOML): |
||||
|
|
||||
|
```yaml |
||||
|
# This is a sample TOML code block |
||||
|
title = "TOML Example" # Title of the document |
||||
|
``` |
||||
|
|
||||
|
And more text |
||||
|
|
||||
|
```console |
||||
|
// Use the command "live" and pass the language code as a CLI argument |
||||
|
$ python ./scripts/docs.py live es |
||||
|
|
||||
|
<span style="color: green;">[INFO]</span> Serving on http://127.0.0.1:8008 |
||||
|
<span style="color: green;">[INFO]</span> Start watching changes |
||||
|
<span style="color: green;">[INFO]</span> Start detecting changes |
||||
|
``` |
||||
|
|
||||
|
And even more text |
||||
|
|
||||
|
```json |
||||
|
{ |
||||
|
// This is a sample JSON code block |
||||
|
"greeting": "Hello, world!" // Greeting |
||||
|
} |
||||
|
``` |
||||
|
|
||||
|
Диаграма Mermaid |
||||
|
|
||||
|
```mermaid |
||||
|
flowchart LR |
||||
|
stone(philosophers-stone) -->|requires| harry-1[harry v1] |
||||
|
``` |
||||
@ -0,0 +1,46 @@ |
|||||
|
# Code blocks { #code-blocks } |
||||
|
|
||||
|
Some text |
||||
|
|
||||
|
```python |
||||
|
# This is a sample Python code block |
||||
|
def hello_world(): |
||||
|
# Comment with indentation |
||||
|
print("Hello, world!") # Print greeting |
||||
|
``` |
||||
|
|
||||
|
Some more text |
||||
|
|
||||
|
The following block has wrong language code (should be TOML): |
||||
|
|
||||
|
``` |
||||
|
# This is a sample TOML code block |
||||
|
title = "TOML Example" # Title of the document |
||||
|
``` |
||||
|
|
||||
|
And more text |
||||
|
|
||||
|
```console |
||||
|
// Use the command "live" and pass the language code as a CLI argument |
||||
|
$ python ./scripts/docs.py live es |
||||
|
|
||||
|
<span style="color: green;">[INFO]</span> Serving on http://127.0.0.1:8008 |
||||
|
<span style="color: green;">[INFO]</span> Start watching changes |
||||
|
<span style="color: green;">[INFO]</span> Start detecting changes |
||||
|
``` |
||||
|
|
||||
|
And even more text |
||||
|
|
||||
|
```json |
||||
|
{ |
||||
|
// This is a sample JSON code block |
||||
|
"greeting": "Hello, world!" // Greeting |
||||
|
} |
||||
|
``` |
||||
|
|
||||
|
Диаграма Mermaid |
||||
|
|
||||
|
```mermaid |
||||
|
flowchart LR |
||||
|
stone(philosophers-stone) -->|requires| harry-1[harry v1] |
||||
|
``` |
||||
@ -0,0 +1,54 @@ |
|||||
|
from pathlib import Path |
||||
|
|
||||
|
import pytest |
||||
|
from typer.testing import CliRunner |
||||
|
|
||||
|
from scripts.translation_fixer import cli |
||||
|
|
||||
|
data_path = Path( |
||||
|
"scripts/tests/test_translation_fixer/test_code_blocks/data" |
||||
|
).absolute() |
||||
|
|
||||
|
|
||||
|
@pytest.mark.parametrize( |
||||
|
"copy_test_files", |
||||
|
[(f"{data_path}/en_doc.md", f"{data_path}/translated_doc_lines_number_gt.md")], |
||||
|
indirect=True, |
||||
|
) |
||||
|
def test_gt(runner: CliRunner, root_dir: Path, copy_test_files): |
||||
|
result = runner.invoke( |
||||
|
cli, |
||||
|
["fix-pages", "docs/lang/docs/doc.md"], |
||||
|
) |
||||
|
assert result.exit_code == 1, result.output |
||||
|
|
||||
|
fixed_content = (root_dir / "docs" / "lang" / "docs" / "doc.md").read_text() |
||||
|
expected_content = Path(f"{data_path}/translated_doc_lines_number_gt.md").read_text() |
||||
|
|
||||
|
assert fixed_content == expected_content # Translated doc remains unchanged |
||||
|
assert "Error processing docs/lang/docs/doc.md" in result.output |
||||
|
assert ( |
||||
|
"Code block has different number of lines than the original block (5 vs 4)" |
||||
|
) in result.output |
||||
|
|
||||
|
|
||||
|
@pytest.mark.parametrize( |
||||
|
"copy_test_files", |
||||
|
[(f"{data_path}/en_doc.md", f"{data_path}/translated_doc_lines_number_lt.md")], |
||||
|
indirect=True, |
||||
|
) |
||||
|
def test_lt(runner: CliRunner, root_dir: Path, copy_test_files): |
||||
|
result = runner.invoke( |
||||
|
cli, |
||||
|
["fix-pages", "docs/lang/docs/doc.md"], |
||||
|
) |
||||
|
# assert result.exit_code == 1, result.output |
||||
|
|
||||
|
fixed_content = (root_dir / "docs" / "lang" / "docs" / "doc.md").read_text() |
||||
|
expected_content = Path(f"{data_path}/translated_doc_lines_number_lt.md").read_text() |
||||
|
|
||||
|
assert fixed_content == expected_content # Translated doc remains unchanged |
||||
|
assert "Error processing docs/lang/docs/doc.md" in result.output |
||||
|
assert ( |
||||
|
"Code block has different number of lines than the original block (3 vs 4)" |
||||
|
) in result.output |
||||
@ -0,0 +1,53 @@ |
|||||
|
from pathlib import Path |
||||
|
|
||||
|
import pytest |
||||
|
from typer.testing import CliRunner |
||||
|
|
||||
|
from scripts.translation_fixer import cli |
||||
|
|
||||
|
data_path = Path( |
||||
|
"scripts/tests/test_translation_fixer/test_code_blocks/data" |
||||
|
).absolute() |
||||
|
|
||||
|
|
||||
|
@pytest.mark.parametrize( |
||||
|
"copy_test_files", |
||||
|
[(f"{data_path}/en_doc.md", f"{data_path}/translated_doc_mermaid_translated.md")], |
||||
|
indirect=True, |
||||
|
) |
||||
|
def test_translated(runner: CliRunner, root_dir: Path, copy_test_files): |
||||
|
result = runner.invoke( |
||||
|
cli, |
||||
|
["fix-pages", "docs/lang/docs/doc.md"], |
||||
|
) |
||||
|
assert result.exit_code == 0, result.output |
||||
|
|
||||
|
fixed_content = (root_dir / "docs" / "lang" / "docs" / "doc.md").read_text() |
||||
|
expected_content = Path(f"{data_path}/translated_doc_mermaid_translated.md").read_text() |
||||
|
|
||||
|
assert fixed_content == expected_content # Translated doc remains unchanged |
||||
|
assert ( |
||||
|
"Skipping mermaid code block replacement. This should be checked manually." |
||||
|
) in result.output |
||||
|
|
||||
|
|
||||
|
|
||||
|
@pytest.mark.parametrize( |
||||
|
"copy_test_files", |
||||
|
[(f"{data_path}/en_doc.md", f"{data_path}/translated_doc_mermaid_not_translated.md")], |
||||
|
indirect=True, |
||||
|
) |
||||
|
def test_not_translated(runner: CliRunner, root_dir: Path, copy_test_files): |
||||
|
result = runner.invoke( |
||||
|
cli, |
||||
|
["fix-pages", "docs/lang/docs/doc.md"], |
||||
|
) |
||||
|
assert result.exit_code == 0, result.output |
||||
|
|
||||
|
fixed_content = (root_dir / "docs" / "lang" / "docs" / "doc.md").read_text() |
||||
|
expected_content = Path(f"{data_path}/translated_doc_mermaid_not_translated.md").read_text() |
||||
|
|
||||
|
assert fixed_content == expected_content # Translated doc remains unchanged |
||||
|
assert ( |
||||
|
"Skipping mermaid code block replacement. This should be checked manually." |
||||
|
) not in result.output |
||||
@ -0,0 +1,56 @@ |
|||||
|
from pathlib import Path |
||||
|
|
||||
|
import pytest |
||||
|
from typer.testing import CliRunner |
||||
|
|
||||
|
from scripts.translation_fixer import cli |
||||
|
|
||||
|
data_path = Path( |
||||
|
"scripts/tests/test_translation_fixer/test_code_blocks/data" |
||||
|
).absolute() |
||||
|
|
||||
|
|
||||
|
@pytest.mark.parametrize( |
||||
|
"copy_test_files", |
||||
|
[(f"{data_path}/en_doc.md", f"{data_path}/translated_doc_number_gt.md")], |
||||
|
indirect=True, |
||||
|
) |
||||
|
def test_gt(runner: CliRunner, root_dir: Path, copy_test_files): |
||||
|
result = runner.invoke( |
||||
|
cli, |
||||
|
["fix-pages", "docs/lang/docs/doc.md"], |
||||
|
) |
||||
|
assert result.exit_code == 1, result.output |
||||
|
|
||||
|
fixed_content = (root_dir / "docs" / "lang" / "docs" / "doc.md").read_text() |
||||
|
expected_content = Path(f"{data_path}/translated_doc_number_gt.md").read_text() |
||||
|
|
||||
|
assert fixed_content == expected_content # Translated doc remains unchanged |
||||
|
assert "Error processing docs/lang/docs/doc.md" in result.output |
||||
|
assert ( |
||||
|
"Number of code blocks does not match the number " |
||||
|
"in the original document (6 vs 5)" |
||||
|
) in result.output |
||||
|
|
||||
|
|
||||
|
@pytest.mark.parametrize( |
||||
|
"copy_test_files", |
||||
|
[(f"{data_path}/en_doc.md", f"{data_path}/translated_doc_number_lt.md")], |
||||
|
indirect=True, |
||||
|
) |
||||
|
def test_lt(runner: CliRunner, root_dir: Path, copy_test_files): |
||||
|
result = runner.invoke( |
||||
|
cli, |
||||
|
["fix-pages", "docs/lang/docs/doc.md"], |
||||
|
) |
||||
|
# assert result.exit_code == 1, result.output |
||||
|
|
||||
|
fixed_content = (root_dir / "docs" / "lang" / "docs" / "doc.md").read_text() |
||||
|
expected_content = Path(f"{data_path}/translated_doc_number_lt.md").read_text() |
||||
|
|
||||
|
assert fixed_content == expected_content # Translated doc remains unchanged |
||||
|
assert "Error processing docs/lang/docs/doc.md" in result.output |
||||
|
assert ( |
||||
|
"Number of code blocks does not match the number " |
||||
|
"in the original document (4 vs 5)" |
||||
|
) in result.output |
||||
@ -0,0 +1,55 @@ |
|||||
|
from pathlib import Path |
||||
|
|
||||
|
import pytest |
||||
|
from typer.testing import CliRunner |
||||
|
|
||||
|
from scripts.translation_fixer import cli |
||||
|
|
||||
|
data_path = Path( |
||||
|
"scripts/tests/test_translation_fixer/test_code_blocks/data" |
||||
|
).absolute() |
||||
|
|
||||
|
|
||||
|
@pytest.mark.parametrize( |
||||
|
"copy_test_files", |
||||
|
[(f"{data_path}/en_doc.md", f"{data_path}/translated_doc_wrong_lang_code.md")], |
||||
|
indirect=True, |
||||
|
) |
||||
|
def test_wrong_lang_code_1(runner: CliRunner, root_dir: Path, copy_test_files): |
||||
|
result = runner.invoke( |
||||
|
cli, |
||||
|
["fix-pages", "docs/lang/docs/doc.md"], |
||||
|
) |
||||
|
assert result.exit_code == 1, result.output |
||||
|
|
||||
|
fixed_content = (root_dir / "docs" / "lang" / "docs" / "doc.md").read_text() |
||||
|
expected_content = Path(f"{data_path}/translated_doc_wrong_lang_code.md").read_text() |
||||
|
|
||||
|
assert fixed_content == expected_content # Translated doc remains unchanged |
||||
|
assert "Error processing docs/lang/docs/doc.md" in result.output |
||||
|
assert ( |
||||
|
"Code block has different language than the original block ('yaml' vs 'toml')" |
||||
|
) in result.output |
||||
|
|
||||
|
|
||||
|
|
||||
|
@pytest.mark.parametrize( |
||||
|
"copy_test_files", |
||||
|
[(f"{data_path}/en_doc.md", f"{data_path}/translated_doc_wrong_lang_code_2.md")], |
||||
|
indirect=True, |
||||
|
) |
||||
|
def test_wrong_lang_code_2(runner: CliRunner, root_dir: Path, copy_test_files): |
||||
|
result = runner.invoke( |
||||
|
cli, |
||||
|
["fix-pages", "docs/lang/docs/doc.md"], |
||||
|
) |
||||
|
assert result.exit_code == 1, result.output |
||||
|
|
||||
|
fixed_content = (root_dir / "docs" / "lang" / "docs" / "doc.md").read_text() |
||||
|
expected_content = Path(f"{data_path}/translated_doc_wrong_lang_code_2.md").read_text() |
||||
|
|
||||
|
assert fixed_content == expected_content # Translated doc remains unchanged |
||||
|
assert "Error processing docs/lang/docs/doc.md" in result.output |
||||
|
assert ( |
||||
|
"Code block has different language than the original block ('' vs 'toml')" |
||||
|
) in result.output |
||||
Loading…
Reference in new issue