Skip to content

Commit

Permalink
Restore original behavior, adjust test to match
Browse files Browse the repository at this point in the history
I remember that the aim of this PR is to add a test demonstrating
the existing behavior. I do not intend to fix any possible problems
I encounter along the way, merely demonstrate them clearly in the
test, so that they may be fixed later, with a clear test in place.

Accordingly, I've removed my attempts to use consistent slashes in
each RSS items' GUID field, and instead adjusted the test to match
the current behavior. The test contains a TODO describing that I
suspect this behavior might be incorrect.
  • Loading branch information
tartley committed Jul 4, 2023
1 parent 8944d20 commit ad03124
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
7 changes: 1 addition & 6 deletions nikola/plugins/task/galleries.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import json
import mimetypes
import os
import pathlib
from collections import OrderedDict
from urllib.parse import urljoin

Expand Down Expand Up @@ -738,10 +737,6 @@ def make_url(url):
else:
img_list, dest_img_list, img_titles = [], [], []

def forward_slashes(path):
"""Given a path, convert directory separators to forward slash, on all platforms."""
return str(pathlib.PurePosixPath(*os.path.split(path)))

items = []
for img, srcimg, title in list(zip(dest_img_list, img_list, img_titles))[:self.kw["feed_length"]]:
img_size = os.stat(
Expand All @@ -750,7 +745,7 @@ def forward_slashes(path):
args = {
'title': title,
'link': make_url(img),
'guid': rss.Guid(forward_slashes(img), False),
'guid': rss.Guid(img, False),
'pubDate': self.image_date(srcimg),
'enclosure': rss.Enclosure(
make_url(img),
Expand Down
14 changes: 9 additions & 5 deletions tests/integration/test_demo_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,13 @@ def test_gallery_rss(build, output_dir):
assert parsed.feed.subtitle == '' # From the XML field 'description'
assert parsed.feed.updated == rfc822(BUILDTIME)
# and the images, as items in the RSS feed, are:
# TODO I think the id for each item should not contain platform-dependant slashes.
# The id for an RSS item should perhaps always use forward slashes no matter
# what platform we are on.
sep = os.path.sep
expected_items = [
dict(
id='galleries/demo/tesla4_lg.jpg',
id=f'galleries{sep}demo{sep}tesla4_lg.jpg',
link='https://example.com/galleries/demo/tesla4_lg.jpg',
links=[
Any(),
Expand All @@ -90,7 +94,7 @@ def test_gallery_rss(build, output_dir):
title='Tesla4 lg',
),
dict(
id='galleries/demo/tesla_conducts_lg.webp',
id=f'galleries{sep}demo{sep}tesla_conducts_lg.webp',
link='https://example.com/galleries/demo/tesla_conducts_lg.webp',
links=[
Any(),
Expand All @@ -105,7 +109,7 @@ def test_gallery_rss(build, output_dir):
title='Tesla conducts lg',
),
dict(
id='galleries/demo/tesla_lightning1_lg.jpg',
id=f'galleries{sep}demo{sep}tesla_lightning1_lg.jpg',
link='https://example.com/galleries/demo/tesla_lightning1_lg.jpg',
links=[
Any(),
Expand All @@ -120,7 +124,7 @@ def test_gallery_rss(build, output_dir):
title='Tesla lightning1 lg',
),
dict(
id='galleries/demo/tesla_lightning2_lg.jpg',
id=f'galleries{sep}demo{sep}tesla_lightning2_lg.jpg',
link='https://example.com/galleries/demo/tesla_lightning2_lg.jpg',
links=[
Any(),
Expand All @@ -135,7 +139,7 @@ def test_gallery_rss(build, output_dir):
title='Tesla lightning2 lg',
),
dict(
id='galleries/demo/tesla_tower1_lg.jpg',
id=f'galleries{sep}demo{sep}tesla_tower1_lg.jpg',
link='https://example.com/galleries/demo/tesla_tower1_lg.jpg',
links=[
Any(),
Expand Down

0 comments on commit ad03124

Please sign in to comment.