-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from Neoteroi/v0.1.2
v0.1.2
- Loading branch information
Showing
7 changed files
with
126 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,3 +11,5 @@ styles/*.css | |
styles/*.css.map | ||
__*.html | ||
__file_out.py | ||
|
||
docs/res/contribs-new.html |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Hello World | ||
|
||
Some sentence. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,10 @@ | ||
import textwrap | ||
|
||
import pytest | ||
from mkdocs.structure.files import File | ||
from mkdocs.structure.pages import Page | ||
|
||
from neoteroi.contribs import ContribsPlugin | ||
from neoteroi.contribs.domain import Contributor | ||
from neoteroi.contribs.git import GitContributionsReader | ||
|
||
|
@@ -11,6 +16,10 @@ | |
" 2\tRoberto Prevato <[email protected]>\n", | ||
[Contributor("Roberto Prevato", "[email protected]", 2)], | ||
], | ||
[ | ||
" 2\tRoberto Prevato (RP) <[email protected]>\n", | ||
[Contributor("Roberto Prevato (RP)", "[email protected]", 2)], | ||
], | ||
[ | ||
( | ||
" 14\tRoberto Prevato <[email protected]>\n" | ||
|
@@ -27,3 +36,102 @@ def test_parse_contributors(value, expected_result): | |
reader = GitContributionsReader() | ||
contributors = list(reader.parse_committers(value)) | ||
assert contributors == expected_result | ||
|
||
|
||
def _get_contribs_config(): | ||
return { | ||
"contributors_label": "Contributors", | ||
"last_modified_label": "Last modified on", | ||
"show_last_modified_time": True, | ||
"show_contributors_title": False, | ||
"time_format": "%Y-%m-%d %H:%M:%S", | ||
} | ||
|
||
|
||
def test_contribs_plugin_success(): | ||
""" | ||
Tests a successful scenario. | ||
""" | ||
handler = ContribsPlugin() | ||
handler.config = _get_contribs_config() | ||
|
||
example = textwrap.dedent( | ||
""" | ||
# Hello World! | ||
Lorem ipsum dolor sit amet. | ||
""".strip( | ||
"\n" | ||
) | ||
) | ||
|
||
result = handler.on_page_markdown( | ||
example, | ||
page=Page( | ||
"Example", | ||
File( | ||
path="res/contribs-01.html", | ||
src_dir="tests/res", | ||
dest_dir="tests", | ||
use_directory_urls=True, | ||
), | ||
{}, | ||
), | ||
) | ||
|
||
assert result is not None | ||
assert ( | ||
result | ||
== """# Hello World! | ||
Lorem ipsum dolor sit amet. | ||
<div class="nt-contribs"><p class="nt-mod-time">Last modified on: 2022-10-04 21""" | ||
+ """:01:05</p><div class="nt-contributors"><div class="nt-contributor """ | ||
+ """nt-group-0" title="Charlie Brown <[email protected]>""" | ||
+ """ (1)"><span class="nt-initials">CB</span></div><div class="nt-cont""" | ||
+ """ributor nt-group-1" title="Sally Brown (SB) <sally.brown@exampl""" | ||
+ """e.org> (1)"><span class="nt-initials">SB</span></div></div></di""" | ||
+ """v>""" | ||
) | ||
|
||
|
||
def test_contribs_plugin_new_file_ignore(): | ||
""" | ||
Tests the scenario of a new file that is created while developing and is not | ||
committed, yet. | ||
""" | ||
handler = ContribsPlugin() | ||
handler.config = _get_contribs_config() | ||
|
||
example = textwrap.dedent( | ||
""" | ||
# Hello World! | ||
Lorem ipsum dolor sit amet. | ||
""".strip( | ||
"\n" | ||
) | ||
) | ||
|
||
with open("docs/res/contribs-new.html", mode="wt", encoding="utf8") as new_file: | ||
new_file.write(example) | ||
|
||
result = handler.on_page_markdown( | ||
example, | ||
page=Page( | ||
"Example", | ||
File( | ||
path="res/contribs-new.html", | ||
src_dir="tests/res", | ||
dest_dir="tests", | ||
use_directory_urls=True, | ||
), | ||
{}, | ||
), | ||
) | ||
|
||
assert result is not None | ||
assert result == example |