diff --git a/docs/contributing.md b/docs/contributing.md index 605ee32..1c810cc 100644 --- a/docs/contributing.md +++ b/docs/contributing.md @@ -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 diff --git a/docs/phylm.md b/docs/phylm.md new file mode 100644 index 0000000..ac968d9 --- /dev/null +++ b/docs/phylm.md @@ -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 + +``` + +See the docs for a source for a full list of the available data points. + +# Reference + +::: phylm.Phylm + rendering: + show_source: true diff --git a/mkdocs.yml b/mkdocs.yml index 2ec7b0b..26c8cc0 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -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: diff --git a/pyproject.toml b/pyproject.toml index ca469ce..cb9f7fa 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "phylm" -version = "4.0.0" +version = "4.0.1" description = "Phylm" authors = ["Dom Batten "] license = "MIT" diff --git a/src/phylm/phylm.py b/src/phylm/phylm.py index e6f13f4..6db6f67 100644 --- a/src/phylm/phylm.py +++ b/src/phylm/phylm.py @@ -1,4 +1,5 @@ """Module to contain the `Phylm` class definition.""" +from typing import List from typing import Optional from phylm.errors import SourceNotLoadedError @@ -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 @@ -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 diff --git a/tests/unit/test_phylm.py b/tests/unit/test_phylm.py index 802c756..335ea6a 100644 --- a/tests/unit/test_phylm.py +++ b/tests/unit/test_phylm.py @@ -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