@@ -495,7 +495,7 @@ def test_included_toc(sphinx_build_factory):
495495 "github_version" : "HEAD" ,
496496 "doc_path" : "docs" ,
497497 },
498- " https://github.com/foo/bar/edit/HEAD/docs/index.rst" ,
498+ ( "Edit on GitHub" , " https://github.com/foo/bar/edit/HEAD/docs/index.rst") ,
499499 ],
500500 [
501501 {
@@ -504,7 +504,7 @@ def test_included_toc(sphinx_build_factory):
504504 "gitlab_version" : "HEAD" ,
505505 "doc_path" : "docs" ,
506506 },
507- " https://gitlab.com/foo/bar/-/edit/HEAD/docs/index.rst" ,
507+ ( "Edit on GitLab" , " https://gitlab.com/foo/bar/-/edit/HEAD/docs/index.rst") ,
508508 ],
509509 [
510510 {
@@ -513,7 +513,10 @@ def test_included_toc(sphinx_build_factory):
513513 "bitbucket_version" : "HEAD" ,
514514 "doc_path" : "docs" ,
515515 },
516- "https://bitbucket.org/foo/bar/src/HEAD/docs/index.rst?mode=edit" ,
516+ (
517+ "Edit on Bitbucket" ,
518+ "https://bitbucket.org/foo/bar/src/HEAD/docs/index.rst?mode=edit" ,
519+ ),
517520 ],
518521]
519522
@@ -526,10 +529,10 @@ def test_included_toc(sphinx_build_factory):
526529 key : f"{ value } /" if key == "doc_path" else value
527530 for key , value in html_context .items ()
528531 },
529- # the URL does not change
530- url ,
532+ # the text and URL do not change
533+ text_and_url ,
531534 ]
532- for html_context , url in good_edits
535+ for html_context , text_and_url in good_edits
533536]
534537
535538# copy the "good" ones, provide a `<whatever>_url` based off the default
@@ -541,11 +544,14 @@ def test_included_toc(sphinx_build_factory):
541544 # add a provider url
542545 ** {f"{ provider } _url" : f"https://{ provider } .example.com" },
543546 ),
544- f"""https://{ provider } .example.com/foo/{ url .split ("/foo/" )[1 ]} """ ,
547+ (
548+ text ,
549+ f"""https://{ provider } .example.com/foo/{ url .split ("/foo/" )[1 ]} """ ,
550+ ),
545551 ]
546- for html_context , url in good_edits
547- for provider in ["gitlab " , "bitbucket " , "github " ]
548- if provider in url
552+ for html_context , ( text , url ) in good_edits
553+ for provider in ["github " , "gitlab " , "bitbucket " ]
554+ if provider in text . lower ()
549555]
550556
551557# missing any of the values should fail
@@ -560,7 +566,7 @@ def test_included_toc(sphinx_build_factory):
560566 },
561567 None ,
562568 ]
563- for html_context , url in good_edits
569+ for html_context , _ in good_edits
564570]
565571
566572# a good custom URL template
@@ -571,7 +577,20 @@ def test_included_toc(sphinx_build_factory):
571577 "https://dvcs.example.com/foo/bar/edit/HEAD/{{ file_name }}"
572578 )
573579 },
574- "https://dvcs.example.com/foo/bar/edit/HEAD/index.rst" ,
580+ ("Edit" , "https://dvcs.example.com/foo/bar/edit/HEAD/index.rst" ),
581+ ]
582+ ]
583+
584+ # a good custom URL template with an additional provider name
585+ good_custom_with_provider = [
586+ [
587+ {
588+ "edit_page_url_template" : (
589+ "https://dvcs.example.com/foo/bar/edit/HEAD/{{ file_name }}"
590+ ),
591+ "edit_page_provider_name" : "FooProvider" ,
592+ },
593+ ("Edit on FooProvider" , "https://dvcs.example.com/foo/bar/edit/HEAD/index.rst" ),
575594 ]
576595]
577596
@@ -594,24 +613,31 @@ def test_included_toc(sphinx_build_factory):
594613]
595614
596615
597- @pytest .mark .parametrize ("html_context,edit_url " , all_edits )
598- def test_edit_page_url (sphinx_build_factory , html_context , edit_url ):
616+ @pytest .mark .parametrize ("html_context,edit_text_and_url " , all_edits )
617+ def test_edit_page_url (sphinx_build_factory , html_context , edit_text_and_url ):
599618 confoverrides = {
600619 "html_theme_options.use_edit_page_button" : True ,
601620 "html_context" : html_context ,
602621 }
603622 sphinx_build = sphinx_build_factory ("base" , confoverrides = confoverrides )
604623
605- if edit_url is None :
606- with pytest .raises (sphinx .errors .ExtensionError ):
624+ if edit_text_and_url is None :
625+ with pytest .raises (
626+ sphinx .errors .ExtensionError , match = "Missing required value"
627+ ):
607628 sphinx_build .build ()
608629 return
609630
631+ edit_text , edit_url = edit_text_and_url
610632 sphinx_build .build ()
611633 index_html = sphinx_build .html_tree ("index.html" )
612634 edit_link = index_html .select (".editthispage a" )
613635 assert edit_link , "no edit link found"
614636 assert edit_link [0 ].attrs ["href" ] == edit_url , f"edit link didn't match { edit_link } "
637+ # First child is the icon
638+ assert (
639+ list (edit_link [0 ].strings )[1 ].strip () == edit_text
640+ ), f"edit text didn't match { edit_text } "
615641
616642
617643@pytest .mark .parametrize (
@@ -636,7 +662,6 @@ def test_edit_page_url(sphinx_build_factory, html_context, edit_url):
636662 ],
637663)
638664def test_analytics (sphinx_build_factory , provider , tags ):
639-
640665 confoverrides = provider
641666 sphinx_build = sphinx_build_factory ("base" , confoverrides = confoverrides )
642667 sphinx_build .build ()
@@ -895,7 +920,7 @@ def test_translations(sphinx_build_factory):
895920 # TODO: Add translations where there are english phrases below
896921 sidebar_secondary = index .select (".bd-sidebar-secondary" )[0 ]
897922 assert "Montrer le code source" in str (sidebar_secondary )
898- assert "Edit this page " in str (sidebar_secondary )
923+ assert "Edit on GitHub " in str (sidebar_secondary )
899924
900925 # TODO: Add translations where there are english phrases below
901926 header = index .select (".bd-header" )[0 ]
0 commit comments