Skip to content

Commit

Permalink
https://github.com/jackdewinter/pymarkdown/issues/1280
Browse files Browse the repository at this point in the history
  • Loading branch information
jackdewinter committed Dec 8, 2024
1 parent 2b26b0f commit b4c9127
Show file tree
Hide file tree
Showing 7 changed files with 110 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ build/
dist/
pymarkdownlnt.egg-info/
p0.prof
ff/
43 changes: 43 additions & 0 deletions batch_tests.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
@echo off
setlocal EnableDelayedExpansion

rem Set needed environment variables.

:uniqLoop
set "XX_TEMPFILE=%tmp%\xx_~%RANDOM%.tmp"
if exist "%XX_TEMPFILE%" goto :uniqLoop

set disable_list="extensions.markdown-task-list-items.enabled=@True"
set disable_list=%disable_list%;"extensions.markdown-strikethrough.enabled=@True"
set disable_list=%disable_list%;"extensions.markdown-extended-autolinks.enabled=@True"
set disable_list=%disable_list%;"extensions.markdown-disallow-raw-html.enabled=@True"
set disable_list=%disable_list%;"extensions.front-matter.enabled=@True"

set filesCount=0 & for %%f in (ff\*) do @(set /a filesCount+=1 > nul)

set "bool_replace=$^!"
for %%a in (%disable_list%) do (
set temp_path=%%a
call set next_path=%%temp_path:@=!bool_replace!%%
echo.
echo Scanning with setting: !next_path!
set /a count = 0
for %%i in (ff\*) do (
set file_to_scan=%%i
set /a count += 1
FOR /F "delims=" %%j IN ('python -c "print((!count! %% 10))"') DO set mcount=%%j
if "!mcount!"=="0" (
echo !count! out of %filesCount%
)
pipenv run python main.py --strict --set "!next_path!" --return-code-scheme minimal scan !file_to_scan! > %XX_TEMPFILE%
if ERRORLEVEL 1 (
type %XX_TEMPFILE%
echo pipenv run python main.py --strict --set "!next_path!" --return-code-scheme minimal scan !file_to_scan!
echo BADD !file_to_scan!
)
)
echo !count! out of %filesCount%
)

set xx=
erase %XX_TEMPFILE%
4 changes: 4 additions & 0 deletions newdocs/src/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@

