Skip to content

Commit

Permalink
Merge pull request #13 from dbatten5/load-sources
Browse files Browse the repository at this point in the history
add `load_sources` support
  • Loading branch information
dbatten5 authored Oct 27, 2021
2 parents ff5b79d + 599be27 commit 213e5d9
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 7 deletions.
3 changes: 2 additions & 1 deletion docs/contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ pip freeze | grep phylm

If you would like to contribute to the repo, you would be most welcome. If
you're tackling an existing issue please comment on the issue that you'd like to
take it on. If it's a new feature/bug, please first raise an issue.
take it on. If it's a new feature/bug, please first raise an issue. If it's a trivial
change (typos, documentation etc.) then no need to raise an issue.

# Local Development

Expand Down
33 changes: 33 additions & 0 deletions docs/phylm.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
This is the main entrypoint class.

# Usage

First instantiate the class with a `title` property:

```python
from phylm import Phylm

p = Phylm(title="The Matrix")
```

Next load a source through either `load_sources` or `load_source`:

```python
p.load_sources(["imdb", "rt"])
p.load_source("mtc")
```

Now the source will be available through a property of the same name:

```python
>>> p.imdb
<phylm.sources.imdb.Imdb object at 0x108a94810>
```

See the docs for a source for a full list of the available data points.

# Reference

::: phylm.Phylm
rendering:
show_source: true
10 changes: 6 additions & 4 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@ theme:

nav:
- Phylm: index.md
- Sources:
IMDb: imdb.md
Metacritic: mtc.md
Rotten Tomatoes: rt.md
- Classes:
- Phylm: phylm.md
- Sources:
IMDb: imdb.md
Metacritic: mtc.md
Rotten Tomatoes: rt.md
- Contributing: contributing.md

plugins:
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "phylm"
version = "4.0.0"
version = "4.0.1"
description = "Phylm"
authors = ["Dom Batten <[email protected]>"]
license = "MIT"
Expand Down
17 changes: 16 additions & 1 deletion src/phylm/phylm.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Module to contain the `Phylm` class definition."""
from typing import List
from typing import Optional

from phylm.errors import SourceNotLoadedError
Expand Down Expand Up @@ -71,7 +72,7 @@ def load_source(self, source: str) -> "Phylm":
"""Load the film data for a source.
Args:
source (str): a list of the desired sources
source (str): the desired source
Returns:
the instance
Expand All @@ -92,3 +93,17 @@ def load_source(self, source: str) -> "Phylm":
return self

raise UnrecognizedSourceError(f"{source} is not a recognized source")

def load_sources(self, sources: List[str]) -> "Phylm":
"""Load multiple sources.
Args:
sources: a list of the desired sources
Returns:
the instance
"""
for source in sources:
self.load_source(source)

return self
35 changes: 35 additions & 0 deletions tests/unit/test_phylm.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,38 @@ def test_recognized_source_rt(self, mock_rt: MagicMock) -> None:

assert phylm.rt == mock_rt.return_value
mock_rt.assert_called_once_with(raw_title="bar")


class TestLoadSources:
"""Tests for the `load_sources` method."""

@patch("phylm.phylm.Mtc", autospec=True)
@patch("phylm.phylm.Rt", autospec=True)
def test_success(self, mock_rt: MagicMock, mock_mtc: MagicMock) -> None:
"""
Given a list of sources,
When the `load_sources` is invoked with the list,
Then the sources are loaded
"""
phylm = Phylm(title="foo")

phylm.load_sources(["rt", "mtc"])

assert phylm.rt == mock_rt.return_value
assert phylm.mtc == mock_mtc.return_value
with pytest.raises(SourceNotLoadedError):
assert phylm.imdb is None

@patch("phylm.phylm.Rt", autospec=True)
def test_one_source_not_recognised(self, mock_rt: MagicMock) -> None:
"""
Given a list of sources where one is unrecognised,
When the `load_sources` is invoked with the list,
Then a UnrecognizedSourceError is raised
"""
phylm = Phylm(title="foo")

with pytest.raises(UnrecognizedSourceError):
phylm.load_sources(["rt", "blort"])

assert phylm.rt == mock_rt.return_value

0 comments on commit 213e5d9

Please sign in to comment.