File: helpers.py

package info (click to toggle)
python-logi-circle 0.2.3-3
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 300 kB
  • sloc: python: 1,685; xml: 16; sh: 5; makefile: 4
file content (39 lines) | stat: -rw-r--r-- 1,028 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
"""Helper functions for Logi Circle API unit tests."""
import os
import asyncio


def get_fixture_name(filename):
    """Strips extension from filename when building fixtures dict key."""
    return os.path.splitext(filename)[0]


def get_fixtures():
    """Grabs all fixtures and returns them in a dict."""
    fixtures = {}
    path = os.path.join(os.path.dirname(__file__), 'fixtures')
    for filename in os.listdir(path):
        with open(os.path.join(path, filename)) as fdp:
            fixture = fdp.read()
            fixtures[get_fixture_name(filename)] = fixture
            continue
    return fixtures


def async_return(result):
    """Mock a return from an async function."""
    future = asyncio.Future()
    future.set_result(result)
    return future


class FakeStream():
    """Mocks a stream returned by aiohttp"""
    async def read(self):
        """Mock read method"""
        return b'123'

    def close(self):
        """Mock close method"""
        # pylint: disable=no-self-use
        return True