- [Issue 810](https://github.com/jackdewinter/pymarkdown/issues/810)
- Added fix for Rule Md012
- [Issue 1280](https://github.com/jackdewinter/pymarkdown/issues/1280)
- Added capability to save all single Markdown documents in
a specified directory, then scanning them one at a time with
PyMarkdown and each of the extensions enabled.

<!--- pyml disable-next-line no-duplicate-heading-->
### Fixed
Expand Down
28 changes: 28 additions & 0 deletions ptest.cmd
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
@echo off
setlocal EnableDelayedExpansion
set OLDDIR=%CD%
pushd %~dp0

rem Required to make sure coverage is written to the right areas.
Expand Down Expand Up @@ -34,6 +35,7 @@ if "%1" == "-h" (
echo -m Enabled multi-core testing.
echo -f Produce a full report for the tests instead of a 'changes only' report.
echo -p Publish project summaries instead of running tests.
echo -d Capture test cases in the specified existing directory.
echo -k [keyword] Execute only the tests matching the specified keyword.
GOTO real_end
) else if "%1" == "-p" (
Expand All @@ -55,6 +57,13 @@ if "%1" == "-h" (
goto error_end
)
shift
) else if "%1" == "-d" (
set PTEST_KEEP_DIRECTORY=%2
if not defined PTEST_KEEP_DIRECTORY (
echo Option -d requires a keyword argument to follow it.
goto error_end
)
shift
) else if "%1" == "" (
goto after_process_arguments
) else (
Expand Down Expand Up @@ -88,6 +97,25 @@ if defined PTEST_MULTI_CORE_ARGS (
set PTEST_MULTI_CORE_ARGS=-n !CORES_TO_USE! --dist loadscope
)

if defined PTEST_KEEP_DIRECTORY (
if not exist %PTEST_KEEP_DIRECTORY%\nul (
echo.
echo {Path specified by the -d option is not an existing directory.}
goto error_end
) else (
pushd %OLDDIR%
cd
cd !PTEST_KEEP_DIRECTORY!
FOR /F "tokens=* USEBACKQ" %%F IN (`cd`) DO (
SET my_var=%%F
)
set "PTEST_KEEP_DIRECTORY=!my_var!"
popd

erase !PTEST_KEEP_DIRECTORY!\*.md
)
)

rem Enter main part of script.
if defined PTEST_KEYWORD (
echo {Executing partial test suite...}
Expand Down
4 changes: 4 additions & 0 deletions run.cmd
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
pipenv run python main.py %1 %2 %3 %4 %5 %6 %7 %8 %9
set RETURN_CODE=%ERRORLEVEL%
echo !RETURN_CODE!
echo %RETURN_CODE%
exit /b %RETURN_CODE%
23 changes: 21 additions & 2 deletions test/pytest_execute.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import logging
import os
import sys
import tempfile
import traceback
from abc import ABC, abstractmethod

Expand Down Expand Up @@ -247,7 +248,7 @@ def handle_normal_exception(cls):
del trace_back
return 1

# pylint: disable=broad-except, too-many-arguments
# pylint: disable=broad-except, too-many-arguments, too-many-locals, too-many-branches
def invoke_main(
self,
arguments=None,
Expand All @@ -259,6 +260,24 @@ def invoke_main(
"""
Invoke the mainline so that we can capture results.
"""

keep_directory = os.getenv("PTEST_KEEP_DIRECTORY", None)
if keep_directory and os.path.isdir(keep_directory):
if (
len(arguments) >= 2
and arguments[-2] == "scan"
and os.path.isfile(arguments[-1])
):
with tempfile.NamedTemporaryFile(
"wt",
encoding="utf-8",
dir=keep_directory,
suffix=".md",
delete=False,
) as temp_file:
with open(arguments[-1], "rt", encoding="utf-8") as fixed_file:
temp_file.write(fixed_file.read())

if suppress_first_line_heading_rule:
new_arguments = arguments.copy() if arguments else []
if "--disable-rules" not in new_arguments:
Expand Down Expand Up @@ -305,4 +324,4 @@ def invoke_main(

return InProcessResult(returncode, std_output, std_error)

# pylint: enable=broad-except, too-many-arguments
# pylint: enable=broad-except, too-many-arguments, too-many-locals, too-many-branches
11 changes: 9 additions & 2 deletions test/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
# from test.verify_line_and_column_numbers import verify_line_and_column_numbers


# pylint: disable=too-many-arguments
# pylint: disable=too-many-arguments, too-many-locals
def act_and_assert(
source_markdown,
expected_gfm,
Expand All @@ -41,6 +41,13 @@ def act_and_assert(
Act and assert on the expected behavior of parsing the source_markdown.
"""

keep_directory = os.getenv("PTEST_KEEP_DIRECTORY", None)
if keep_directory and os.path.isdir(keep_directory):
with tempfile.NamedTemporaryFile(
"wt", encoding="utf-8", dir=keep_directory, suffix=".md", delete=False
) as temp_file:
temp_file.write(source_markdown)

# Arrange
logging.getLogger().setLevel(logging.DEBUG if show_debug else logging.WARNING)
ParserLogger.sync_on_next_call()
Expand Down Expand Up @@ -80,7 +87,7 @@ def act_and_assert(
)


# pylint: enable=too-many-arguments
# pylint: enable=too-many-arguments, too-many-locals


def read_contents_of_text_file(source_path: str) -> str:
Expand Down

0 comments on commit b4c9127

Please sign in to comment.