Skip to content

Commit

Permalink
storage: Switch to pyfakefs for testing
Browse files Browse the repository at this point in the history
Had big issues with mockfs on Windows.

Relates to #243
  • Loading branch information
postlund committed Sep 2, 2023
1 parent 7cc5a92 commit 856fede
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 12 deletions.
2 changes: 1 addition & 1 deletion docs/api/pyatv.html
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ <h2 class="section-title" id="header-functions">Functions</h2>
</dd>
<dt id="pyatv.scan">
<code class="name flex">
<span>async def <span class="ident">scan</span></span>(<span>loop: asyncio.events.AbstractEventLoop, timeout: int = 5, identifier: Union[str, Set[str], None] = None, protocol: Union[<a title="pyatv.const.Protocol" href="const#pyatv.const.Protocol">Protocol</a>, Set[<a title="pyatv.const.Protocol" href="const#pyatv.const.Protocol">Protocol</a>], None] = None, hosts: Optional[List[str]] = None, aiozc: Optional[zeroconf.asyncio.AsyncZeroconf] = None, storage: Optional[<a title="pyatv.interface.Storage" href="interface#pyatv.interface.Storage">Storage</a>] = None) -> List[<a title="pyatv.interface.BaseConfig" href="interface#pyatv.interface.BaseConfig">BaseConfig</a>]</span>
<span>async def <span class="ident">scan</span></span>(<span>loop: asyncio.events.AbstractEventLoop, timeout: int = 5, identifier: Union[str, Set[str], ForwardRef(None)] = None, protocol: Union[<a title="pyatv.const.Protocol" href="const#pyatv.const.Protocol">Protocol</a>, Set[<a title="pyatv.const.Protocol" href="const#pyatv.const.Protocol">Protocol</a>], ForwardRef(None)] = None, hosts: Optional[List[str]] = None, aiozc: Optional[zeroconf.asyncio.AsyncZeroconf] = None, storage: Optional[<a title="pyatv.interface.Storage" href="interface#pyatv.interface.Storage">Storage</a>] = None) -> List[<a title="pyatv.interface.BaseConfig" href="interface#pyatv.interface.BaseConfig">BaseConfig</a>]</span>
</code>
</dt>
<dd>
Expand Down
2 changes: 1 addition & 1 deletion docs/api/pyatv/interface.html
Original file line number Diff line number Diff line change
Expand Up @@ -1239,7 +1239,7 @@ <h3>Methods</h3>
</code></dt>
<dd>
<section class="desc"><p>Container for media (e.g. audio or video) metadata.</p></section>
<div class="git-link-div"><a href="https://github.com/postlund/pyatv/blob/master/pyatv/interface.py#L75-L82" class="git-link">Browse git</a></div>
<div class="git-link-div"><a href="https://github.com/postlund/pyatv/blob/master/pyatv/interface.py#L73-L82" class="git-link">Browse git</a></div>
<h3>Class variables</h3>
<dl>
<dt id="pyatv.interface.MediaMetadata.album"><code class="name">var <span class="ident">album</span> -> Optional[str]</code></dt>
Expand Down
2 changes: 1 addition & 1 deletion docs/api/pyatv/settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ <h3>Class variables</h3>
<dd>
<section class="desc"></section>
</dd>
<dt id="pyatv.settings.InfoSettings.mac"><code class="name">var <span class="ident">mac</span> -> typing_extensions.Annotated[str, AfterValidator(func=<function _mac_validator at 0x7f7fbf2a8af0>)] = 02:70:79:61:74:76</code></dt>
<dt id="pyatv.settings.InfoSettings.mac"><code class="name">var <span class="ident">mac</span> -> str = 02:70:79:61:74:76</code></dt>
<dd>
<section class="desc"></section>
</dd>
Expand Down
2 changes: 1 addition & 1 deletion requirements/requirements_test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ black==23.7.0
deepdiff==6.3.1
flake8==6.1.0
isort==5.12.0
mockfs==1.1.4
mutagen==1.46.0
pyfakefs==5.2.4
pylint==2.17.5
pytest==7.4.0
pytest-asyncio==0.21.1
Expand Down
7 changes: 2 additions & 5 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from unittest.mock import Mock, patch

from ifaddr import IP, Adapter
import mockfs
import pytest
import pytest_asyncio
from pytest_httpserver import HTTPServer
Expand Down Expand Up @@ -191,7 +190,5 @@ def data_webserver_fixture(httpserver: HTTPServer, files: typing.Sequence[str]):


@pytest.fixture(name="mockfs")
def mockfs_fixture():
mocked = mockfs.replace_builtins()
yield mocked
mockfs.restore_builtins()
def mockfs_fixture(fs):
yield fs
4 changes: 1 addition & 3 deletions tests/test_storage_functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
Uses MemoryStorage as storage for simplicity.
"""
import asyncio
import os
from unittest.mock import MagicMock, patch

from deepdiff import DeepDiff
Expand All @@ -21,7 +20,7 @@

pytestmark = pytest.mark.asyncio

STORAGE_FILENAME = os.path.join(os.environ["HOME"], "pyatv.conf")
STORAGE_FILENAME = "pyatv.conf"


@pytest.fixture(autouse=True)
Expand All @@ -34,7 +33,6 @@ async def new_storage(
) -> Storage:
storage = FileStorage(filename, loop)
await storage.load()
mockfs.add_entries({filename: ""})
return storage


Expand Down

0 comments on commit 856fede

Please sign in to comment.