New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add tag weights #19
Merged
Merged
Add tag weights #19
Changes from all commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
3b3e9ee
Add tag weights
9d9b66e
Use existing pad instead of creating a new one.
c4204f6
Compute tag counts only if necessary
1e9d758
typo
53508fe
Replace arguments `a` and `b` by `lower` and `upper`
10b9213
Replace `collections.defaultdict(int)` by `collections.Counter()`.
1f3b141
Replace the `tagweight` dictionary with a `TagWeight` class
16e8c5b
Fix tag count
4b13f0d
Removed some magic: explict is better than implicit
586029e
Add AUTHORS and LICENSE files
464f52c
Remove my name from lektor_tags.py (my name has been added to AUTHORS…
2a59bce
[tag weights] Even with `lektor server`, tag weights are re-calculate…
4f49660
Add comment
0c3407d
Merge branch 'master' into weights
95e0f25
The primary data structure is a mapping of tag names to TagWeight() o…
e7d43cc
Update authors
388268c
Update documentation to match 95e0f251914fdcd000bfa67c6338d34e537868fc
63aa420
Apply black and reorder-python-imports
8637745
Proposed tests for tagweights PR
dairiki 8d010e9
Turn TagWeight into a dataclass
d2b6899
TagWeight ordering: Use functools.total_ordering; raise NotImplemente…
6be1c9d
Return {} if there is not tags
91f5da1
Cosmetic change to the way TagWeight.linear() and TagWeight.log() are…
e1cfa91
Set ``tagweight`` jinja environment variable only once.
cf9753a
TagWeight: Do not fail with pages without any tags (or with a tag fie…
b98be0f
TagWeight tests: Use a group of three elements for loggroup() test
d55baa8
Blacken tests/test_tagweights.py
dairiki e2f8f4d
Fix TagWeight rich comparison methods
dairiki File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
Original author: A. Jesse Jiryu Davis | ||
|
||
Contributors: | ||
|
||
- Joseph Nix (release, bug fixes) | ||
- Jakob Schnitzer (release, bug fixes) | ||
- Louis Paternault (tag weights) |
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,8 @@ | ||
Copyright 2016 A. Jesse Jiryu Davis | ||
Copyright 2018 Joseph Nix | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
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 |
---|---|---|
@@ -0,0 +1,96 @@ | ||
from collections import Counter | ||
|
||
import pytest | ||
from lektor.context import Context | ||
|
||
from lektor_tags import TagWeight | ||
|
||
|
||
@pytest.fixture | ||
def tags_plugin(env): | ||
return env.plugins["tags"] | ||
|
||
|
||
@pytest.fixture | ||
def lektor_context(pad): | ||
with Context(pad=pad) as ctx: | ||
yield ctx | ||
|
||
|
||
@pytest.mark.usefixtures("lektor_context") | ||
def test_tagcount(tags_plugin): | ||
assert tags_plugin.tagcount() == Counter({"tag1": 2, "tag2": 1, "tag3": 1}) | ||
|
||
|
||
@pytest.mark.usefixtures("lektor_context") | ||
def test_tagweights(tags_plugin): | ||
assert tags_plugin.tagweights() == { | ||
"tag1": TagWeight(2, 1, 2), | ||
"tag2": TagWeight(1, 1, 2), | ||
"tag3": TagWeight(1, 1, 2), | ||
} | ||
|
||
|
||
@pytest.mark.usefixtures("lektor_context") | ||
def test_tagweights_no_tags(pad, tags_plugin): | ||
config = tags_plugin.get_config() | ||
config["tags_field"] = "test_no_tags" | ||
assert tags_plugin.tagweights() == {} | ||
|
||
|
||
@pytest.fixture | ||
def tagweight(count, mincount, maxcount): | ||
return TagWeight(count, mincount, maxcount) | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"count, mincount, maxcount, lower, upper, expected", | ||
[ | ||
(1, 1, 1, 1, 2, 1), | ||
(1, 1, 3, 1, 2, 1), | ||
(2, 1, 3, 1, 2, 1.5), | ||
(3, 1, 3, 1, 2, 2), | ||
], | ||
) | ||
def test_TagWeight_linear(tagweight, lower, upper, expected): | ||
assert tagweight.linear(lower, upper) == expected | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"count, mincount, maxcount, groups, expected", | ||
[ | ||
(1, 1, 4, ("a", "b"), "a"), | ||
(2, 1, 4, ("a", "b"), "a"), | ||
(3, 1, 4, ("a", "b"), "b"), | ||
(4, 1, 4, ("a", "b"), "b"), | ||
], | ||
) | ||
def test_TagWeight_lineargroup(tagweight, groups, expected): | ||
assert tagweight.lineargroup(groups) == expected | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"count, mincount, maxcount, lower, upper, expected", | ||
[ | ||
(1, 1, 1, 1, 3, 1), | ||
(1, 1, 4, 1, 3, 1), | ||
(2, 1, 4, 1, 3, 2), | ||
(4, 1, 4, 1, 3, 3), | ||
], | ||
) | ||
def test_TagWeight_log(tagweight, lower, upper, expected): | ||
assert tagweight.log(lower, upper) == expected | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"count, mincount, maxcount, groups, expected", | ||
[ | ||
(1, 1, 100, ("a", "b", "c"), "a"), | ||
(3, 1, 100, ("a", "b", "c"), "a"), | ||
(12, 1, 100, ("a", "b", "c"), "b"), | ||
(90, 1, 100, ("a", "b", "c"), "c"), | ||
(100, 1, 100, ("a", "b", "c"), "c"), | ||
], | ||
) | ||
def test_TagWeight_loggroup(tagweight, groups, expected): | ||
assert tagweight.loggroup(groups) == expected |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could be a dataclass, but they do not exist yet in python3.6, which is supported by lektor.
This comment was marked as resolved.
Sorry, something went wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done 8d010e9