forked from lektor/lektor
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix semantics of Record equality (lektor#1105)
* A sources identity depends on alt as well as path * Fix Attachment.iter_source_filenames It should return the both the alt-specific and the fallback .lr filenames (in addition to the attachment filename.) * SourceObject subclasses should all implement .iter_source_filenames The SourceObject.source_filename property now just returns the first of the filenames returned by the iter_source_filenames method. * Make the identity key (source, alt) explicit for VirtualSourceObjects Both Records and VirtualSourceObjects are described by the identity key (path, alt, pad). That is, if obj2 = pad.get(obj.path, alt=obj.path) then obj2 == obj Records already had __eq__ and __hash__ methods which made this explicit. Here we add those methods for VirtualSourceObjects. Note this allows us to convert Context.referenced_virtual_dependencies from a dict to a set. (The key was only being used as an identity key for the VirtualSourceObjects.)
- Loading branch information
Showing
7 changed files
with
124 additions
and
68 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
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
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,38 @@ | ||
import pytest | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"key1, key2, is_eq", | ||
[ | ||
({"path": "/"}, {"path": "/"}, True), | ||
({"path": "/"}, {"path": "/", "alt": "en"}, True), | ||
({"path": "/"}, {"path": "/blog"}, False), | ||
({"path": "/blog/post1"}, {"path": "/blog/post1@siblings"}, False), | ||
({"path": "/"}, {"path": "/", "page_num": 1}, False), | ||
({"path": "/"}, {"path": "/", "alt": "de"}, False), | ||
({"path": "/", "alt": "en"}, {"path": "/", "alt": "de"}, False), | ||
], | ||
) | ||
def test_records_eq(pad, key1, key2, is_eq): | ||
r1 = pad.get(**key1) | ||
pad.cache.flush() | ||
r2 = pad.get(**key2) | ||
if is_eq: | ||
assert r1 == r2 | ||
assert hash(r1) == hash(r2) | ||
else: | ||
assert r1 != r2 | ||
|
||
|
||
def test_records_from_different_pads_ne(env): | ||
pad1 = env.new_pad() | ||
pad2 = env.new_pad() | ||
assert pad1.get("/") == pad1.get("/") | ||
assert pad1.get("/") != pad2.get("/") | ||
|
||
|
||
def test_asset_ne_record(pad): | ||
record = pad.get("/") | ||
asset = pad.get_asset("/") | ||
assert record != asset | ||
assert asset != record |