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 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735
|
# standard lib
import logging
import os
import re
import shutil
# other 3rd party
import pytest
from click.testing import CliRunner
# MkDocs
from mkdocs.__main__ import build_command
# ##################################
# ######## Globals #################
# ##################################
# custom log level to get plugin info messages
logging.basicConfig(level=logging.INFO)
# ##################################
# ########## Helpers ###############
# ##################################
def setup_clean_mkdocs_folder(
mkdocs_yml_path: str, output_path: str, docs_path: str = "tests/fixtures/docs"
):
"""
Sets up a clean mkdocs directory
outputpath/testproject
├── docs/
└── mkdocs.yml
Args:
mkdocs_yml_path (Path): Path of mkdocs.yml file to use
output_path (Path): Path of folder in which to create mkdocs project
Returns:
testproject_path (Path): Path to test project
"""
testproject_path = output_path / "testproject"
# Create empty 'testproject' folder
if os.path.exists(str(testproject_path)):
logging.warning(
"""This command does not work on windows.
Refactor your test to use setup_clean_mkdocs_folder() only once"""
)
shutil.rmtree(str(testproject_path))
# Copy correct mkdocs.yml file and our test 'docs/'
shutil.copytree(docs_path, str(testproject_path / docs_path.split("/")[-1]))
shutil.copyfile(mkdocs_yml_path, str(testproject_path / "mkdocs.yml"))
return testproject_path
def build_docs_setup(testproject_path: str):
"""
Runs the `mkdocs build` command
Args:
testproject_path (Path): Path to test project
Returns:
command: Object with results of command
"""
# TODO: Try specifying path in CliRunner, this function could be one-liner
cwd = os.getcwd()
os.chdir(str(testproject_path))
try:
runner = CliRunner()
run = runner.invoke(build_command)
os.chdir(cwd)
return run
except:
os.chdir(cwd)
raise
def validate_build(testproject_path: str, plugin_config: dict = {}):
"""
Validates a build from a testproject
Args:
testproject_path (Path): Path to test project
"""
assert os.path.exists(str(testproject_path / "site"))
# Make sure index file exists
index_file = testproject_path / "site/index.html"
assert index_file.exists(), "%s does not exist" % index_file
def validate_mkdocs_file(
temp_path: str, mkdocs_yml_file: str, docs_path: str = "tests/fixtures/docs"
):
"""
Creates a clean mkdocs project
for a mkdocs YML file, builds and validates it.
Args:
temp_path (PosixPath): Path to temporary folder
mkdocs_yml_file (PosixPath): Path to mkdocs.yml file
"""
testproject_path = setup_clean_mkdocs_folder(
mkdocs_yml_path=mkdocs_yml_file, output_path=temp_path, docs_path=docs_path
)
result = build_docs_setup(
testproject_path,
)
assert result.exit_code == 0, "'mkdocs build' command failed"
# validate build with locale retrieved from mkdocs config file
validate_build(testproject_path)
return testproject_path
def validate_static(html_content: str, path: str = "", exist: bool = True):
"""
Validate glightbox.min.css and glightbox.min.js have been loaded or not
"""
assert exist == (
re.search(
rf'<link href="{re.escape(path)}assets\/stylesheets\/glightbox\.min\.css" rel="stylesheet"\/>',
html_content,
)
is not None
)
assert exist == (
re.search(
rf'<script src="{re.escape(path)}assets\/javascripts\/glightbox\.min\.js"><\/script>',
html_content,
)
is not None
)
def validate_script(html_content: str, exist: bool = True):
"""
Validate GLightbox have been initialized or not
"""
assert exist == (
re.search(
r"const lightbox = GLightbox\((.*)\);",
html_content,
)
is not None
)
EMOJI_LIST = ["emojione", "gemoji", "twemoji"]
# ##################################
# ########### Tests ################
# ##################################
def test_basic(tmp_path):
"""
Minimal sample
"""
mkdocs_file = "mkdocs.yml"
testproject_path = validate_mkdocs_file(tmp_path, f"tests/fixtures/{mkdocs_file}")
file = testproject_path / "site/index.html"
contents = file.read_text(encoding="utf8")
validate_static(contents)
validate_script(contents)
assert re.search(
r'<a class="glightbox".*?href="img\.png".*?>\s*<img.*?src="img\.png".*?\/><\/a>',
contents,
)
def test_material(tmp_path):
"""
Integrate with Material for MkDocs
"""
mkdocs_file = "mkdocs-material.yml"
testproject_path = validate_mkdocs_file(tmp_path, f"tests/fixtures/{mkdocs_file}")
file = testproject_path / "site/index.html"
contents = file.read_text(encoding="utf8")
validate_static(contents)
validate_script(contents)
assert re.search(
r"document\$\.subscribe\(\(\) => { lightbox.reload\(\) }\);",
contents,
)
assert re.search(
r'<a class="glightbox".*?href="img\.png".*?>\s*<img.*?src="img\.png".*?\/><\/a>',
contents,
)
def test_material_instant(tmp_path):
"""
Integrate with Material for MkDocs
"""
mkdocs_file = "mkdocs-material-instant.yml"
testproject_path = validate_mkdocs_file(tmp_path, f"tests/fixtures/{mkdocs_file}")
file = testproject_path / "site/index.html"
contents = file.read_text(encoding="utf8")
validate_static(contents)
validate_script(contents)
assert re.search(
r"document\$\.subscribe\(\(\) => { lightbox.reload\(\) }\);",
contents,
)
assert re.search(
r'<a class="glightbox".*?href="img\.png".*?>\s*<img.*?src="img\.png".*?\/><\/a>',
contents,
)
def test_use_directory_urls(tmp_path):
"""
Compatible with use_directory_urls is false or with --use-directory-urls and --use-directory-urls as args
https://www.mkdocs.org/user-guide/configuration/#use_directory_urls
https://www.mkdocs.org/user-guide/cli/
"""
mkdocs_file = "mkdocs-target-file.yml"
testproject_path = validate_mkdocs_file(tmp_path, f"tests/fixtures/{mkdocs_file}")
file = testproject_path / "site/sub_dir/page_in_sub_dir.html"
contents = file.read_text(encoding="utf8")
path = "../"
validate_static(contents, path=path)
validate_script(contents)
assert re.search(
rf'<a class="glightbox".*?href="{re.escape(path)}img\.png".*?>\s*<img.*?src="\.\.\/img\.png".*?\/><\/a>',
contents,
)
def test_disable_by_page(tmp_path):
"""
Disable by page with page meta
"""
mkdocs_file = "mkdocs.yml"
testproject_path = validate_mkdocs_file(tmp_path, f"tests/fixtures/{mkdocs_file}")
file = testproject_path / "site/disable_by_page/index.html"
contents = file.read_text(encoding="utf8")
validate_static(contents, exist=False)
validate_script(contents, exist=False)
assert (
re.search(
r'<a class="glightbox".*?href="img\.png".*?>\s*<img.*?src="img\.png".*?\/><\/a>',
contents,
)
is None
)
def test_disable_by_image(tmp_path):
"""
Disable by the image with image custom class or predefined class
"""
mkdocs_file = "mkdocs-disable-by-image.yml"
testproject_path = validate_mkdocs_file(tmp_path, f"tests/fixtures/{mkdocs_file}")
file = testproject_path / "site/disable_by_image/index.html"
contents = file.read_text(encoding="utf8")
path = "../"
validate_static(contents, path=path)
validate_script(contents)
assert re.search(
rf'<p><img.*?class="off-glb".*?src="{re.escape(path)}img\.png".*?\/><\/p>',
contents,
)
assert re.search(
rf'<p><img.*?class="skip-lightbox".*?src="{re.escape(path)}img\.png".*?\/><\/p>',
contents,
)
assert re.search(
rf'<a class="glightbox".*?href="{re.escape(path)}img\.png".*?><img.*?src="{re.escape(path)}img\.png".*?\/><\/a>',
contents,
)
@pytest.mark.parametrize("emoji_name", EMOJI_LIST)
def test_disable_with_emoji(emoji_name, tmp_path):
"""
Disable when the image with emoji class name(defined in PyMdown Extensions): emojione, gemoji, twemoji
https://facelessuser.github.io/pymdown-extensions/extensions/emoji/
"""
mkdocs_file = f"mkdocs-material-{emoji_name}.yml"
testproject_path = validate_mkdocs_file(tmp_path, f"tests/fixtures/{mkdocs_file}")
file = testproject_path / "site/emoji/index.html"
contents = file.read_text(encoding="utf8")
validate_static(contents, path="../")
validate_script(contents)
assert re.search(
rf'<p><img.*?class="{re.escape(emoji_name)}".*?\/>.*?<\/p>',
contents,
)
def test_url(tmp_path):
"""
Compatible with URL
"""
mkdocs_file = "mkdocs.yml"
testproject_path = validate_mkdocs_file(tmp_path, f"tests/fixtures/{mkdocs_file}")
file = testproject_path / "site/url/index.html"
contents = file.read_text(encoding="utf8")
validate_static(contents, path="../")
validate_script(contents)
image_url = re.escape("https://dummyimage.com/600x400/bdc3c7/fff.png")
assert re.search(
rf'<a class="glightbox".*?href="{image_url}".*?><img.*?src="{image_url}".*?\/><\/a>',
contents,
)
def test_default_options(tmp_path):
"""
Validate GLightbox default options
"""
mkdocs_file = "mkdocs.yml"
testproject_path = validate_mkdocs_file(tmp_path, f"tests/fixtures/{mkdocs_file}")
file = testproject_path / "site/images/index.html"
contents = file.read_text(encoding="utf8")
path = "../"
validate_static(contents, path)
validate_script(contents)
regex_obj = re.search(
rf'<a class="glightbox".*?href="{re.escape(path)}img\.png.*?"><img.*?src="{re.escape(path)}img\.png".*?\/><\/a>',
contents,
)
# validate position
regex_obj = re.search(
r"const lightbox = GLightbox\((.*)\);",
contents,
)
assert regex_obj
text = regex_obj.group(1)
options = [
'"touchNavigation": true',
'"loop": false',
'"zoomable": true',
'"draggable": true',
'"openEffect": "zoom"',
'"closeEffect": "zoom"',
'"slideEffect": "slide"',
]
for option in options:
assert option in text
def test_options(tmp_path):
"""
Validate GLightbox options setting through plugins
"""
mkdocs_file = "mkdocs-options.yml"
testproject_path = validate_mkdocs_file(tmp_path, f"tests/fixtures/{mkdocs_file}")
file = testproject_path / "site/images/index.html"
contents = file.read_text(encoding="utf8")
path = "../"
validate_static(contents, path)
validate_script(contents)
# validate override style
assert ".gslide-image img { background: none; }" in contents
assert (
""".glightbox-clean .gslide-media {
-webkit-box-shadow: none;
box-shadow: none;
}"""
in contents
)
# validate slide options
regex_obj = re.search(
rf'<a class="glightbox".*?href="{re.escape(path)}img\.png"(.*?)><img.*?src="{re.escape(path)}img\.png".*?\/><\/a>',
contents,
)
assert regex_obj
text = regex_obj.group(1)
assert 'data-height="60%"' in text
assert 'data-width="80%"' in text
assert 'data-desc-position="right"' in text
# validate GLightbox options
regex_obj = re.search(
r"const lightbox = GLightbox\((.*)\);",
contents,
)
assert regex_obj
text = regex_obj.group(1)
options = [
'"touchNavigation": false',
'"loop": true',
'"zoomable": false',
'"draggable": false',
'"openEffect": "fade"',
'"closeEffect": "fade"',
'"slideEffect": "fade"',
]
for option in options:
assert option in text
def test_gallery(tmp_path):
"""
Validate gallery
"""
mkdocs_file = "mkdocs-material.yml"
testproject_path = validate_mkdocs_file(tmp_path, f"tests/fixtures/{mkdocs_file}")
file = testproject_path / "site/gallery/index.html"
contents = file.read_text(encoding="utf8")
path = "../"
validate_static(contents, path=path)
validate_script(contents)
regex_obj = re.search(
rf'<a class="glightbox".*?href="{re.escape(path)}img\.png"(.*?)><img alt="image-a".*?src="{re.escape(path)}img\.png".*?\/><\/a>',
contents,
)
assert regex_obj
text = regex_obj.group(1)
assert 'data-gallery="1"' in text
regex_obj = re.search(
rf'<a class="glightbox".*?href="{re.escape(path)}img\.png"(.*?)><img alt="image-b".*?src="{re.escape(path)}img\.png".*?\/><\/a>',
contents,
)
assert regex_obj
text = regex_obj.group(1)
assert 'data-gallery="1"' in text
regex_obj = re.search(
rf'<a class="glightbox".*?href="{re.escape(path)}another-img\.png"(.*?)><img alt="image-c".*?src="{re.escape(path)}another-img\.png".*?\/><\/a>',
contents,
)
assert regex_obj
text = regex_obj.group(1)
assert 'data-gallery="2"' in text
regex_obj = re.search(
rf'<a class="glightbox".*?href="{re.escape(path)}another-img\.png"(.*?)><img alt="image-d".*?src="{re.escape(path)}another-img\.png".*?\/><\/a>',
contents,
)
assert regex_obj
text = regex_obj.group(1)
assert 'data-gallery="2"' in text
def test_caption(tmp_path):
"""
Validate captions feature
"""
mkdocs_file = "mkdocs-material.yml"
testproject_path = validate_mkdocs_file(tmp_path, f"tests/fixtures/{mkdocs_file}")
file = testproject_path / "site/caption/index.html"
contents = file.read_text(encoding="utf8")
path = "../"
validate_static(contents, path=path)
validate_script(contents)
# validate title and description
regex_obj = re.search(
rf'<a class="glightbox".*?href="{re.escape(path)}img\.png"(.*?)><img alt="image-default".*?src="{re.escape(path)}img\.png".*?\/><\/a>',
contents,
)
assert regex_obj
text = regex_obj.group(1)
assert 'data-description="data-description"' in text
assert 'data-title="data-title"' in text
# validate position
regex_obj = re.search(
rf'<a class="glightbox".*?href="{re.escape(path)}img\.png"(.*?)><img alt="image-right".*?src="{re.escape(path)}img\.png".*?\/><\/a>',
contents,
)
assert regex_obj
text = regex_obj.group(1)
assert 'data-desc-position="right"' in text
# validate compatible with figure
regex_obj = re.search(
rf'<a class="glightbox".*?href="{re.escape(path)}img\.png"(.*?)><img alt="image-figure".*?src="{re.escape(path)}img\.png".*?\/><\/a><\/p>',
contents,
)
assert regex_obj
text = regex_obj.group(1)
assert 'data-description="data-description"' in text
assert 'data-title="data-title"' in text
def test_auto_caption_by_page(tmp_path):
"""
Validate auto captions with image tag alt by page
"""
mkdocs_file = "mkdocs-material.yml"
testproject_path = validate_mkdocs_file(tmp_path, f"tests/fixtures/{mkdocs_file}")
file = testproject_path / "site/auto_caption/index.html"
contents = file.read_text(encoding="utf8")
path = "../"
validate_static(contents, path=path)
validate_script(contents)
# validate title and description
regex_obj = re.search(
rf'<a class="glightbox".*?href="{re.escape(path)}img\.png"(.*?)><img.*?src="{re.escape(path)}img\.png".*?\/><\/a>',
contents,
)
assert regex_obj
text = regex_obj.group(1)
assert 'data-title="alt as caption"' in text
def test_auto_caption(tmp_path):
"""
Validate auto captions with image tag alt for all page
"""
mkdocs_file = "mkdocs-auto-caption.yml"
testproject_path = validate_mkdocs_file(tmp_path, f"tests/fixtures/{mkdocs_file}")
file = testproject_path / "site/index.html"
contents = file.read_text(encoding="utf8")
validate_static(contents)
validate_script(contents)
regex_obj = re.search(
r'<a class="glightbox".*?href="img\.png"(.*?)><img.*?src="img\.png".*?\/><\/a>',
contents,
)
assert regex_obj
text = regex_obj.group(1)
assert 'data-title="image"' in text
def test_material_template(tmp_path):
"""
Compatible with template
"""
mkdocs_file = "mkdocs-material-template.yml"
testproject_path = validate_mkdocs_file(
tmp_path,
f"tests/fixtures/{mkdocs_file}",
docs_path="tests/fixtures/template_docs",
)
file = testproject_path / "site/index.html"
contents = file.read_text(encoding="utf8")
validate_static(contents)
validate_script(contents)
assert re.search(
r"document\$\.subscribe\(\(\) => { lightbox.reload\(\) }\);",
contents,
)
assert re.search(
r'<a class="glightbox".*?href="img\.png".*?>\s*<img.*?src="img\.png".*?\/><\/a>',
contents,
)
def test_site_url(tmp_path):
"""
Compatible with the site with path prefix
"""
mkdocs_file = "mkdocs-site-url.yml"
testproject_path = validate_mkdocs_file(tmp_path, f"tests/fixtures/{mkdocs_file}")
file = testproject_path / "site/index.html"
contents = file.read_text(encoding="utf8")
validate_static(contents)
validate_script(contents)
assert re.search(
r'<a class="glightbox".*?href="img\.png".*?>\s*<img.*?src="img\.png".*?\/><\/a>',
contents,
)
file = testproject_path / "site/images/index.html"
contents = file.read_text(encoding="utf8")
path = "../"
validate_static(contents, path)
validate_script(contents)
assert re.search(
rf'<a class="glightbox".*?href="{re.escape(path)}img\.png".*?><img.*?src="{re.escape(path)}img\.png".*?\/><\/a>',
contents,
)
def test_static(tmp_path):
"""
Validate static files
"""
mkdocs_file = "mkdocs.yml"
testproject_path = validate_mkdocs_file(tmp_path, f"tests/fixtures/{mkdocs_file}")
assert os.path.exists(
os.path.join(testproject_path, "site/assets/stylesheets/glightbox.min.css")
)
assert os.path.exists(
os.path.join(testproject_path, "site/assets/javascripts/glightbox.min.js")
)
def test_image_in_anchor(tmp_path):
"""
Disable when image in an anchor tag
"""
mkdocs_file = "mkdocs.yml"
testproject_path = validate_mkdocs_file(tmp_path, f"tests/fixtures/{mkdocs_file}")
file = testproject_path / "site/image_in_anchor/index.html"
contents = file.read_text(encoding="utf8")
path = "../"
validate_static(contents, path)
validate_script(contents)
assert (
re.search(
rf'<a class="glightbox".*?href="{re.escape(path)}img\.png".*?><img.*?src="{re.escape(path)}img\.png".*?\/><\/a>',
contents,
)
is None
)
def test_image_without_ext(tmp_path):
"""
Image without extension
"""
mkdocs_file = "mkdocs.yml"
testproject_path = validate_mkdocs_file(tmp_path, f"tests/fixtures/{mkdocs_file}")
file = testproject_path / "site/without_ext/index.html"
contents = file.read_text(encoding="utf8")
path = "../"
validate_static(contents, path)
validate_script(contents)
assert re.search(
r'<a class="glightbox".*?href="https://picsum\.photos/1200/800".*?data-type="image".*?><img.*?src="https://picsum\.photos/1200/800".*?\/><\/a>',
contents,
)
def test_error(tmp_path):
"""
Wrapping for error
"""
mkdocs_file = "mkdocs-error.yml"
testproject_path = validate_mkdocs_file(
tmp_path,
f"tests/fixtures/{mkdocs_file}",
docs_path="tests/fixtures/error_docs",
)
file = testproject_path / "site/index.html"
contents = file.read_text(encoding="utf8")
validate_static(contents)
validate_script(contents)
def test_privacy(tmp_path):
"""
Compatible with material privacy plugin
"""
mkdocs_file = "mkdocs-material-privacy.yml"
testproject_path = validate_mkdocs_file(tmp_path, f"tests/fixtures/{mkdocs_file}")
file = testproject_path / "site/url/index.html"
contents = file.read_text(encoding="utf8")
validate_static(contents, path="../")
validate_script(contents)
image_url = re.escape("../assets/external/dummyimage.com/600x400/bdc3c7/fff.png")
assert re.search(
rf'<a class="glightbox"(?!.*href=).*?><img.*?src="{image_url}".*?><\/a>',
contents,
)
patch_script = re.escape(
"document.querySelectorAll('.glightbox').forEach(function(element) {"
)
assert re.search(
rf"{patch_script}",
contents,
)
def test_enable_by_image(tmp_path):
"""
Enable by the image with on-glb class
"""
mkdocs_file = "mkdocs-material.yml"
testproject_path = validate_mkdocs_file(tmp_path, f"tests/fixtures/{mkdocs_file}")
file = testproject_path / "site/enable_by_image/index.html"
contents = file.read_text(encoding="utf8")
path = "../"
validate_static(contents, path=path)
validate_script(contents)
assert re.search(
rf'<p><img alt="image" src="{re.escape(path)}img\.png" \/><\/p>',
contents,
)
assert re.search(
rf'<a class="glightbox".*?href="{re.escape(path)}img\.png".*?><img.*?class="on-glb".*?src="{re.escape(path)}img\.png".*?\/><\/a>',
contents,
)
def test_manual(tmp_path):
"""
Manual mode
"""
mkdocs_file = "mkdocs-manual.yml"
testproject_path = validate_mkdocs_file(tmp_path, f"tests/fixtures/{mkdocs_file}")
file = testproject_path / "site/index.html"
contents = file.read_text(encoding="utf8")
validate_static(contents)
validate_script(contents)
assert (
re.search(
r'<a class="glightbox".*?href="img\.png".*?>\s*<img.*?src="img\.png".*?\/><\/a>',
contents,
)
is None
)
file = testproject_path / "site/manual/index.html"
contents = file.read_text(encoding="utf8")
validate_static(contents, path="../")
validate_script(contents)
assert re.search(
r'<a class="glightbox".*?href="..\/img\.png".*?>\s*<img.*?src="..\/img\.png".*?\/><\/a>',
contents,
)
file = testproject_path / "site/manual_enable_by_page/index.html"
contents = file.read_text(encoding="utf8")
validate_static(contents, path="../")
validate_script(contents)
assert re.search(
r'<a class="glightbox".*?href="..\/img\.png".*?>\s*<img.*?alt="image-a" src="..\/img\.png".*?\/><\/a>',
contents,
)
assert (
re.search(
r'<a class="glightbox".*?href="..\/img\.png".*?>\s*<img.*?alt="image-b" src="..\/img\.png".*?\/><\/a>',
contents,
)
is None
)
assert re.search(
r'<a class="glightbox".*?href="..\/img\.png".*?>\s*<img.*?alt="image-c" src="..\/img\.png".*?\/><\/a>',
contents,
)
|