Skip to content

Commit 731e0f8

Browse files
committed
add fail_on_diagnostic toml flag
1 parent e411b69 commit 731e0f8

File tree

4 files changed

+37
-6
lines changed

4 files changed

+37
-6
lines changed

snooty/main.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
import watchdog.events
2626
import watchdog.observers
2727
from pathlib import Path, PurePath
28-
from typing import Any, Dict, List, Optional, Union
28+
from typing import Any, Dict, List, Optional, Union, Sequence
2929
from docopt import docopt
3030

3131
from . import language_server
@@ -39,6 +39,7 @@
3939
logger = logging.getLogger(__name__)
4040
SNOOTY_ENV = os.getenv("SNOOTY_ENV", "development")
4141
PACKAGE_ROOT = Path(sys.modules["snooty"].__file__).resolve().parent
42+
4243
if PACKAGE_ROOT.is_file():
4344
PACKAGE_ROOT = PACKAGE_ROOT.parent
4445

@@ -82,6 +83,7 @@ def dispatch(self, event: watchdog.events.FileSystemEvent) -> None:
8283

8384

8485
class Backend:
86+
8587
def __init__(self) -> None:
8688
self.total_errors = 0
8789

@@ -249,9 +251,10 @@ def _generate_build_identifiers(args: Dict[str, Optional[str]]) -> BuildIdentifi
249251
return identifiers
250252

251253

252-
def main() -> None:
254+
def main(argv: Optional[Sequence[str]] = None) -> None:
253255
# docopt will terminate here and display usage instructions if snooty is run improperly
254-
args = docopt(__doc__)
256+
print(argv)
257+
args = docopt(__doc__, argv)
255258

256259
logging.basicConfig(level=logging.INFO)
257260

@@ -263,6 +266,7 @@ def main() -> None:
263266
return
264267

265268
url = args["<mongodb-url>"]
269+
266270
connection = (
267271
None if not url else pymongo.MongoClient(url, password=getpass.getpass())
268272
)
@@ -288,5 +292,11 @@ def main() -> None:
288292
print("Closing connection...")
289293
connection.close()
290294

295+
if(project.config.fail_on_diagnostics):
296+
EXIT_STATUS_ERROR_DIAGNOSTICS = 1
297+
#print("TOTAL ERRORS: ", project.config.fail_on_diagnostics, "\n\n cheese")
298+
print(backend.total_errors)
299+
assert False
300+
291301
if args["build"] and backend.total_errors > 0:
292302
sys.exit(EXIT_STATUS_ERROR_DIAGNOSTICS)

snooty/test_main.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import os
22
import json
33
import builtins
4+
import subprocess
5+
from subprocess import run
6+
from pathlib import Path
47
from typing import Any, List
58
from .types import FileId
69
from .diagnostics import InvalidLiteralInclude, InvalidURL, UnknownSubstitution
@@ -72,3 +75,8 @@ def test_print(*values: Any, **kwargs: Any) -> None:
7275
}
7376
},
7477
]
78+
79+
def test_main():
80+
subprocess.call(["snooty", "build", "test_data/test_parser_failure"])
81+
#subprocess.call(["ls", "-l"])
82+
#main.main(["build", 'test_data'])

snooty/test_parser.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
def test_tabs() -> None:
2424
tabs_path = ROOT_PATH.joinpath(Path("test_tabs.rst"))
2525
project_config = ProjectConfig(ROOT_PATH, "")
26+
print(project_config)
27+
assert False
2628
parser = rstparser.Parser(project_config, JSONVisitor)
2729
page, diagnostics = parse_rst(parser, tabs_path, None)
2830
page.finish(diagnostics)
@@ -86,6 +88,8 @@ def test_tabs_invalid_yaml() -> None:
8688
def test_codeblock() -> None:
8789
tabs_path = ROOT_PATH.joinpath(Path("test.rst"))
8890
project_config = ProjectConfig(ROOT_PATH, "")
91+
print(project_config)
92+
assert False
8993
parser = rstparser.Parser(project_config, JSONVisitor)
9094

9195
# Test a simple code-block
@@ -166,8 +170,9 @@ def test_codeblock() -> None:
166170
def test_literalinclude() -> None:
167171
path = ROOT_PATH.joinpath(Path("test.rst"))
168172
project_config = ProjectConfig(ROOT_PATH, "", source="./")
173+
print(ProjectConfig.open(path))
169174
parser = rstparser.Parser(project_config, JSONVisitor)
170-
175+
171176
# Test a simple literally-included code block
172177
page, diagnostics = parse_rst(
173178
parser,
@@ -177,6 +182,7 @@ def test_literalinclude() -> None:
177182
""",
178183
)
179184
page.finish(diagnostics)
185+
print(parser.project_config.open(ROOT_PATH))
180186
assert diagnostics == []
181187
check_ast_testing_string(
182188
page.ast,
@@ -207,6 +213,7 @@ def test_literalinclude() -> None:
207213
""",
208214
)
209215
page.finish(diagnostics)
216+
print(parser.project_config)
210217
assert diagnostics == []
211218
check_ast_testing_string(
212219
page.ast,
@@ -319,6 +326,7 @@ def test_literalinclude() -> None:
319326
:end-before: end example 1
320327
""",
321328
)
329+
print(parser.project_config)
322330
page.finish(diagnostics)
323331
assert len(diagnostics) == 1
324332
assert isinstance(diagnostics[0], InvalidLiteralInclude)
@@ -331,7 +339,7 @@ def test_literalinclude() -> None:
331339
</directive>
332340
</root>""",
333341
)
334-
342+
print(parser.project_config)
335343
# Test poorly specified linenos: out-of-bounds (greater than file length)
336344
page, diagnostics = parse_rst(
337345
parser,
@@ -383,7 +391,8 @@ def test_literalinclude() -> None:
383391
page.finish(diagnostics)
384392
assert len(diagnostics) == 1
385393
assert isinstance(diagnostics[0], DocUtilsParseError)
386-
394+
print(parser.project_config)
395+
assert False
387396

388397
def test_include() -> None:
389398
path = ROOT_PATH.joinpath(Path("test.rst"))
@@ -599,6 +608,7 @@ def test_roles() -> None:
599608
</list>
600609
</root>""",
601610
)
611+
assert False
602612

603613

604614
def test_doc_role() -> None:

snooty/types.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,7 @@ def finish(
373373
class ProjectConfig:
374374
root: Path
375375
name: str
376+
fail_on_diagnostics: bool
376377
default_domain: Optional[str] = field(default=None)
377378
title: str = field(default="untitled")
378379
source: str = field(default="source")
@@ -401,6 +402,7 @@ def open(cls, root: Path) -> Tuple["ProjectConfig", List[Diagnostic]]:
401402
try:
402403
with path.joinpath("snooty.toml").open(encoding="utf-8") as f:
403404
data = toml.load(f)
405+
print(data)
404406
data["root"] = path
405407
result, parsed_diagnostics = check_type(
406408
ProjectConfig, data
@@ -409,6 +411,7 @@ def open(cls, root: Path) -> Tuple["ProjectConfig", List[Diagnostic]]:
409411
except FileNotFoundError:
410412
pass
411413
except LoadError as err:
414+
412415
diagnostics.append(UnmarshallingError(str(err), 0))
413416

414417
path = path.parent

0 commit comments

Comments
 (0)