Skip to content

Commit

Permalink
Remove dependency on asynctest for python 3.8+
Browse files Browse the repository at this point in the history
  • Loading branch information
LilSpazJoekp committed Nov 27, 2022
1 parent 8680ff8 commit cad6e76
Show file tree
Hide file tree
Showing 36 changed files with 230 additions and 47 deletions.
2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -24,7 +24,7 @@
"sphinxcontrib-trio",
],
"test": [
"asynctest >=0.13.0",
"asynctest >=0.13.0 ; python_version < '3.8'",
"mock >=0.8",
"pytest ==7.2.*",
"pytest-asyncio",
Expand Down
12 changes: 12 additions & 0 deletions tests/__init__.py
@@ -1,4 +1,16 @@
"""Async PRAW Test Suite."""
import sys

if sys.version_info < (3, 8):
from asynctest import TestCase

class BaseTest(TestCase):
"""Base class for Async PRAW tests."""

else:

class BaseTest:
"""Base class for Async PRAW tests."""


class HelperMethodMixin:
Expand Down
23 changes: 17 additions & 6 deletions tests/integration/__init__.py
@@ -1,29 +1,31 @@
"""Async PRAW Integration test suite."""
import asyncio
import inspect
import logging

import aiohttp
import asynctest
import pytest

from asyncpraw import Reddit
from tests import HelperMethodMixin
from tests import BaseTest, HelperMethodMixin
from tests.conftest import vcr


class IntegrationTest(asynctest.TestCase, HelperMethodMixin):
class IntegrationTest(BaseTest, HelperMethodMixin):
"""Base class for Async PRAW integration tests."""

logger = logging.getLogger(__name__)

@pytest.fixture(autouse=True)
def auto_close_reddit(self, event_loop):
yield
event_loop.run_until_complete(self.reddit.close())

def setup_method(self, method):
self._overrode_reddit_setup = True
self.setup_reddit()
self.setup_vcr()

async def teardown_method(self, _):
await self.reddit.close()

def setup_vcr(self):
"""Configure VCR instance."""
self.recorder = vcr
Expand Down Expand Up @@ -102,3 +104,12 @@ def use_cassette(self, cassette_name=None, **kwargs):
def get_cassette_name(self) -> str:
function_name = inspect.currentframe().f_back.f_back.f_code.co_name
return f"{type(self).__name__}.{function_name}"

@pytest.fixture(autouse=True, scope="function")
def patch_sleep(self, monkeypatch):
"""Patch sleep to speed up tests."""

async def _sleep(*_, **__):
pass

monkeypatch.setattr(asyncio, "sleep", value=_sleep)
8 changes: 7 additions & 1 deletion tests/integration/models/reddit/test_collections.py
@@ -1,7 +1,13 @@
"""Test classes from collections.py."""

import sys

import pytest
from asynctest import mock

if sys.version_info < (3, 8):
from asynctest import mock
else:
from unittest import mock

from asyncpraw.exceptions import ClientException, RedditAPIException
from asyncpraw.models import Submission
Expand Down
8 changes: 7 additions & 1 deletion tests/integration/models/reddit/test_comment.py
@@ -1,5 +1,11 @@
import sys

import pytest
from asynctest import mock

if sys.version_info < (3, 8):
from asynctest import mock
else:
from unittest import mock

from asyncpraw.exceptions import AsyncPRAWException, ClientException, RedditAPIException
from asyncpraw.models import Comment, Submission
Expand Down
8 changes: 7 additions & 1 deletion tests/integration/models/reddit/test_draft.py
@@ -1,5 +1,11 @@
import sys

import pytest
from asynctest import mock

if sys.version_info < (3, 8):
from asynctest import mock
else:
from unittest import mock

from asyncpraw.exceptions import ClientException
from asyncpraw.models import Draft, Subreddit
Expand Down
8 changes: 7 additions & 1 deletion tests/integration/models/reddit/test_emoji.py
@@ -1,5 +1,11 @@
import sys

import pytest
from asynctest import mock

if sys.version_info < (3, 8):
from asynctest import mock
else:
from unittest import mock

from asyncpraw.exceptions import ClientException
from asyncpraw.models import Emoji
Expand Down
8 changes: 7 additions & 1 deletion tests/integration/models/reddit/test_live.py
@@ -1,6 +1,12 @@
"""Test asyncpraw.models.LiveThread"""
import sys

import pytest
from asynctest import mock

if sys.version_info < (3, 8):
from asynctest import mock
else:
from unittest import mock

from asyncpraw.const import API_PATH
from asyncpraw.exceptions import RedditAPIException
Expand Down
8 changes: 7 additions & 1 deletion tests/integration/models/reddit/test_message.py
@@ -1,5 +1,11 @@
import sys

import pytest
from asynctest import mock

if sys.version_info < (3, 8):
from asynctest import mock
else:
from unittest import mock

from asyncpraw.models import Message, Redditor, Subreddit, SubredditMessage

Expand Down
6 changes: 5 additions & 1 deletion tests/integration/models/reddit/test_modmail.py
@@ -1,6 +1,10 @@
import sys
from datetime import datetime

from asynctest import mock
if sys.version_info < (3, 8):
from asynctest import mock
else:
from unittest import mock

from asyncpraw.models import ModmailMessage, Subreddit

Expand Down
7 changes: 6 additions & 1 deletion tests/integration/models/reddit/test_multi.py
@@ -1,4 +1,9 @@
from asynctest import mock
import sys

if sys.version_info < (3, 8):
from asynctest import mock
else:
from unittest import mock

from asyncpraw.models import Comment, Submission, Subreddit

Expand Down
8 changes: 7 additions & 1 deletion tests/integration/models/reddit/test_redditor.py
@@ -1,7 +1,13 @@
"""Test asyncpraw.models.redditor."""
import sys

import pytest
from asyncprawcore import Forbidden
from asynctest import mock

if sys.version_info < (3, 8):
from asynctest import mock
else:
from unittest import mock

from asyncpraw.exceptions import RedditAPIException
from asyncpraw.models import Comment, Redditor, Submission
Expand Down
8 changes: 7 additions & 1 deletion tests/integration/models/reddit/test_removal_reasons.py
@@ -1,5 +1,11 @@
import sys

import pytest
from asynctest import mock

if sys.version_info < (3, 8):
from asynctest import mock
else:
from unittest import mock

from asyncpraw.exceptions import ClientException
from asyncpraw.models import RemovalReason
Expand Down
8 changes: 7 additions & 1 deletion tests/integration/models/reddit/test_rules.py
@@ -1,5 +1,11 @@
import sys

import pytest
from asynctest import mock

if sys.version_info < (3, 8):
from asynctest import mock
else:
from unittest import mock

from asyncpraw.exceptions import ClientException, RedditAPIException
from asyncpraw.models import Rule
Expand Down
8 changes: 7 additions & 1 deletion tests/integration/models/reddit/test_submission.py
@@ -1,5 +1,11 @@
import sys

import pytest
from asynctest import mock

if sys.version_info < (3, 8):
from asynctest import mock
else:
from unittest import mock

from asyncpraw.exceptions import RedditAPIException
from asyncpraw.models import Comment, Submission
Expand Down
6 changes: 5 additions & 1 deletion tests/integration/models/reddit/test_subreddit.py
Expand Up @@ -8,7 +8,11 @@
from aiohttp import ClientResponse
from aiohttp.http_websocket import WebSocketError
from asyncprawcore import BadRequest, Forbidden, NotFound, TooLarge
from asynctest import mock

if sys.version_info < (3, 8):
from asynctest import mock
else:
from unittest import mock

from asyncpraw.const import PNG_HEADER
from asyncpraw.exceptions import (
Expand Down
6 changes: 5 additions & 1 deletion tests/integration/models/reddit/test_widgets.py
Expand Up @@ -2,7 +2,11 @@
from os.path import abspath, dirname, join

import pytest
from asynctest import mock

if sys.version_info < (3, 8):
from asynctest import mock
else:
from unittest import mock

from asyncpraw.models import (
Button,
Expand Down
7 changes: 6 additions & 1 deletion tests/integration/models/reddit/test_wikipage.py
@@ -1,8 +1,13 @@
import sys
from base64 import urlsafe_b64encode

import pytest
from asyncprawcore import Forbidden, NotFound
from asynctest import mock

if sys.version_info < (3, 8):
from asynctest import mock
else:
from unittest import mock

from asyncpraw.exceptions import RedditAPIException
from asyncpraw.models import Redditor, WikiPage
Expand Down
8 changes: 7 additions & 1 deletion tests/integration/models/test_comment_forest.py
@@ -1,6 +1,12 @@
"""Test asyncpraw.models.comment_forest."""
import sys

import pytest
from asynctest import mock

if sys.version_info < (3, 8):
from asynctest import mock
else:
from unittest import mock

from asyncpraw.exceptions import DuplicateReplaceException
from asyncpraw.models import Comment, MoreComments
Expand Down
8 changes: 7 additions & 1 deletion tests/integration/models/test_inbox.py
@@ -1,7 +1,13 @@
"""Test asyncpraw.models.inbox."""
import sys

import pytest
from asyncprawcore import Forbidden
from asynctest import mock

if sys.version_info < (3, 8):
from asynctest import mock
else:
from unittest import mock

from asyncpraw.models import Comment, Message, Redditor, Subreddit

Expand Down
7 changes: 6 additions & 1 deletion tests/integration/models/test_preferences.py
@@ -1,4 +1,9 @@
from asynctest import mock
import sys

if sys.version_info < (3, 8):
from asynctest import mock
else:
from unittest import mock

from asyncpraw.models import Preferences

Expand Down
7 changes: 6 additions & 1 deletion tests/integration/models/test_redditors.py
@@ -1,5 +1,10 @@
"""Test asyncpraw.models.redditors."""
from asynctest import mock
import sys

if sys.version_info < (3, 8):
from asynctest import mock
else:
from unittest import mock

from asyncpraw.models import Redditor, Subreddit

Expand Down
7 changes: 6 additions & 1 deletion tests/integration/models/test_subreddits.py
@@ -1,5 +1,10 @@
"""Test asyncpraw.models.subreddits."""
from asynctest import mock
import sys

if sys.version_info < (3, 8):
from asynctest import mock
else:
from unittest import mock

from asyncpraw.models import Subreddit

Expand Down
7 changes: 6 additions & 1 deletion tests/integration/models/test_trophy.py
@@ -1,5 +1,10 @@
"""Test asyncpraw.models.Trophy"""
from asynctest import mock
import sys

if sys.version_info < (3, 8):
from asynctest import mock
else:
from unittest import mock

from .. import IntegrationTest

Expand Down
8 changes: 7 additions & 1 deletion tests/integration/models/test_user.py
@@ -1,7 +1,13 @@
"""Test asyncpraw.models.user."""
import sys

import asyncprawcore.exceptions
import pytest
from asynctest import mock

if sys.version_info < (3, 8):
from asynctest import mock
else:
from unittest import mock

from asyncpraw.exceptions import RedditAPIException
from asyncpraw.models import Multireddit, Redditor, Submission, Subreddit
Expand Down
1 change: 0 additions & 1 deletion tests/integration/test_github_actions.py
Expand Up @@ -12,7 +12,6 @@
from asyncpraw.models import Submission


@pytest.mark.asyncio
@pytest.mark.skipif(
not os.getenv("NETWORK_TEST_CLIENT_ID"),
reason="Not running from the NETWORK_TEST ci task on praw-dev/asyncpraw",
Expand Down
7 changes: 6 additions & 1 deletion tests/integration/test_reddit.py
@@ -1,9 +1,14 @@
"""Test asyncpraw.reddit."""
import sys
from base64 import urlsafe_b64encode

import pytest
from asyncprawcore.exceptions import BadRequest, ServerError
from asynctest import mock

if sys.version_info < (3, 8):
from asynctest import mock
else:
from unittest import mock

from asyncpraw.exceptions import RedditAPIException
from asyncpraw.models import LiveThread
Expand Down
1 change: 1 addition & 0 deletions tests/unit/models/list/test_base.py
Expand Up @@ -2,6 +2,7 @@
import pytest

from asyncpraw.models.list.base import BaseList

from ... import UnitTest


Expand Down

0 comments on commit cad6e76

Please sign in to comment.