Skip to content

Commit

Permalink
Support pathlib for feed filenames in parse() function
Browse files Browse the repository at this point in the history
The mopidy core is using pathlib internally, and its use is growing
everywhere all the time.
  • Loading branch information
djmattyg007 committed Jan 24, 2022
1 parent 9b120e6 commit 33e9972
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
3 changes: 3 additions & 0 deletions mopidy_podcast/feeds.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import datetime
import email.utils
import re
from pathlib import Path

import uritools
from mopidy import models
Expand All @@ -14,6 +15,8 @@


def parse(source):
if isinstance(source, Path):
source = str(source)
if isinstance(source, str):
url = uritools.uricompose("file", "", source)
else:
Expand Down
14 changes: 10 additions & 4 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
import functools
import os
from pathlib import Path
from unittest import mock

import mopidy_podcast as ext
import pytest


@pytest.fixture
def abspath():
return functools.partial(os.path.join, os.path.dirname(__file__))
def testpath() -> Path:
return Path(__file__).parent


@pytest.fixture
def abspath(testpath: Path):
return functools.partial(os.path.join, str(testpath))


@pytest.fixture
Expand All @@ -17,7 +23,7 @@ def audio():


@pytest.fixture
def config():
def config(testpath: Path):
return {
"podcast": {
"browse_root": "Podcasts.opml",
Expand All @@ -27,7 +33,7 @@ def config():
"cache_ttl": 86400,
"timeout": 10,
},
"core": {"config_dir": os.path.dirname(__file__)},
"core": {"config_dir": testpath},
"proxy": {},
}

Expand Down
7 changes: 4 additions & 3 deletions tests/test_feeds.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import uritools
from pathlib import Path

import pytest
from mopidy_podcast import feeds
Expand All @@ -8,8 +9,8 @@
"filename,expected",
[("directory.xml", feeds.OpmlFeed), ("rssfeed.xml", feeds.RssFeed)],
)
def test_parse(abspath, filename, expected):
path = abspath(filename)
def test_parse(testpath: Path, filename: str, expected):
path = testpath / filename
feed = feeds.parse(path)
assert isinstance(feed, expected)
assert feed.uri == uritools.uricompose("podcast+file", "", path)
assert feed.uri == uritools.uricompose("podcast+file", "", str(path))

0 comments on commit 33e9972

Please sign in to comment.