-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconftest.py
More file actions
90 lines (67 loc) · 2.25 KB
/
conftest.py
File metadata and controls
90 lines (67 loc) · 2.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
from io import StringIO
from typing import Callable
import pytest
from mdtable.core import generate_md_table
@pytest.fixture
def sample_table() -> list[list[str]]:
"""
Provide a sample table fixture for testing Markdown table formatting.
Returns:
List[List[str]]: A list of rows, where each row is a list of string cells.
"""
return [
["Name", "Age", "City"],
["Alice", "30", "NYC"],
["Bob", "25", "LA"],
["Charlie", "35", "Chicago"],
]
@pytest.fixture
def markdown_output(sample_table: list[list[str]]) -> str:
"""
Generate the expected Markdown-formatted output for a sample table.
Parameters:
sample_table (List[List[str]]): A list of rows, where each row is a list of
string cells.
Returns:
str: The expected Markdown output as a string.
"""
return generate_md_table(sample_table)
@pytest.fixture
def malformed_table() -> list[list[str]]:
"""
Provide a malformed table fixture for testing error handling and formatting edge
cases.
Returns:
List[List[str]]: A list of rows, where each row is a list of string cells.
"""
return [
["Name", "Age"],
["Alice", "30", "NYC"], # Extra column
["Bob"], # Missing column
]
@pytest.fixture
def cli_args(monkeypatch: pytest.MonkeyPatch) -> Callable:
"""
Provide a helper function to inject CLI arguments using monkeypatching.
Parameters:
monkeypatch (pytest.MonkeyPatch): Fixture for safely patching built-ins and
environment during the test.
Returns:
Callable: A function that sets sys.argv to simulate CLI input.
"""
def _inject(args):
monkeypatch.setattr("sys.argv", ["mdtable"] + args)
return _inject
@pytest.fixture
def capture_stdout(monkeypatch: pytest.MonkeyPatch) -> StringIO:
"""
Provide a fixture to capture stdout output during tests using monkeypatching.
Parameters:
monkeypatch (pytest.MonkeyPatch): Fixture for safely patching built-ins and
environment during the test.
Returns:
StringIO: A StringIO object that captures printed output from sys.stdout.
"""
buffer = StringIO()
monkeypatch.setattr("sys.stdout", buffer)
return buffer